erendrake

[1.3] kOS Scriptable Autopilot System v1.1.3.0

Recommended Posts

Wrong script.

Oops, realy should close some of these tabs every now and again.:blush: fixed.

I will surely accept a padding PR on github k_wink.gif

Will get on it, might be a while though as i need to learn C# first. I shall treat this as incentive:).

Ok haven't tried a rover script before the equation i posted above is what i have been using to fly hover / vtol craft to a way point (placing a flag in the air was proving tricky:P).

Couldn't get LOCK WHEELSTEERING to a heading to work at all.

But these comands work;

lock wheelsteering to target.

lock wheelstering to latlng([latitude],[longitude]). //no need for the equation i posted above on rovers. will look at this for aircraft but probably wont use it as i cant do any correction on it (to pull prograde onto the heading instead of just pointing at it).

set ship:control:wheelsteer to [1 to -1]. // if you want raw controls.

Edited by TDW

Share this post


Link to post
Share on other sites
Yes. wrappers around the various string manipulators like substring, toupper, and so on would be nice. It might be a good idea to wait until there's such a thing as methods wrapping things in kOS (upcoming future feature) so we can make it work like it should (var.toupper() rather than toupper(var)).

Absolutely, it is the chief reason they arent in kOS yet. Functions will make them easy to use and easy to define

Share this post


Link to post
Share on other sites

I've got a small problem:

cIonay.png

Here is the script:


lock throttle to 1.
lock VYSOTA to SHIP:ALTITUDE.
declare parameter ANGL.
until VERTICALSPEED > 100 {lock steering to up + R(0,0,270).}.
unlock steering.
print "Beginning gravity turn".

until (1.2*(VYSOTA/1000)-(VYSOTA/1500)) > 80 {
lock ANGL to (1.2*(VYSOTA/1000)-(VYSOTA/1500)).
lock Y to (90-ANGL).
set MyDIR to HEADING (90,Y).
lock throttle to 1.
lock steering to MyDIR.
print "Current angle = " + CEILING(ANGL) + " degrees." at(0,2).
print "Altitude =" + CEILING(VYSOTA) + " m." at(0,1).
}.
unlock ANGL.
set ANGL to (1.2*(VYSOTA/1000)-(VYSOTA/1500)).

until APOAPSIS > 645000 {
set FANGL to (90-ANGL).
print "Final angle = " + CEILING(FANGL) + " degrees." at(0,2).
lock MyDIR to HEADING (90,FANGL).
lock throttle to 1.
lock steering to MyDIR.
}.

lock steering to HEADING(90,0).
lock throttle to 0.
clearscreen.
wait until eta:apoapsis < 100.

[B]until PERIAPSIS > 640000 {[/B]
lock throttle to 1.
lock MyDIR to HEADING (90,0).
lock steering to MyDIR.
}.
unlock throttle.
unlock steering.
break.

What I'm doing wrong?

And is there a spoiler tag? ))

Edited by MaxP

Share this post


Link to post
Share on other sites
I've got a small problem:

What I'm doing wrong?

Well that is strange, try

until SHIP:PERIAPSIS > 640000 { }

And is there a spoiler tag? ))

the spoiler tag has been broken on this forum forever :P

Share this post


Link to post
Share on other sites

@MaxP, Can you look at your log file (on windows it's under KSP_Data or KSP_Data_x64 if you run 64 bit, and in either case it's called "output_log.txt" It has a different name on Mac and Linux for some weird reason (ask Unity why, it was their idea to change the name depending on OS for .. some reason). This specific error message ("reference not set to...") *probably* indicates some problem that's not your fault but is the mod's fault *usually, not always* that is the case with the "reference not set" error. Can you either post the log, or if you don't want to because it's enormous (it usually is), can you show the... ohh.. say 100 lines or so above and below all the places where it has the string "NullReference" somewhere in the log?

And on another note, not at all related to the crash (probably): you don't really need to keep re-issuing the LOCK commands over and over again in the "until periapsis > 640000" loop. That's sort of the point of a lock is that they are always reset to the formula all the time, dynamically on the fly. You could probably issue those commands once, and then just wait until periapsis > 640000 doing nothing, and it would have the same effect.

Share this post


Link to post
Share on other sites
Well that is strange, try

until SHIP:PERIAPSIS > 640000 { }

The same, the only difference is the pointer on the "S" ))

[LOG 20:49:32.010] 1Test2 Debris Unloaded

[LOG 20:49:32.011] RemoteTech: AntennaManager: RegisterProtos(1Test2 Debris, a6a36b8f-9763-4266-bc74-2bcaa3136735)

[LOG 20:49:32.013] RemoteTech: SatelliteManager: RegisterProto(1Test2 Debris, a6a36b8f-9763-4266-bc74-2bcaa3136735)

[LOG 20:49:32.013] RemoteTech: GetSignalProcessor(1Test2 Debris): Check

[LOG 20:49:32.013] Packing 1Test2 Debris for orbit

[LOG 20:49:39.908] 1Test2 Debris Unloaded

[LOG 20:49:39.909] RemoteTech: AntennaManager: RegisterProtos(1Test2 Debris, 98a00f9d-8bee-4809-90c7-a3b9e0dbe6b9)

[LOG 20:49:39.910] RemoteTech: SatelliteManager: RegisterProto(1Test2 Debris, 98a00f9d-8bee-4809-90c7-a3b9e0dbe6b9)

[LOG 20:49:39.910] RemoteTech: GetSignalProcessor(1Test2 Debris): Check

[LOG 20:49:39.910] Packing 1Test2 Debris for orbit

[LOG 20:49:42.620] RemoteTech: ModuleRTAntennaPassive: Remove TRANSMITTER success.

[LOG 20:49:49.094] At launch on 1, line 52

until PERIAPSIS > 640000 {

^

[LOG 20:49:49.094] System.NullReferenceException: Object reference not set to an instance of an object

at kOS.Execution.CPU.OnSave (.ConfigNode node) [0x00000] in <filename unknown>:0

[LOG 20:49:49.095] Code Fragment

File Line:Col IP opcode operand

---- ----:--- ---- ---------------------

1/launch 47:1 0363 push 76

1/launch 47:1 0364 addtrigger false

1/launch 47:1 0365 push steering

1/launch 47:1 0366 push True

1/launch 47:1 0367 call toggleflybywire()

1/launch 48:1 0368 push $throttle*

1/launch 48:1 0369 push 11

1/launch 48:1 0370 store

1/launch 48:1 0371 push 72

1/launch 48:1 0372 addtrigger false

1/launch 48:1 0373 push throttle

1/launch 48:1 0374 push True

1/launch 48:1 0375 call toggleflybywire()

1/launch 49:1 0376 call clearscreen()

1/launch 50:1 0377 push 80

1/launch 50:1 0378 addtrigger true

1/launch 52:7 0379 push $periapsis <<--INSTRUCTION POINTER--

1/launch 52:19 0380 push 640000

1/launch 52:17 0381 gt

1/launch 52:17 0382 not

1/launch 52:17 0383 br.false 21

1/launch 53:1 0384 push $throttle*

1/launch 53:1 0385 push 3

1/launch 53:1 0386 store

1/launch 53:1 0387 push 72

1/launch 53:1 0388 addtrigger false

1/launch 53:1 0389 push throttle

1/launch 53:1 0390 push True

1/launch 53:1 0391 call toggleflybywire()

1/launch 54:1 0392 push $mydir*

1/launch 54:1 0393 push 68

1/launch 54:1 0394 store

1/launch 55:1 0395 push $steering*

Ok, I'll try to use only one "lock" command.

____

The same...

The error appears near

wait until ETA:APOAPSIS < 60.

string, anyway.

And another question.

Does anyone knows, how to stage with RealFuels engines?

The stage:liquidfuels doesn't work for it.

I've tried to use ENGINE:THRUST parameter, but it said that engine parameter is not declared...

Edited by MaxP

Share this post


Link to post
Share on other sites

And another question.

Does anyone knows, how to stage with RealFuels engines?

The stage:liquidfuels doesn't work for it.

I've tried to use ENGINE:THRUST parameter, but it said that engine parameter is not declared...

The liquidfuel can be replaced with any resource name so just change it to stage:[whatever your engine burns].

My preference for staging is to do this though:

When efo THEN {
STAGE.
SET efo TO FALSE.
PRESERVE.
}.
UNTIL done {
LIST ENGINES IN l_eng.
SET efo TO FALSE.
FOR ENG IN l_eng{
IF ENG:FLAMEOUT{
SET efo TO TRUE.
}.
}.
}.

so long as any new engines are in the same stage event as the decouplers that will stage any engine liquid or solid whatever it is burning, and works with asparagus staging too, without having to put in a value for the tank sizes.

the rest of the launch script can either be done as when triggers or if conditions inside the until loop.

Share this post


Link to post
Share on other sites
The liquidfuel can be replaced with any resource name so just change it to stage:[whatever your engine burns].

Thanks, I forgot to activate stage before ))

Please consider on you script:

- what is efo?

- what s PRESERVE?

Didn't find anything on it.

Share this post


Link to post
Share on other sites

Sorry that was only a segment of a larger script.

The first section of the script (where you set all the variables) would need to include:

SET done TO FALSE. - done is just a variable that has I have set as a boolean toggle.

SET efo TO FALSE. - again efo is another custom toggle set up by the script (standing for engine flame out, but you can use whatever you want).

PRESERVE. - when included in a trigger (on / when) means that it can be triggered more than once. info on that here.

Edited by TDW

Share this post


Link to post
Share on other sites
Thanks, I forgot to activate stage before ))

Please consider on you script:

- what is efo?

- what s PRESERVE?

Didn't find anything on it.

efo is just a variable that's created and used in that snippet. The name is probably short for "engine flame-out".

The PRESERVE statement tells kOS to keep the WHEN trigger in place and allow it to fire again, instead of the default behavior of removing it after it fires once. Documentation at http://ksp-kos.github.io/KOS_DOC/command/flowControl/index.html#PRESERVE .

Share this post


Link to post
Share on other sites

Thanks, I'll try.

LIST ENGINES IN l_eng. - can you bring an example of setting l_eng variable?

And about the previous problem - here is my new script for ascending.


lock throttle to 1.
declare parameter MyDIR.
declare parameter ANGL.
declare parameter Y.
declare parameter VYSOTA.
lock VYSOTA to SHIP:ALTITUDE.
lock ANGL to (1.2*(VYSOTA/1000)-(VYSOTA/1500)).
lock Y to (90-ANGL).
lock MyDIR to HEADING(90,Y).
stage.
print "Launch".
lock steering to up + R(0,0,270).
wait until VERTICALSPEED > 100.
lock steering to MyDIR.
print "Beginning gravity turn".
wait until (1.2*(VYSOTA/1000)-(VYSOTA/1500)) > 80.
unlock MyDIR.
set MyDIR to HEADING (90,Y). //adjusting angle to ~10 deg.
wait until APOAPSIS > 640000.
lock throttle to 0.
lock MyDIR to HEADING(90,0).
clearscreen.
print "Warping to apoapsis".
set warp to 4.
wait until SHIP:ALTITUDE > 620000.
set warp to 0.
lock throttle to 1.
wait until SHIP:APOAPSIS > 650000.
unlock throttle.
set throttle to 0.
unlock steering.
break.

I'm getting the same error, as on picture above, but the string is "set warp to 0", with pointer on the first letter.

The error appears before 640 km. All works except warp, and program not ending.

Any ideas? :)

Edited by MaxP

Share this post


Link to post
Share on other sites
Thanks guys, I'll try.

And about the previous problem - here is my new script for ascending.


lock throttle to 1.
declare parameter MyDIR.
declare parameter ANGL.
declare parameter Y.
declare parameter VYSOTA.
lock VYSOTA to SHIP:ALTITUDE.
lock ANGL to (1.2*(VYSOTA/1000)-(VYSOTA/1500)).
lock Y to (90-ANGL).
lock MyDIR to HEADING(90,Y).
stage.
print "Launch".
lock steering to up + R(0,0,270).
wait until VERTICALSPEED > 100.
lock steering to MyDIR.
print "Beginning gravity turn".
wait until (1.2*(VYSOTA/1000)-(VYSOTA/1500)) > 80.
unlock MyDIR.
set MyDIR to HEADING (90,Y). //adjusting angle to ~10 deg.
wait until APOAPSIS > 640000.
lock throttle to 0.
set MyDIR to HEADING(90,0).
print "Cruising to apoapsis".
wait until SHIP:ALTITUDE > 630000.
[B]lock throttle to 1.[/B]
wait until SHIP:PERIAPSIS > 640000.
unlock throttle.
set throttle to 0.
unlock steering.
break.

I'm getting the same error, as on picture above, but the string is "lock throttle to 1", with pointer on the first letter.

The error appears before 640 km.

Any ideas? :)

What happens if you change the reference to APOAPSIS a few lines back to SHIP:APOAPSIS? And is there supposed to be a space between HEADING and the parentheses six lines before the bolded line? It sounds like something earlier in the code is leaving the parser in a state that's only detected as an error when it finds the beginning of the LOCK statement.

Share this post


Link to post
Share on other sites
What happens if you change the reference to APOAPSIS a few lines back to SHIP:APOAPSIS?

Changed, so VERTICALSPEED to SHIP:VERTICALSPEED, no changes.

And is there supposed to be a space between HEADING and the parentheses six lines before the bolded line?

Works fine even without it, but fix it, just in case.

that's only detected as an error when it finds the beginning of the LOCK statement.

Is there need to unlock throttle before locking it to 1?

P.S. As the game cannot warp time when the engines throttled up, I've add a "wait 2." command before "set warp to 4.". Now it crashes "into terrain" just after the printing command ))

print "Warping to apoapsis".
wait 2.
set warp to 4.
wait until SHIP:ALTITUDE > 620000.
set warp to 0.
lock throttle to 1.
wait until SHIP:APOAPSIS > 650000.

Edited by MaxP

Share this post


Link to post
Share on other sites
What happens if you change the reference to APOAPSIS a few lines back to SHIP:APOAPSIS? And is there supposed to be a space between HEADING and the parentheses six lines before the bolded line? It sounds like something earlier in the code is leaving the parser in a state that's only detected as an error when it finds the beginning of the LOCK statement.

I can save you a little wasted time trying to find out what "you" are doing wrong by pointing out that we've discovered you might be hitting a bug in the kOS code that we've had a very hard time reproducing with enough regular consistency to be able to track it down and find the exact cause of it. It has something to do with KSP firing off one of its automated "quicksave" events while a kOS program is running code. The code that KSP fires off in kOS during the autosave is the same code that it triggers when you save&quit, but there's something about it happening during autosave that makes it trigger the problem, but not consistently, and not all the time, which is why we've been having a heck of a time tracing it down to fix.

You seem to have a case where the problem actually does happen all the time, but it's wandering around exactly *when* during the code it happens because of precise timing alterations. We're trying to fix it, or at least find a way around it.

In the meantime, can you save us a snapshot of what your stuff looks like right now while the problem is still reproducible so we can use it to try to solve the problem? The inability to reproduce it regularly has been the problem on our end and you seem to have a case where it reproduces all the time.

Oh, and changing this setting temporarily might help you work around the problem until we get it fixed:

Open your settings.cfg in your KSP folder, and change this line:

AUTOSAVE_INTERVAL = 300

Setting a really big number there instead. This is the number of seconds between autosaves and setting it really big is the only way to effectively disable KSP's autosave, since they didn't put that setting on the user interface screen.

Share this post


Link to post
Share on other sites

Thanks, but I don't want to spend your time for this, till I'm new to KoS and depths of KSP, and my game slowly turns into an extremly unstable combine with over 9000 mods - anything, but not a game.

So for this time I prefer to use MechJeb, although it doesn't supports RT2.

But if someone would be interested in described bug, I can provide full log and the list of mods.

Share this post


Link to post
Share on other sites

As far as I can tell, v0.14 seems to be working fine with 0.25, also haven't run into the crippling half my ship missing bug either with it :)

Share this post


Link to post
Share on other sites

New Version

v0.14.1

This is a minor release to fix a few major issues.

* Kerbal Space Program 0.25 Support

* OnSave and OnLoad should no longer disappear your craft. This is a bit of a stop-gap fix that doesn't guarantee that the kOS part will be happy, but at least your craft will still be there.

* Resolves #257 by unbinding the X key from throttle cutoff while the window is in focus.

* KSP AVC Support

* Added Body:RotationalPeroid

Edited by erendrake

Share this post


Link to post
Share on other sites
New Version

v0.14.1

This is a minor release to fix a few major issues.

* Kerbal Space Program 0.25 Support

* OnSave and OnLoad should no longer disappear your craft. This is a bit of a stop-gap fix that doesn't guarantee that the kOS part will be happy, but at least your craft will still be there.

* Resolves #257 by unbinding the X key from throttle cutoff while the window is in focus.

* KSP AVC Support

* Added Orbit:RotationalPeroid

Awesome :D

Just a note though Orbit:RotationalPeriod hasn't been added, but body:rotationperiod has, I assume thats what you meant?

But thank you for putting it in :)

Edited by Joe32320
Me can speak english

Share this post


Link to post
Share on other sites

Very grateful for adding the rotational period, that will be very helpful for setting up generic geosync orbits.

One thing I've noticed in the newest update, support for remote tech doesn't seem to be working any more. It worked great in the previous version of both. I wonder if it's a collision related to the remote tech 1.5 update.

I absolutely love this mod though. So very useful. Really give you full control of the vessel and lets you do complicated maneuvers without relying on a tool like mechjeb.

Share this post


Link to post
Share on other sites
Awesome :D

Just a note though Orbit:RotationalPeriod hasn't been added, but body:rotationperiod has, I assume thats what you meant?

But thank you for putting it in :)

You are of course correct, do you know how many places i have to edit that now! Thanks :)

Very grateful for adding the rotational period, that will be very helpful for setting up generic geosync orbits.

One thing I've noticed in the newest update, support for remote tech doesn't seem to be working any more. It worked great in the previous version of both. I wonder if it's a collision related to the remote tech 1.5 update.

I absolutely love this mod though. So very useful. Really give you full control of the vessel and lets you do complicated maneuvers without relying on a tool like mechjeb.

Tell me more about it being broken? you dont have local control without a connection anymore? more input required because i would like to get this fixed!

P.S. you are both very welcome :)

Share this post


Link to post
Share on other sites

I mainly use kOS to automate stuff (like with my Ornithopter). I am looking for better interaction with kOS. That would include entry of data at runtime other than via the action groups. Since kOS is catching keypresses nicely when the console is active, I hope this will be available some time.

Also, printing at x/y coordinates on the screen would be lovely.

This would enable us to create simple dashboards and UIs. (Ncurses for kOS :)

Share this post


Link to post
Share on other sites
I mainly use kOS to automate stuff (like with my Ornithopter). I am looking for better interaction with kOS. That would include entry of data at runtime other than via the action groups. Since kOS is catching keypresses nicely when the console is active, I hope this will be available some time.

Also, printing at x/y coordinates on the screen would be lovely.

This would enable us to create simple dashboards and UIs. (Ncurses for kOS :)

Before I realized I was being way too optimistic about my own abilities (and time management skills), I looked at working kOS into rasterProp's IVA console. Maybe even creating a small number pad-ish keyboard to allow the Kerbonauts to enter in some basic info. That would, of course, require something akin to ncurses for display on the prop monitor. And an input method of some sort (tied to a when trigger, of course, since blocking I/O would suck really, really bad)...

Once I started realizing how much work it would be, I decided to stop trying to do it myself (since it would also require learning C#, Unity modelling, and texturing), and try to encourage people with more talent and time than I have (i.e., someone single and/or childless). Seriously, it just needs a num-pad and some cursor/selector buttons. Hell, go old-school and enter numbers with dials and an "Enter" button. You just have to pay very close attention to what's being prompted for... Bonus points for wood paneling and nixie-style input displays...

Nixie displays... Maybe I need to wander over to that KSP<->Arduino external console thread... Or get more coffee... :)

Share this post


Link to post
Share on other sites

Also, printing at x/y coordinates on the screen would be lovely.

This would enable us to create simple dashboards and UIs. (Ncurses for kOS :)

check out the PRINT AT command

http://ksp-kos.github.io/KOS_DOC/command/terminal/index.html

Before I realized I was being way too optimistic about my own abilities (and time management skills), I looked at working kOS into rasterProp's IVA console.

There are so many of these out there for me too. Steven and I have said that it is too bad kOS doesnt pay because there is no lack of work to do.

Share this post


Link to post
Share on other sites
Tell me more about it being broken? you dont have local control without a connection anymore? more input required because i would like to get this fixed!

P.S. you are both very welcome :)

Loss of local control (as expected), but also the kos script stops running (just like it did before I turned on the RT2 in config). So on a rocket with no antennae, I hit the 3000m mark and then the throttle goes to zero, automated control fails, and I cannot recover using local control. I even tried to renable the RT2 flag at the beginning of the script execution. I didn't notice any exceptions in the debuging log, but I would have to run it again to confirm (can do tonight).

Thanks for the quick response!

Edited by hvacengi

Share this post


Link to post
Share on other sites
Tell me more about it being broken? you dont have local control without a connection anymore? more input required because i would like to get this fixed!

P.S. you are both very welcome :)

Loss of local control (as expected), but also the kos script stops running (just like it did before I turned on the RT2 in config). So on a rocket with no antennae, I hit the 3000m mark and then the throttle goes to zero, automated control fails, and I cannot recover using local control. I even tried to renable the RT2 flag at the beginning of the script execution. I didn't notice any exceptions in the debuging log, but I would have to run it again to confirm (can do tonight).

Thanks for the quick response!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.