Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

5 hours ago, super_nova said:

Can you guys add ";" as an alternative to "."? It's really annying for me. First, I was typing ";" at the end of lines while scripting with kOS but then I get used to it. And now, I'm typing "." even while coding C++ :P Pleaseeeeeeeeee

The problem with allowing multiple syntaces to do the same thing just because you *can* is that eventually it leads to Perl, where trying to read someone else's code is a real pain because they're using one of the other 20 ways to write the same statement than the one you're familiar with.

I'm not a fan of the period syntax either, but it predates my involvement in the mod and I dislike the practice of making multiple correct ways to do the same thing even more than I do the wonky period syntax.  It gets out of hand very fast.

Link to comment
Share on other sites

If your program ends right after locking throttle - it will be unlocked back.

Options are:

  1. make sure your program runs until some conditions are met (you can also use action groups and any other pilot inputs as such conditions to give you manual control)
  2. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 1. //This will affect your throttle gauge directly.
Link to comment
Share on other sites

1 hour ago, Alchemist said:

If your program ends right after locking throttle - it will be unlocked back.

Options are:

  1. make sure your program runs until some conditions are met (you can also use action groups and any other pilot inputs as such conditions to give you manual control)
  2. SET SHIP:CONTROL:PILOTMAINTHROTTLE TO 1. //This will affect your throttle gauge directly.

It is not enough. If you don't want to end program, just one part of it, for example you have found optimal Throttle for desired acceleration and you want to print it on screen,
and return throttle to pilot without terminating the rest of script, you also need this:

SET SHIP:CONTROL:PILOTMAINTHROTTLE TO my_value.
SET SHIP:CONTROL:NEUTRALIZE TO TRUE. // That is from kOS manual on github.

That will leave throttle to whatever position you have searched for (my_value) and it will return Throttle input controls to pilot while rest of script keeps runing.

Link to comment
Share on other sites

i tried what you guys give me but the problem is that im working with RT mod so when i get over the distance of contact the ship's throttle becomes idle. It is realy frustrating to make just a ascent program that is able to launch a communication probe in an orbit using a mathmetical formula.

what i have at the moment but doesn't work is

SAS on.
RCS off.
lock throttle to 0.

clearscreen.

if SHIP:ALTITUDE < 100 {
set runmode to 1.
}

if runmode = 1 {
print "5".
wait 1.
print "4".
wait 1.
print "3".
stage.
wait 1.
print "2".
wait 1.
print "1".
set runmode to 2.
}

if runmode = 2 {
lock throttle to 1.
lock steering to up.
   if SHIP:ALTITUDE >10000 {
      lock throttle to 0.
      set runmode to 3.
   }
}

 

Link to comment
Share on other sites

There is lack of "runmode=3", I suppose that should be "idle" state when program does not have to do anything. If that is a case, then in this piece of code you missing mentioned commands.

if runmode = 2 {
  lock throttle to 1.
  lock steering to up.
   if SHIP:ALTITUDE >10000 {
      lock throttle to 0.
      set runmode to 3.
      set SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
      set SHIP:CONTROL:NEUTRALIZE TO TRUE. // That is from kOS manual on github.
   }
}

When you execute mode 2 and your ship reach needed altitude, engines would shut off, controls will be given back to pilot input and script will be continue to execute whatever you want in mode 3 (opening cargo bays, deploy antennas, scanners, solar panels, whatever you have planed to do)

Link to comment
Share on other sites

i made a loop but the throttle stil goes to idle when i exceed the range of the antenna's 

this is what i got what am i doing wrong?

 

SAS on.
RCS off.
lock throttle to 0.

clearscreen.

set targetaltitude to 20000.

if ship:altitude < 100 {
set runmode to 1.
}

until runmode = 0 {

  if runmode = 1 {
  print "5".
  wait 1.
  print "4".
  wait 1.
  print "3".
  stage.
  wait 1.
  print "2".
  wait 1.
  print "1".
  set runmode to 2.
  }

  if runmode = 2 {
  set throttle to 1.
  set runmode to 3.
  }

  if runmode = 3 {
    if ship:apoapsis > targetaltitude {
    set throttle to 0.
    set runmode to 0.
    }
  }

Link to comment
Share on other sites

35 minutes ago, kerboman25 said:

i made a loop but the throttle stil goes to idle when i exceed the range of the antenna's 

this is what i got what am i doing wrong?

 

  if runmode = 3 {
    if ship:apoapsis > targetaltitude {
    set throttle to 0.
    set runmode to 0.
    }
  }

Change that part of script with example below and try. I also still learning kOS, but described example worked for me.

  if runmode = 3 {
    if ship:apoapsis > targetaltitude {
    set throttle to 0.
    set SHIP:CONTROL:PILOTMAINTHROTTLE TO 0.
    set SHIP:CONTROL:NEUTRALIZE TO TRUE. // That is from kOS manual on github.
    set runmode to 0.
    }
 

Currently, I'm messing around with hovering script. Thing that I'm going to try next is that after whatever value for thtrottle is set I run mentioned commands before calling wait my_delay_value.

That should alow pilot to apply his own control input for throttle to override throttle set by hovering script in case of imediate danger - PID set throttle too low for some reason and you are on low altitude that might crash plane.

Another step to insert into hovering script is to find out if throttle was changed by pilot instead of PID controller and stop script execution.

 

Link to comment
Share on other sites

Hi,

After upgrading the latest kOS from github (ksp 1.0.4) I started having the following error:

 

Method not found: 'GameVariables.UnlockedActionGroupsCustom'.
At fdrill on archive, line 18
      D:DOACTION(deployDrill,true).

This is the complete method that is failing:


declare function deploy {
  print "drill " at(2,3).

  DECLARE DRILLS to SHIP:MODULESNAMED("ModuleAnimationGroup"). // MKS drills

  DECLARE deployDrill to "Deploy Drill".
  DECLARE drillCount to 0.
  FOR D IN DRILLS {

    if D:HASACTION(deployDrill) {
      D:DOACTION(deployDrill,true).
      set drillCount to drillCount+1.
    }
  }

  print ("Found " + drillCount + " " + "undeployed drills") at (12,5).

}

Any clues? Or this version simply cannot run on 1.0.4?

 

BTW I would be surprised if I have any issues with control groups this deep into the career.

 

Edited by Qigon
Link to comment
Share on other sites

I need to make a simple script that can fly an upper stage to orbit in one burn. Or atleast get close to it. Its been awhile since ive used KoS so when I say simple I mean something like this.

RCS on.

Lock throttle to 1.

Lock heading to 90.

Wait until periapsis > 100000

Lock throttle to 0.

... simple. Lol. Problem is that might give me a very high apoapsis.

Keep apoapsis < 100000

Is such a line even possible?

 

 

Link to comment
Share on other sites

10 hours ago, Qigon said:

Hi,

After upgrading the latest kOS from github (ksp 1.0.4) I started having the following error:

Any clues? Or this version simply cannot run on 1.0.4?

There was a small change in KSP API between 1.0.4 and 1.0.5 resulting in this function failing if the plugin has been compilled for the other version. So, for 1.0.4 you either have to use kOS 0.18.1 or make your own recompile.

 

Link to comment
Share on other sites

Well... I be dammed...

Hyper-'ventilated' a satellite into orbit as a target.. at an Inclination=55 and LAN=330.

Launch from KSC at the right time and try get the LAN and INC right... How easy it is to make math mistakes, not to mention programming yourself up the creek.

Butttt... a moment of brilliance ..tap tap tap.. and.. what can I Say :-)

(Edt - Ignore the ship heading as it's programmed to Prograde at this moment - I just haven't updated the screen parameter.)

NIVy8Vl.jpg

Edited by ColKlonk
Link to comment
Share on other sites

15 hours ago, Alchemist said:

There was a small change in KSP API between 1.0.4 and 1.0.5 resulting in this function failing if the plugin has been compilled for the other version. So, for 1.0.4 you either have to use kOS 0.18.1 or make your own recompile.

 

 

I could successfully upgrade all my critical mods and make it to 1.0.5 today, and it worked like a charm as you predicted. 

Much smooth, very awe. I love this mod. 

Link to comment
Share on other sites

I'm suprised how effective PID controller library can be. I couldn't find any mod that properly work with slow response engines like jets or KAX piston engines that need just enough throttle for hovering above ground purposes.

I couldn't find good PID settings for throttle / alt:radar hower control - it simply oscilate too much to be good enough for hovering.
However, I was able to create stable hover with throttle/ship:verticalspeed combo. After that, I have used two PID controlers in combination.
One to control hover trough ship vertical speed, and other that will give input for the first one for desired altitude over ground.

It might not be good for rapid changes of altitude over ground, but once craft is slow enough - already hovering over desired spot, it is quite useful for precise maneuver. Here is most important part of script, if someone need it:
 

until AltHover = false
	{
		// Set desired Hovering Altitude trough Vertical Velocity speed instead directly trough throttle
		set seekVelocity to PID_seek( AltHoverPID, seekAlt, alt:radar).
		
		
		ThrottleLimits(). // Recalculate Min/Max Throttle 
		set VelHoverPID[3] to MinThrottle. // ~0.85 of TWR to prevent too high down velocity - crashing issue
		set VelHoverPID[4] to MaxThrottle. // ~1.2 of TWR to prevent too high up velocity - flipng issue
		
		set myThrottle to PID_seek( VelHoverPID, seekVelocity, ship:verticalspeed ).
		
		SET SHIP:CONTROL:PILOTMAINTHROTTLE TO myThrottle.
		SET SHIP:CONTROL:NEUTRALIZE TO TRUE.
		display_block(1,8).
		// For Low response engines, like Jets and KAX piston wait time can be higher than for rockets
		wait 0.5. // Pilot can set his own throttle inside 0.5 sec time frame between two PID adjustments
	}.

 

Instead of using lock throttle command, I have used pilotmainthrottle command. That and sligtly larger delay time between two iteration of script allows pilot to override throttle inside that 0.5 sec timeframe - taping "Z" or "X" for example to provoke PID controll to quicker response or prevent crashing if down speed is still too high.

I would like to improve this script further, so instead of main throttle on all engines, I would like to alter only engines that have vertical thrust.
I know to list all ship engines, but how to detect engines that point thrust down ?

Link to comment
Share on other sites

While trying to write an autopilot for launching a rocket I've got this error.
screenshot2

It appears while loading a custom lib written by me that contains all the functions of the script. Since there isn't a line of code that causes the error I'm not able to tell where it stoped working, The last thing I was working on was to regulate the throttle by looking at the TWR. --> function limitTWR and function startGravityturn.

Since this is one of my first scripts I probably did something horrible wrong and it's all my fault. :)

Here are my two files that caused the Error:

launch003.ks.txt
lib_launch.ks.txt

and here is the output_log:

output_log.txt

Could someone tell me what caused the error? I've already created a issue on github since the log tells me to do so but maybe someone here can help me too.

Thanks for your help and greetings from Germany

Link to comment
Share on other sites

To the author of kOS:
A new structure about control view. Rotation and far/near.
Would you add a such structure into new version kOS?
Then in some cases, the players can say goodbye to mouse wheel.
Thanks.

Link to comment
Share on other sites

23 hours ago, gh7531 said:

While trying to write an autopilot for launching a rocket I've got this error.
screenshot2

It appears while loading a custom lib written by me that contains all the functions of the script. Since there isn't a line of code that causes the error I'm not able to tell where it stoped working, The last thing I was working on was to regulate the throttle by looking at the TWR. --> function limitTWR and function startGravityturn.

Since this is one of my first scripts I probably did something horrible wrong and it's all my fault. :)

Here are my two files that caused the Error:

launch003.ks.txt
lib_launch.ks.txt

and here is the output_log:

output_log.txt

Could someone tell me what caused the error? I've already created a issue on github since the log tells me to do so but maybe someone here can help me too.

Thanks for your help and greetings from Germany

I saw your github issue but it came at a time when we just were working in that area of the code and testing to recreate it is a pain.  I'll try it tonight (I'm in UTC-5 so that will be a while yet) and see what I can find out.

Link to comment
Share on other sites

5 hours ago, Lookerksy said:

To the author of kOS:
A new structure about control view. Rotation and far/near.
Would you add a such structure into new version kOS?
Then in some cases, the players can say goodbye to mouse wheel.
Thanks.

We've thought about this before, but there is some debate among the kOS developers as to whether or not this would be outside the remit of kOS.  I'd like to be able to draw the line somewhere between "what kOS does do" and "what kOS doesn't do", so we don't end up turning an already kind-of-large mod into something so large it's just as big as the base game itself is and we don't have the ability to deal with it in our spare time.  We agree that there should be such a line, but not on exactly where that line is.  Camera controls may or may not fall beyond that line.  They're not autopiloting, but then again they are part of the player experience while watching the autopilot.

Link to comment
Share on other sites

I feel I'm overcomplicating something,

How do I get the compass heading of an airplane as a scalar? I'm doing vang with facing and north, but this always gives me a "small" positive number. I'd like something that returns -1 when pointing to 359 degrees, or at least something equivalent. 

Link to comment
Share on other sites

29 minutes ago, Qigon said:

I feel I'm overcomplicating something,

How do I get the compass heading of an airplane as a scalar? I'm doing vang with facing and north, but this always gives me a "small" positive number. I'd like something that returns -1 when pointing to 359 degrees, or at least something equivalent. 

 

Have you tried navball orientation library from community examples ? Try provided library with example, it is simple to use and understand.

If you realy need -1 you can always use 360 miunus pointing value.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...