Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

In the days before the SQRT operator you had to get a square root by taking something to the power ^0.5 and that worked just fine. Are you sure this doesn't work?

My bad, I tried to raise a negative number to a non-integer power. Now, that I changed the code, everything works just fine!

PS.: Right now the launching program works very well. Maybe I'll post it, when I tweaked it to perfection.

Edited by aNewHope
Link to comment
Share on other sites

You can add IF .. ELSE statement?

Without it, my script for automatic control capacitors (Near Future Propulsion) very ugly.

That is in my (informal) TODO list, you better add an issue in the github tracker (here) so we don't forget about it.

Link to comment
Share on other sites

My bad, I tried to raise a negative number to a non-integer power. Now, that I changed the code, everything works just fine!

Ah, I see. If that non-integer was less than 1, then yeah kOSscript doesn't deal with imaginary numbers. Everything must be representable as a Double.

Link to comment
Share on other sites

Uhm there is no such thing as "lock thrustlimit to 0.5" right? I want to change thrust limit on multiple engines with one command

You can add the relevant engines to a list and then use the FOR command to iterate over it and set the thrust limit for each one (you don't need to use LOCK)

Link to comment
Share on other sites

You can add the relevant engines to a list and then use the FOR command to iterate over it and set the thrust limit for each one (you don't need to use LOCK)

I mean in the documentation I do not see an object to change "thrust limiter" just an object for throttle , you know the slider that you can change from 0 to 100 to limit the power of the engine regardless of the max throttle

Link to comment
Share on other sites

I mean in the documentation I do not see an object to change "thrust limiter" just an object for throttle , you know the slider that you can change from 0 to 100 to limit the power of the engine regardless of the max throttle

That was added in the last update (v11.1) so it may no be in the documentation you're reading (it's in the release notes here).

To access the thrust limiter you first need to build a list of engines (LIST engines IN [variable name]) and then you can read/write a bunch of parameters of each engine, including the thurst limiter.

The now official kOS project location is https://github.com/KSP-KOS and there's a dedicated documentation project where you can find more info (in this particular case here).

Link to comment
Share on other sites

I second this. The lack of "else" has made me write some weird code.

I would say it is the bread and butter of any computer language. I kind of loved the clunky nature of early kOS/KerboScript, but if it is going to be made into a more mature language, it should be included.

Link to comment
Share on other sites

Stupid question inbound guys. :P

Even with my highly noobish coding skillz (outside of Matlab at least), I've more or less managed to make a crude, but universal launch script from scratch. Only thing remaining at the moment is some sort of throttle control to keep my rockets from trying to go faster than the terminal velocity at any given altitude.

After a quick look at the table of terminal velocities on Kerbin at various altitudes on the wiki, I've found that

(altitude/775)^2 + 100)

is a decent enough approximation to the terminal velocity through the first 20km of flight, and then

(altitude/650)^2 - 180

throughout the rest of the atmosphere.

However, I'm not able to transfer the comparison between this approximation and the actual speed into functional throttle commands.

Using T to represent the throttle value, V to represent my approximation and S to represent the square root of the surface speed squared + the vertical speed squared (which is what I assume is my true velocity?), and doing something like this

lock V to ((altitude/775)^2) + 100.
lock S to (((surfacespeed)^2)+((verticalspeed)^2))^(1/2).
set T to 1.
if S > V + 5 {
set T to T - 0.1.
}.
if S < V - 5 AND T < 1 {
set T to T + 0.1.
}.

yet it doesn't seem to want to do like I want it to. I've tried to use "lock T" instead of "set T" as well, but it didn't seem to make much of a difference. I've also tried to just look at the numbers during a flight, and both the value of S and V works fine. It's only T which seems to stay at 1, no matter what. I'm guessing there's some obvious fault in my thinking here, but I can't say that I find it. Like I said, my only previous experience with any sort of scripting is with matlab, and I'm fairly sure this would work there, provided the syntax was right.

Yes, I know there's better ways to do reduce the throttle, and better models to follow, but since I'm still trying to learn my ways around this thing, I figured I wouldn't bother with "harder" maths just yet, but keep to approximations and guestimates. The main point for now is to get something that works, and after it does that, I'll start to refine the mathematics behind it.

Edited by SBaL
Link to comment
Share on other sites

Any chance of, in future, being able to lock steering to normal or antinormal?

We already have prograde, retrograde and up is antiradial. I was going to try doing a cross product of up and prograde or retrograde, which I think would get normal and antinormal, except it turns out the values are in Euler angles, not vectors. My maths-fu isn't strong enough to figure out how to get the normal and antinormal using Euler angles...

Link to comment
Share on other sites

@SBaL: wrap the two IFs with a loop, something like "until false { .... }". Oh, and add parenthesis to the expressions, they work like they should most of the time but there may be some weird behavior with operator precedence.

Link to comment
Share on other sites

That was added in the last update (v11.1) so it may no be in the documentation you're reading (it's in the release notes here).

To access the thrust limiter you first need to build a list of engines (LIST engines IN [variable name]) and then you can read/write a bunch of parameters of each engine, including the thurst limiter.

The now official kOS project location is https://github.com/KSP-KOS and there's a dedicated documentation project where you can find more info (in this particular case here).

Thanks, you have been very helpful

Another question, how do I write "{" and "}" on non english keyboard ? Alt 123/125 does not work in KOS console

Edited by brusura
Link to comment
Share on other sites

1.

Another question, how do I write "{" and "}" on non english keyboard ? Alt 123/125 does not work in KOS console

If it doesn't work in your kOS console, try editing the txt-files directly (It's also much more comfortable IMO.). After you created a program, you can find it in

Kerbal Space Program/Plugins/PluginData/Archive .

2. I have a question myself:

Why the heck does this autostaging - subprogram NOT work (Especially the first half)?

declare parameter use.

if use = 1{
list engines in engl.
for eng in engl{
if eng:flameout = true{
set use to 0.
}
}
}

if use = 0{
stage.
print round(Missiontime) + "s Stage " + St at (1,Log).
set Log to Log+1.
set St to St-1.
print St + " " at (Ic2,Il+4).
}

Whenever I try to read out any info out of the engine-structure kOS just gives me a flagrant error.

Edited by aNewHope
Link to comment
Share on other sites

@SBaL: wrap the two IFs with a loop, something like "until false { .... }". Oh, and add parenthesis to the expressions, they work like they should most of the time but there may be some weird behavior with operator precedence.

Oh yea, all of that is allready inside a loop like

lock S to (((surfacespeed)^2)+((verticalspeed)^2))^0.5.
lock V to ((altitude/775)^2) + 100.
set T to 1.

until altitude > 20000 {
if S > V + 5 {
set T to T - 0.1.
}.
if S < V - 5 AND T < 1 {
set T to T + 0.1.
}.
}.

lock V to ((altitude/650)^2) - 180.

until apoapsis > 60000 {
if S > V + 5 {
set T to T - 0.1.
}.
if S < V - 5 AND T < 1 {
set T to T + 0.1.
}.
}.

Sorry I forgot to mention that. It was kinda late over here when I posted.

Link to comment
Share on other sites

Using T to represent the throttle value, V to represent my approximation and S to represent the square root of the surface speed squared + the vertical speed squared (which is what I assume is my true velocity?)

That makes sense but you don't actually have to do that, and it presumes a flat world rather than a spherical one. As you gain altitude, your actual horizontal speed won't match your surface speed anymore - not exactly - because you're moving out at a larger radius from the center than the surface is. (But under 70,000 it's going to be a rather small error).

You can just use the surface velocity vector instead:

velocity:surface

You can use the pythagorean theorem yourself to get the magnitude, or just use the MAG suffix like so:

velocity:surface:mag

Link to comment
Share on other sites

1.

If it doesn't work in your kOS console, try editing the txt-files directly (It's also much more comfortable IMO.). After you created a program, you can find it in

Kerbal Space Program/Plugins/PluginData/Archive .

2. I have a question myself:

Why the heck does this autostaging - subprogram NOT work (Especially the first half)?

declare parameter use.

if use = 1{
list engines in engl.
for eng in engl{
if eng:flameout = true{
set use to 0.
}
}
}

if use = 0{
stage.
print round(Missiontime) + "s Stage " + St at (1,Log).
set Log to Log+1.
set St to St-1.
print St + " " at (Ic2,Il+4).
}

Whenever I try to read out any info out of the engine-structure kOS just gives me a flagrant error.

Thanks and yes I have the same problem with this, anything after : generate a flagrant error ( error is after first print )


clearscreen.

list engines in motori.

for m in motori
{
print "Engine: " + m.
print "Max Thrust: " + m:maxthrust.
print "Thrust: " + m:thrust.
print "Thrust Limit: " + m:thrustlimit.
print " ".
}.

There is must be a bug with version 0.11.1 because the above code ( removing "thrustlimit" wich is not yet implemented in 0.11.0 ) run just fine in version 0.11.0

EDIT: the problem is fixed with release 0.12P1

Edited by brusura
Link to comment
Share on other sites

Seems like I've got it working now. Though I can't really say I fully understand what I've done right this time. :P

declare T. declare V. declare S.
lock V to (((altitude/775)^2) + 100).
lock S to (((surfacespeed)^2)+((verticalspeed)^2))^0.5.
set T to 1.
lock throttle to T.

when altitude > 20000 then {
lock V to (((altitude/650)^2) - 180).
}.
when altitude > 60000 then lock throttle to 1.

until apoapsis > 60000 {
if S > (V + 1.5) AND T > 0 {
set T to T - 0.01.
wait 0.1.
}.
if S < (V - 1.5) AND T < 1 {
set T to T + 0.01.
wait 0.1.
}.
}.

Oh, and this is just a small piece of a larger script I'm working on. Next issue to tackle is the fact that the turn rates always seem to be too slow, causing my trajectory to be way to vertical. Is there any good ways to mitigate this?

Edited by SBaL
Link to comment
Share on other sites

Seems like I've got it working now. Though I can't really say I fully understand what I've done right this time. :P

I bet on the parenthesis :)

Oh, and this is just a small piece of a larger script I'm working on. Next issue to tackle is the fact that the turn rates always seem to be too slow, causing my trajectory to be way to vertical. Is there any good ways to mitigate this?

You have to adjust the direction all the time either by locking steering to an expression or manually controlling the yaw. Of course if you don't have enough torque there's no way to move the rocket.

Edited by marianoapp
Link to comment
Share on other sites

I doubt it's the lack of torque alone, since flying any of my rockets manually gives me no problems what so ever when it comes to steering them.

Also, the only crafts kOS seems to be able to steer with any degree of success are small, single stage crafts. Even a simple two stage 1.25m suborbital rocket is too much for it, and it will take too long to steer in any direction.

To put my coding "pfails" short:

<Stuffs>
lock Y to (((((apoapsis+altitude)/2)/60000)^(4/3)) * (-90)).
<Many many codes>
when altitude > 5000 OR apoapsis > 6500 then {
lock steering to UP + R(0,Y,180).
sas off.
}.
when apoapsis > 60000 then {
<Do lots of things>
lock Y to (-90).
}.
<Even more codes and loops>

There's a loop later on to autostage when ever it's needed, and to keep the script running through the entire ascent. I've done some changes like removing redundant loops and such throughout the script, and use more "when _ then" statements since they seem to work just as well for my purpose. This change has however of course not changed the steering behaviour. Or, not in any significant way at least.

When I'm looking at the steering control gauge thingies in KSP, it seems like kOS is mostly spazzing (like the old asas did) the controls around their respective centres, and it hardly outputs steering commands of more than 1/3 to 1/2 of what it can in any direction. I'd figured that it was mostly an issue with this "spazzing" of controls. But I can't say I've come up with any good way to mitigate this.

I've tried to just lock Y to -90 much earlier, but it doesn't really speed things along.

Oh, and thanks for all your help so far. :)

Link to comment
Share on other sites

I doubt it's the lack of torque alone, since flying any of my rockets manually gives me no problems what so ever when it comes to steering them.

Also, the only crafts kOS seems to be able to steer with any degree of success are small, single stage crafts. Even a simple two stage 1.25m suborbital rocket is too much for it, and it will take too long to steer in any direction.

Oh, and thanks for all your help so far. :)

if The normal steering assist doesnt behave like you want. you have direct access to the steering and you can turn it exactly like you would by hand.

EDIT: By this i mean there is a flight control API for you to set the yaw/pitch/roll directly

Edited by erendrake
Link to comment
Share on other sites

Hi SBal, you can get the current terminal velocity from ship:termvelocity ;)

I found out after I did the complete math in a script, LOL:


set e to 2.7182818284590452353602874713527.

// Launch
set t to 1.
lock throttle to t.
sas on.

clearscreen.

stage.

until ship:liquidfuel < 0.01 {

set f to -1 * altitude / 5000.

set pbaro to body:atm:sealevelpressure * ( e ^ f).

// if pbaro < 0.001 { set pbaro to 0.001. }.
print "pbaro: " + pbaro at (0,0).

set rho to 1.2230948554874 * pbaro.

print "rho: " + rho at (0,1).

set r to altitude + body:radius.
set grav to body:mu.
set grav to grav / ( r * r).

print "grav: " + grav at (0,2).

set vesc to 250 * grav.
set vesc to vesc / rho.
set vesc to vesc / 0.2.
set vesc to vesc ^ 0.5.
print "vesc: " + vesc at (0,3).
[COLOR="#FF0000"]print "vt: " + ship:termvelocity at (0,4).[/COLOR]
set v to verticalspeed.
set dv to (vesc - v) / 10.

set t to dv.

if (t > 1) { set t to 1. }.
if (t < 0) { set t to 0. }.
print "t: " + t at (0,5).


}.

Cheers

Hans

P.S: Awesome job with the kOS mod, guys. I like it very much.

Link to comment
Share on other sites

Hi SBal, you can get the current terminal velocity from ship:termvelocity ;)

Really? That's a bit too ... Mechjeb. I'd rather have the components that go into the calculation than the final result of it. We're supposed to be writing the autopilot ourselves here.

Link to comment
Share on other sites

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