Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

Suggestions: (Based on them not being present in the documentation)

1) Solid rocket fuel variable! STAGE:SOLIDFUEL

2) Other logic gates: ELSE, AND, OR, NAND, NOR and XOR.

3) Functions: Allow the creation of standardized functions that can be saved and used independently (but interchangeably) with the current "procedure files" system.

4) Body-specific, or preferably Current-body system variables: Boolean:HasAtmosphere (self-explanatory), Int/Float/Double:AtmosphereInfluence (altitude of vacuum, in meters), etc...

5) [Far in the future?] User-defined class structures!

----------

Please implement them as soon as possible! So that I ("we") can make things like, for example, an any-planet automatic launch function!

Code-logic:

AutoOrbitLaunch( GTurnAlt, OrbAlt )
{
//"Go up" code...

If ( BODY:HasAtmosphere )
{
UNTIL ( ALTITUDE >= GTurnAlt )
{
IF ( STAGE:SOLIDFUEL == 0 OR STAGE:LIQUIDFUEL == 0 OR STAGE:OXIDIZER == 0 ) { Stage. PRINT "Staging spent tanks!". }
}
// Begin and do gravity turn.
UNTIL ( ALTITUDE >= BODY:AtmosphereInfluence OR APOAPSIS >= OrbAlt )
{
SET RTOAOA TO [Insert impossible math here]. //RTOAOA means "Rotation To Optimal Angle Of Ascent" ... Basically, some complicated math to determine best angle of ascent here.
LOCK Direction TO UP + RTOAOA.
}
}
Else
{
//Same as above but optimized for vacuum ascent.
}

//Circularization code...
}

Link to comment
Share on other sites

Ok, it's nearly 4am so I'd better get to sleep soon. Tossing this out there to see what people think at this early stage.

http://mononyk.us/ArcEditor_prealpha_28-8-13.zip

This is a plaintext editor for kOS's archive, in a very early alpha form. If installed correctly, it will appear in your command pod menu as 'Open ArcEditor'. Clicking this brings a pretty simple form, with a filename field, a load button, a textarea and a save button. If the editor finds a matching file in kOS's archive, it loads it up for you to edit. You can copy and paste and do many other things you'd expect from a plain text field. It is not exactly an IDE yet. Clicking 'save' will write the file to the archive in the correct format.

HOWEVER. (known issues)

Yes, the text area doesn't match the window size. I know. The "Open ArcEditor" does not change to "Close ArcEditor". I know. These are small chance, because:

At the moment, it requires a KSP restart to get the file to stick. This is not good. It is because kOS loads the whole Archive into memory eveidently only at the very start, and so it wont see any of the changes you've made. So if you make your edits and try to load the program immediately, even to switch vessels, or even to exit to the main menu. it will not work. A reset is needed.

This is obviously not good, but again, I need to go to bed. We'll see what tomorrow brings.

Source code in the zip file; license too. License is GPL3 as it uses code from kOs.

Distribution also features ModuleManager

http://forum.kerbalspaceprogram.com/showthread.php/31342-0-20-ModuleManager-1-3-for-all-your-stock-modding-needs

And sarbian's ModuleManager Extension, which will add kOS and ArcEditor to all Command pods and probes.

https://github.com/sarbian/MMSarbianExt/

Installation:

1. The module manager files should go into GameData, if you have any of them already, try not to duplicate them.

2. The ksomething.dll MUST go alongside the kOS.dll to have proper access to its archive.

3. Source zip file can be inspected, used in your own projects, or deleted. It is not very well commented, yet, as it's 4am.

As with all GPL software, this comes with ABSOLUTELY NO WARRANTY.

Edited by GavinZac
Link to comment
Share on other sites

T his is a plaintext editor for kOS's archive, in a very early alpha form.

I feel awful reading this, because I can see how hard you've worked on it. 0.4 is actually going to have archive files stored in plaintext in a folder.

I tested it last night and it does maintain synchronicity with the filesystem at all times. The arc format will be discontinued.

I can only hope that your project can easily be changed into something that is helpful with editing files offline in the new system which should be released in the coming days.

Link to comment
Share on other sites

I'm not entirely sure if this has been brought up by anyone, but I think It hasn't been, but will you be adding a part for probes and 2.5 meter rockets?

See post #149.

Yes, I had envisioned different parts with different hard drive sizes, speed of CPU, tonnage, and cost. Even expansion parts that offer a volume and no CPU.
0.4 is actually going to have archive files stored in plaintext in a folder.

Glad to hear both of these. This whole thing is great.

Now for some more requests/clarifications...

Can we get the AND, NOT, and OR at least?

In the readme file, it shows what looks like comments. Does the system actually treat these as comments?

The WHEN.. THEN sets up a one-time trigger, correct?

We have access to some maneuver node information. Can we get burn time information as well?

Link to comment
Share on other sites

Can we get the AND, NOT, and OR at least?

Yes, no ETA on that.

In the readme file, it shows what looks like comments. Does the system actually treat these as comments?

No, but there will be commenting. Probably the same style you see there. I can't think of a good reason not to use double slashes.

The WHEN.. THEN sets up a one-time trigger, correct?

Yes, and so does ON. But I'm pretty sure ON should be re-triggerable and possibly WHEN.. THEN too. Thoughts?

We have access to some maneuver node information. Can we get burn time information as well?

Let me get back to you on that.

Link to comment
Share on other sites

Yes, no ETA on that.

No, but there will be commenting. Probably the same style you see there. I can't think of a good reason not to use double slashes.

Excellent.

Yes, and so does ON. But I'm pretty sure ON should be re-triggerable and possibly WHEN.. THEN too. Thoughts?

I think that there's room for both single-shot and repeatable triggers.

Let me get back to you on that.

I'm not in any hurry. The three day weekend isn't for a few more days. :)

I was just reading through the document, and it struck me that it was the one node info we seemed to be missing.

Link to comment
Share on other sites

I feel awful reading this, because I can see how hard you've worked on it. 0.4 is actually going to have archive files stored in plaintext in a folder.

I tested it last night and it does maintain synchronicity with the filesystem at all times. The arc format will be discontinued.

I am getting extremely, extremely excited about this!

With the WHEN function as you mentioned, this means we can use it by placing something like

When stage:liquidfuel = 0 { stage. }.

at the very top of our code, and it'll do that while doing everything else, right? Such as waiting for new steering locks etc

Link to comment
Share on other sites

Suggestions: (Based on them not being present in the documentation)

1) Solid rocket fuel variable! STAGE:SOLIDFUEL

Seconded. I have a family of ~30 ton lifters with liquid fuel tanks mounted on top of the SRBs that feed into the central tank. MechJeb shuts the main engines down about 30 seconds into the ascent, and restarts them after the SRBs burn out. As a result, the 6-booster and 8-booster variants still have fuel in the booster-top drop tanks when the SRBs burn out, bringing the TWR below unity until they are manually staged away. I considered using

<SolidFuel> = 0

but realized that other solid-fueled motors in the payload (e.g. launch escape systems, the Kosmos VA deorbit motor, my Duna lander's deobit and braking pack, etc.) would interfere with this.

Edited by Fail-Man 3D
Deleted an errant comma after a [CODE] block
Link to comment
Share on other sites

I considered using
<SolidFuel> = 0

but realized that other solid-fueled motors in the payload (e.g. launch escape systems, the Kosmos VA deorbit motor, my Duna lander's deobit and braking pack, etc.) would interfere with this.

Pencil, paper, and start adding them up. I did this for liquid fuel the first time.

So how long until someone posts a video of a Munshot using only this system?

Link to comment
Share on other sites

I was trying to figure out how to make a simple landing autopilot using this

Q9SuZJA.jpg

But for some reason the "if verticalspeed" thing doesn't work. It just leaves the throttle at %10 until it crashes. What am I doing wrong?

It's because you don't have it in a loop. otherwise it will just go through the if statement once then go on its way. Do something like this:

until verticalspeed = 0{
if vertical speed > 10{
set tVal to tVal + 0.1.
}.
}.

If I'm not mistaken that should work, please correct if I'm wrong.

Edited by neogoo123
wanted to clarify.
Link to comment
Share on other sites

Pencil, paper, and start adding them up. I did this for liquid fuel the first time.

So how long until someone posts a video of a Munshot using only this system?

It already accounts for solid fuel booster. I've written programs that drop my SRBs the moment they burn out.

Link to comment
Share on other sites

It already accounts for solid fuel booster. I've written programs that drop my SRBs the moment they burn out.

I haven't tried anything with solid rocket boosters. But it should be working with everything in the resources section. Hey... that means we can add coding to open the solar panels when electricity runs low?

Would that work? (Ignoring the incorrect syntax, and assuming AG1 opens the panels...) Run a "WHEN <power> < 5% { TOGGLE AG1. }." and then have other programs running in the background?

Edit:

This should work, correct?

WHEN <ElectricCharge> < 20 THEN PRINT "TEST".

It gives me:

Unrecognized term: ''.

Also, does the computer itself draw power?

Edited by razark
Link to comment
Share on other sites

The resolution problem happen when you select "Texture" (Eight/Quarter/Half/Full) Resolution in the graphics settings, happened to me too =)

Awesome thank you! I didn't even notice that setting before.

I realize now that it's a mip-mapping issue. A fix for this will be in the 0.4 release.

Link to comment
Share on other sites

Has anyone found a way to extract values off R() or things like PROGRADE, RETROGRADE etc? I would like to use those values for a script that attempts to kill horizontal velocity while hovering.

There isn't a way yet to access subelements of R(). It will probably be something like PROGRADE:ROLL, RETROGRADE:YAW etc.

Link to comment
Share on other sites

WHEN <ElectricCharge> = 20 THEN PRINT "TEST".

This doesn't give an error, but it doesn't seem to trigger, either.

I'll try the stage:electriccharge next flight. I'm trying the reentry program now.

Yes. The screen will go blank if it runs out of power.

And so it did. Right after popping the chute. Watching that power drain as it approached deployment altitude had a nice pucker factor. I either need a quicker reentry or I need to keep the service module longer.

Edited by razark
Link to comment
Share on other sites

It's because you don't have it in a loop. otherwise it will just go through the if statement once then go on its way. Do something like this:

until verticalspeed = 0{
if vertical speed > 10{
set tVal to tVal + 0.1.
}.
}.

If I'm not mistaken that should work, please correct if I'm wrong.

It didn't work for me. I also tried "until altitude < 70" but that didn't work either.

Link to comment
Share on other sites

So, I could use a little help. I want to program an escape system sequence using action groups. The sequence is as follows:

AG 1 : Decouple from the main stack and fire the escape tower's SRB's

Wait 1 second.

AG2 : decouple the escape tower

Wait 1 second.

AG3 :Deploy the chute.

So, the following works great when entered as a command line entry :


on ag9 {toggle ag1. wait 1. toggle ag2. wait 1. toggle ag3.} .

As soon as I press '9' it triggers the sequence.

When I try to do this as a script the program just ends.

I tried using a loop as follows:


set x to 0.
until x>0 {
on ag9 {toggle ag1. wait 1. toggle ag2. wait 1. toggle ag3.} . }.

Any pointers as to why this doesn't work would be greatly appreciated.

Edited by Astronut
Link to comment
Share on other sites

I feel awful reading this, because I can see how hard you've worked on it. 0.4 is actually going to have archive files stored in plaintext in a folder.

I tested it last night and it does maintain synchronicity with the filesystem at all times. The arc format will be discontinued.

I can only hope that your project can easily be changed into something that is helpful with editing files offline in the new system which should be released in the coming days.

On the contrary, feel good! That's great news. However, what would really make it easier to maintain a separate editor with as much 'detachment' from yours (to ensure compatibility and that users can easily choose to use either or both) would be a function in kOS that when it reboots, (the "power" funncion) it reloads everything from (real) disk again. Unfortunately I coded with that as an assumption of what powercycling in kOS terminal did and that's why it requires the reset in my editor which is not very user friendly. I don't think there is currently a way to access the kOS "Files" collection.

Edited by GavinZac
Link to comment
Share on other sites

It didn't work for me. I also tried "until altitude < 70" but that didn't work either.

If you copied it directly, then it won't work, I just noticed that I wrote verticalspeed wrong on the second line, there can not be a space in between the vertical and speed, all one word... so:

until verticalspeed = 0{
if verticalspeed > 10{
set tVal to tVal + 0.1.
}.
}.

Link to comment
Share on other sites

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