Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

I'm not having that problem here. I'm seeing lines with multiple variable and literal strings printing fine.


print missiontime + ": Stage 1 separation.".
print "MECO: " + missiontime + " " + altitude.
print missiontime + ": " + status + " " + body.
print alt:apoapsis + " x " + alt:periapsis.

All of these have worked fine.

you have version 4.4?

I was using version 4.2 just this morning. I wrote the script and it worked just fine. I exited the game and DLed the new 4.4 dll. No more worky. I didn't change a thing from the functioning script.

Edited by Payload
Link to comment
Share on other sites

Is it me, or is the break command giving syntax errors? I have a program with an infinite loop that I'd like to cancel on a simple buttonpress. So the loop contains the line:

"ON AG9 BREAK.". For some reason this gives me a syntax error. If I put the break command between brackets the program only experiences a syntax error when I press 9. So that sort of works, but it is rather cludgy and prevents me from doing anything after the infinite loop. Am I just failing at something simple here, or did I find a bug?

Check for another break condition. Such as.... ON AG9 SET X TO 1. UNTIL X = 1 { do this }.

I posted an example script a few pages ago that has examples of a working UI.

If you are relying on BREAK to exit loops you are doing it wrong anyway. Loops should always have a breakout planned before you even put anything in them.

Edited by Payload
Link to comment
Share on other sites

I really hate to be the one to nag, but I'm not sure if my response to your last comment to me was overlooked, Kevin. Programs still won't be saved to the Archive folder, and I checked I have the latest reversion (even re-downloaded it) and triple-checked that the folder is in the right place. I have KSP installed on the desktop so it shouldn't have anything to do with permission issues, either.

What steps are you taking? I've just tried it and I'm able to create a new txt file in the archive folder by switching to archive and editing and saving a script.

EDIT:

Did you install it to Gamedata or by using the old directory structure.

Edited by Cpt. Kipard
Link to comment
Share on other sites

you have version 4.4?

I was using version 4.2 just this morning. I wrote the script and it worked just fine. I exited the game and DLed the new 4.4 dll. No more worky. I didn't change a thing from the functioning script.

Yes, I just downloaded the new version this morning.

Link to comment
Share on other sites

So has anyone figured out the syntax for using things like vessel status or body yet?

I keep running into the same wall here.

I want to know if my vessel is landed, or more specifically, for my code to know. But I've tried everything I can think of and I can't access status.

I've tried

if status = landed

if status == landed

if status = "landed"

if status:landed

if landed

I've got no ideas from here.

Link to comment
Share on other sites

What steps are you taking? I've just tried it and I'm able to create a new txt file in the archive folder by switching to archive and editing and saving a script.

EDIT:

Did you install it to Gamedata or by using the old directory structure.

1. Install kOS in old directory structure - with PluginData folder inside Plugins folder as it is by default.

2. Start KSP.

3. Go to launchpad and open up the console.

4. Make sure I'm using Volume 0 (Archive).

5. Write program, press F5 (save). "SAVED" message does not appear, but it does when I save to volume 1, which has no name or folder anywhere in PluginData. Either way, the program does not appear on the list of either volumes after the flight has ended.

Link to comment
Share on other sites

So has anyone figured out the syntax for using things like vessel status or body yet?

I keep running into the same wall here.

I want to know if my vessel is landed, or more specifically, for my code to know. But I've tried everything I can think of and I can't access status.

I've tried

if status = landed

if status == landed

if status = "landed"

if status:landed

if landed

I've got no ideas from here.

Why are you trying to check for landed anyway? It's just the status of your ship according to the game. You need to set your own landed condition.


until landed = 1
{
set Ralt to alt:radar.
lock steering to up + R(0,0,180).
if verticalspeed > -2
{ lock throttle to 0. }.
if verticalspeed < -2
{ lock throttle to .75. }.
if Ralt < 3.5
{ set landed to 1. }.
}.

Before we had radar alt I was using if verticalspeed < -.2 { set landed to 1. }. and that worked just fine.

About the string concatenation, see if this works for you. I tried concatenation in the console and it worked. When I run the program it always fails at the same line.


print "Select your orbit altitude.".
print "--------------------------------".
print " ".
print "Default orbit alt is set to " + tOrbit.
print " ".
print "Use action group 9 to add 10Km to orbit alt.".
print " ".
print "Use action group 8 to remove 10Km from orbit alt.".
print " ".
print "Use action group 7 to confirm orbit alt.".

For me program always halts at t of tOrbit. Very strange. I suspect it may be because the arrangement or the blank lines. Even when I type this in console print "Default orbit alt is set to " + tOrbit. I get a fail. Yes I initialized tOrbit first just to be sure. Try it yourself. Unless there are more than one version 4.4. something is amiss.

fRMHcDS.jpg

What now we cant use variables that start with "T".? HAHAHAHA

Edited by Payload
Link to comment
Share on other sites

About the string concatenation, see if this works for you. I tried concatenation in the console and it worked. When I run the program it always fails at the same line.


print "Default orbit alt is set to " + tOrbit.

For me program always halts at t of tOrbit. Very strange. I suspect it may be because the arrangement or the blank lines.

Very strange indeed.

I've tried a few things. It doesn't seem to like your variable name. Try renaming it something that doesn't use "orbit" in the name, and make sure you initialize it before trying to use it. It doesn't seem to have anything to do with blank lines, because I stripped everything out except the print statement, and a SET..TO line.

Link to comment
Share on other sites

And then the user makes a perfectly circular orbit or flies really well, and then your program ruins everything.

No because the loop isn't executed until it's falling 200 above radar alt because the previous loop doesn't break until then. To be frank about it. If you are anywhere near orbit and you have some loop from a landing program checking for vertical speed less than that, then you are doing something way wrong.

Also now we can have compound if. If alt:radar is < x and vertical speed is < x { set landed to 1 }. Checks for both conditions.

Here is the whole thing.

Simple lander test.

This style is called lasagna. It uses more drive space but everything is compartmentalized so it's easy to debug and expand.


clearscreen.
set landed to 0.
print "Five Seconds Until Liftoff!".
wait 5.
lock throttle to 1.
stage.
wait 1.
stage.
toggle gear.
set Ralt to alt:radar.

until Ralt > 2500
{
set Ralt to alt:radar.
lock throttle to 1.
lock steering to up + R(0,0,180).
if verticalspeed > 100
{ lock throttle to 0. }.
}.

until Ralt < 1000
{
set Ralt to alt:radar.
lock steering to up + R(0,0,180).
if verticalspeed > -100
{ lock throttle to 0. }.
if verticalspeed < -100
{ lock throttle to 1. }.
}.

until Ralt < 100
{
set Ralt to alt:radar.
lock steering to up + R(0,0,180).
if verticalspeed > -30
{ lock throttle to 0. }.
if verticalspeed < -30
{ lock throttle to .75. }.
}.

toggle gear.

until landed = 1
{
set Ralt to alt:radar.
lock steering to up + R(0,0,180).
if verticalspeed > -2
{ lock throttle to 0. }.
if verticalspeed < -2
{ lock throttle to .75. }.
if Ralt < 3.5
{ set landed to 1. }.
}.

Ok we need a separate thread for these script discussions guys. Lets get one setup in the science area. Perhaps a collaborative works thread to set up a basic UI autopilot. We can all have modules to do and discuss the methodology there.

Edited by Payload
Link to comment
Share on other sites

Quick bug report by the way,

you need values in the running code to have some kind of catch for possible NaN values, such as MAXTHRUST. Although 0.00 comes out on print, it is running code with NaN values. This is what causes the weird glitches on the graphics if you do this, as KSP tends to go a bit mad when NaN happens.

Link to comment
Share on other sites

So, I wrote a very basic PI altitude controller. It works great! It has quite bit of overshoot for my testing craft, but you can fix that by tweaking the PI parameters. Rock steady at the desired altitude:

Clearscreen.
print "Launch!".
stage.

set TargetH to 50.
lock steering to up + R(0,0,180).
set I to 0.
set deactivateFlag to 0.
on AG9 set deactivateFlag to 1.

until deactivateFlag=1 {
set P to 0.02*((TargetH - ALT:RADAR)-verticalspeed).
set I to 0.02*((TargetH - ALT:RADAR)-verticalspeed + I).
lock throttle to P+I.
}.


print "Thanks for flying!".
lock throttle to 0.

I'm planning to expand it to allow translation control and height control. The latter seems easiest (no nasty angle calculations) so I was trying to allow the user to adjust the target height in flight.

My first method was very simple, just add the following before the control loop:

 on AG10 {
TargetH = TargetH + 5.
print "New hover height = " + TargetH.
}.

and a corresponding counterpart to decrease hover height. However, I found that the system refused to reenter the loop after the execution of a height change (Or even just a simple print "x"). Don't really understand why, the deactivation flag wasn't touched and this code segment is right before the control loop. So I'd think it'd jump right back in. Anyway, the second thing I tried was to place this bit of code inside the control loop. However, it seems loops don't like embedded brackets. So this method only allows me to execute a single command, and it gets rather spammy.

Anyone has a good idea on how to solve this without kludging something together from if statements and flags?

Link to comment
Share on other sites

.... Ok we need a separate thread for these script discussions guys. Lets get one setup in the science area. Perhaps a collaborative works thread to set up a basic UI autopilot. We can all have modules to do and discuss the methodology there.

Ok start one.

Link to comment
Share on other sites

You might try running "copy program to Archive." by name instead of number after writing your program. I've seen archive show up as volume 1 before (multiple computer units on the vessel).

Ah, so copying it to Archive after saving it worked. I didn't know you had to save it and then also copy it to the volume you want.

Link to comment
Share on other sites

Ah, so copying it to Archive after saving it worked. I didn't know you had to save it and then also copy it to the volume you want.

Hmm, you should be able to save directly to the Archive volume without having to use copy, even on a fresh install. I'll do some more testing on this.

Link to comment
Share on other sites

Requests:

I'd like to have access to the orbital period of the vessel. The game clock would also be useful.

Figuring out the orbital period is easy. T = 2*pi*sqrt( (Ap+Pe)^3/8u) where U is the gravitational parameter for the parent body. All these operations are already implemented (At least, I think we have powers) so you can use a small script to calculate it. All you need to do is feed it sufficiently accurate values for pi and u.

Link to comment
Share on other sites

Try 0.45, I made AND And OR require whitespace on both sides, and fixed the order they're processed in.

You should mention that capitalization of AND/OR is required in wiki. I am in favor of more Case tense separation as long as you put it in the wiki. But yea now my launch to orbit script is finally working again. TY.

EDIT:

HAHA now the scripts work. Do I need to update the part and not just the .dll? Because now when the rocket gets up to somewhere around 6000m, A part of it stays there and the rest goes up and the rocket zooms off the top of my screen. I think it has something to do with your part handling.

I checked and the parts are the same. Sooo. .dll related?

Don't worry. You aren't the first to have the stretchy rocket problem. I know several mods have had it in the past. The last I remember was the procedural fuel tanks.

Edited by Payload
Link to comment
Share on other sites

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