Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

I'm sorry if this has been asked before, but I haven't found the answer.

When you launch with "lock steering to up + R(0,0,180)" and later do the gravity turn, what is the difference between "lock steering to up + R(0,0,180) + R(0,-60,0)" and "lock steering to up + R(0,-60,180)"?

EDIT: To fix my poor spelling. :-)

Edited by Kethevin
Link to comment
Share on other sites

A small feature request.

I can currently not get this to work.

print velocity:mag.

Basically having the velocity behave like an ordinary vector.

Supposedly although velocity is meant to be a synonym for velocity:orbit it isn't quite. It's probably a good idea to avoid using it and instead use velocity:orbit, like so:

set vorb to velociy:orbit.

print vorb:mag.

Link to comment
Share on other sites

I've been having trouble using if.. then... in side loops. For example the demo launch by Kevin Laity

[..snip..]


set tVal to tVal + 0.02.

Produces the error unrecognised term 'tVal 0.02'

From that it seems as if somehow the program is treating things like strings rather than numbers at some stage, so that the statement:

set tVal to tVal + 0.02.

Is interpreting the "+" sign as a string concatenation instead of as addition.

It doesn't seem valid for it to be doing that. Try various different ways to express it to see if it helps getting KOS to stop treating 'tVal + 0.02' as a string.

Link to comment
Share on other sites

Argggh I'll never get used to learning syntax and code from videos. I miss huge tomes of spiral-bound code books and syntax guides. I wish I wasn't born in the 70's. Ironic considering I learned to code with BASIC, which kOS sort of reminds me of. But I'll check it out I guess.

I'm the same way. I don't think a video is an appropriate way to teach an inherently bookish, textual thing like a programming language. But it's better than nothing and other people can transform the videos Kevin makes into written documentation.

Link to comment
Share on other sites

Every time I try to use the new "set target to xxxx" command with xxxx as either:

mun,

Mun,

"mun",

"Mun",

kerbin,

Kerbin,

"kerbin",

or

"Kerbin".

It just makes the words "no target" appear on the screen and nothing happens.

(Edit: Never mind: I see the problem now. It's inherent to KSP not KOS. KSP won't let you target your current SOI body, nor will it let you target the parent body of your current SOI body. So if you're orbiting the Mun, you can't target the Mun nor can you target the Mun's parent, Kerbin. But you can target anywhere else in the solar system.)

Edited by Steven Mading
Link to comment
Share on other sites

How would I go about locking steering only on a specific axis?

I want the ship to be able to yaw freely, but keep the pitch/roll locked.

When you say "yaw freely" do you mean from live user input on the "A" and "D" keys, or from another variable in the script program somewhere? If it's live user input I don't think there's a way to do it, but if it's from another variable in the program there should be a way.

Link to comment
Share on other sites

From that it seems as if somehow the program is treating things like strings rather than numbers at some stage, so that the statement:

set tVal to tVal + 0.02.

Is interpreting the "+" sign as a string concatenation instead of as addition.

It doesn't seem valid for it to be doing that. Try various different ways to express it to see if it helps getting KOS to stop treating 'tVal + 0.02' as a string.

Before you do any operations on "tVal," you should say "set tVal to 0."This is what I do, it's worked for me. This is during a main engine startup sequence. It's a "smooth" throttle up, instead of an instant 0%->90%.

90%.


print "Main Engine Start.".
print "6". set t to t-1.
stage.
set tVal to 0.
lock throttle to tVal.

until tVal > 0.9
{
set tVal to tVal + 0.08.
}.

When you say "yaw freely" do you mean from live user input on the "A" and "D" keys, or from another variable in the script program somewhere? If it's live user input I don't think there's a way to do it, but if it's from another variable in the program there should be a way.

I would like to know this as well. I know that

lock steering to up + R(0,0,180).
Lock steering to up + R(0,0,90).

will cause the ship to roll, (while going straight vertical) but it does that far too slowly. Is there a workaround?

Edited by Cepheus
Link to comment
Share on other sites

I am having issues with setting up a new node some time in the future. With previous versions it was like this:

set x to node(time+60,0,0,1000).

to define a maneuver node 60s in the future with a 1000m/s prograde burn. Now I get

 Supplied parameter 'time+60' is not a number.

.

Did 0.9.1 mess up with types?

Regards, Andreas

Link to comment
Share on other sites

Trying to return the magnitude of the "nextnode" vector. It seems like the program isn't recognizing "nextnode" as a vector, so nextnode:X, nextnode:Y, nextnode:Z, or nextnode:MAG doesn't work.

The data is all there when I print it, but I can't seem to access it. Locking steering to nextnode works fine.

Is this a bug or am I missing something obvious?

Edit: I figured out that the suffixes are _:prograde and _:normal. _:radial doesn't work so anyone's guess is as good as mine as for that component.

Edit 2: Through exhaustive guesswork I figured out that component 3 is named "Radialout". Computing the magnitude from the three known components is trivial.

I assume the arbitrary data structure is a result of it being pulled directly from KSP and is no fault of kOS.

Edited by mossman
Link to comment
Share on other sites

I am having issues with setting up a new node some time in the future. With previous versions it was like this:

set x to node(time+60,0,0,1000).

to define a maneuver node 60s in the future with a 1000m/s prograde burn. Now I get

 Supplied parameter 'time+60' is not a number.

.

Did 0.9.1 mess up with types?

Regards, Andreas

I just figured this out last night actually. TIME seems to return the universal time in seconds, but not as a number which means it can't be used in node(). the SECONDS suffix returns the same thing, but properly typed as a number. So

set x to node(time:seconds+60,0,0,1000).

should work. Note that SECONDS and SECOND are distinct suffixes.

Link to comment
Share on other sites

I'm sorry if this has been answered before, but has anyone figured a good way of performing the burn for a node accurately? I've gotten the node placed at the right point and starting at the right time, but I can't seem to get the burn to end anywhere near the right point. My code's a mess of different, cobbled together methods right now, and it's performing a circularization burn that's 3km off on both apoapsis and periapsis (if it even works at all).

Edited by Stiggles
Link to comment
Share on other sites

By the way, concerning a possible RemoteTech/kOS compatibility, I think Cilph and Kevin really need to talk, they don't use each other's mod I guess so they don't understand what to do to make both work. Cilph is waiting for a contact, here is the post : http://forum.kerbalspaceprogram.com/threads/56399-0-22-Remote-Tech-2-Build-those-satellite-networks!?p=756045&viewfull=1#post756045. I suggested him a few work-arounds already but he doesn't seem quite interested in a cheap solution. Maybe Kevin would have better ideas ! I know he already has a lot of work on kOS but if he could try to do it that would be great ! I know he likes to add features in each update, and that is a quite demanded one. :wink:

Link to comment
Share on other sites

@Stiggles I think something like this should work:


lock steering to node.
set dV to nextnode:deltav:mag.
lock v1 to velocity:orbit:mag.
set v2 to v1 + dV.

lock throttle to 1.
wait until v1 >= v2.

lock throttle to 0.

I would add a loop to play with the throttle a bit probably and something before to make sure if dV is negative or positive. Maybe there's some other workaround but I think that should work just fine!

Link to comment
Share on other sites

Cliph "It's coming, but most of the work needs to come from the kOS side. Tell them to contact me with their demands."

Ye this is Cliph's response to my request for Remote Tech 2 and kOS compatibility.

Using the 2 mods together would be really fun. Uploading command scripts for probes or rovers with the real limitations of time delay and line of sight. It would be fun!

Link to comment
Share on other sites

For Windows there's the Windows IDE for color syntax highlighting for Kos script, but for UNIXy people like me who prefer editing with the VI text editor even when using Windows, I made a crude VIM syntax file for KOSscript code that should highlight the colors correctly for you if you install the files in the right places if you're a VIM user:

Here's a screenshot while using the koehler color theme. The syntax file doesn't define the actual colors, by the way. It just categorizes things into parts of speech (statements, comments, strings, numbers, identifiers, operators, etc), and then lets the color theme file pick the colors for them. That way it should work with any color theme choice you have.

n4am2a8.png

Note, the usual way for VIM to detect which syntax type it's dealing with is to look at the filename. i.e. if it's called ".java" its a Java file, if it's called ".c" it's C code, etc. But the problem with KOS is that the source code files are named .txt and therefore clash with normal other plaintext files (for which you won't want to have KOS highlighting turned on). Therefore in order to enable syntax highlighting, put this comment at the top of the source file:

//KOS

And the files are set up to look for that on line 1 as the trigger to turn on KOS syntax mode.

Or, alternatively, force kos mode by issuing this command:

 :set filetype=kos

The setup files for it are over here on google docs:

https://drive.google.com/folderview?id=0Bxkeai7oN35fV2xCa0Y1RThSYkU&usp=sharing

Link to comment
Share on other sites

@Stiggles I think something like this should work:


lock steering to node.
set dV to nextnode:deltav:mag.
lock v1 to velocity:orbit:mag.
set v2 to v1 + dV.

lock throttle to 1.
wait until v1 >= v2.

lock throttle to 0.

I would add a loop to play with the throttle a bit probably and something before to make sure if dV is negative or positive. Maybe there's some other workaround but I think that should work just fine!

The above won't work. You need vector math to do it properly you can't just convert vectors to their magnitudes and expect things to work, last time I tried to build code like this in kOS vector math was only implemented for some very specific situations. I requested it but got no response. I'm still hoping Kevin gets round to it. There's a really lame workaround, split the vectors into x/y/z variables and do the math yourself.

A computer system on board a rocket like this one will primarily be used as a navigation tool. You can't do navigation without a proper implementation of vector math. I really like kOS but without vector math it's not usable for me. I'm really eager, I think kOS and a handfull of scripts should be able to replace mechjeb.

Link to comment
Share on other sites

split the vectors into x/y/z variables and do the math yourself.

Yeah I end up having to do the same thing. Vector math is halfway implemented for a few things now, but it still doesn't have everything so sometimes you still have to do it manually:

What is implemented:

Tip -to- tail vector addition:

set newVect to v1 + v2.

(indirectly) scalar times a vector, via the new ":mag" operator:

// Multiply vector v1 by scalar s1, storing the result back into v1:

set v1:mag to (s1 * v1:mag).

What isn't implemented yet is cross products and dot products and matrix transformation multiplications. For those you still have to break it apart into its separate XYZ pieces and run them manually, which in a slow language like KOSscript, is really slow.

Another feature that would be very nice is to transform a Direction into a unit vector. i.e. V( North) to turn the Direction North into a vector of length 1 in the direction of North. Right now I do this by hand with breaking the XYZ parts up and running the rotation matrix transformation math on the rotation angles in the Direction vector, but that's something like 10-15 lines of KOS script to do a thing that I'm sure is done natively in just one fast function call in the underlying 3D engine.

Link to comment
Share on other sites

Suggestion: a way to implement an UDP listner, so it will be possible to send commands to kOS from outside. (or enlighten me please if there is a workaround to achieve the same, like reading external files ormsth)

I am asking this to be able to write a custom/extended control scheme independent from the KSP one. So i am able to implement flybywire, complex commands executed by a press of a switch/key, etc.

EDIT: i noticed a plugin can register custom function calls with kOS so i might go and do such extension myself.

Link to comment
Share on other sites

Suggestion: a way to implement an UDP listner, so it will be possible to send commands to kOS from outside.

This is exactly what I came to ask, but I'd like to see a remote console output as well. Complete remote control, just like NASA uses - upload a program, command the probe to run it, download the results.

Link to comment
Share on other sites

Hey people! Last week I format my computer and now reinstalled KSP and KOS.. But I'm with some trouble running scripts, and I have sure must be something wrong I did, of course!

First, the script is this:


print "Steering Up".
lock steering to up.
print "Throttel 100%".
lock throttle to 1.
print "Launch!".
stage.

It's saved as launch.txt in E:\KSP_win\Plugins\PluginData\Archive folder

On KSP, I open KOS terminal and type:


switch to archive.
run launch.

Then the clamps release the rocket, but it does not ignite. What I forgot?

klQqmyw.png

Link to comment
Share on other sites

Hey people! Last week I format my computer and now reinstalled KSP and KOS.. But I'm with some trouble running scripts, and I have sure must be something wrong I did, of course!

First, the script is this:


print "Steering Up".
lock steering to up.
print "Throttel 100%".
lock throttle to 1.
print "Launch!".
stage.

It's saved as launch.txt in E:\KSP_win\Plugins\PluginData\Archive folder

On KSP, I open KOS terminal and type:


switch to archive.
run launch.

Then the clamps release the rocket, but it does not ignite. What I forgot?

~snip~

My guess would be that the program ends the instant after you launch. kOS probably resets throttle after that happens. Try adding "wait 10." or something after "stage."

Link to comment
Share on other sites

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