Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

In regards to this, I already have a basic idea of what i will need, I just need to write it somewhere other than my memory, and start ordering the data needed... I imagined that most of the FAR data I may need was not going to be accesible from kOS, but if those values are static it's just a matter of having the user of the autopilot set them... Once I have a clear idea of what i need, i'll post it here and also ask ferram how the math works...

There's actually a FARAPI that ferram4 has that would allow kOS to pull some of the data directly from FAR. What I don't know is if it's different than the same info we can already get from KSP. In other words, when we get the aerodynamic data from KSP, has it already been through FAR, or do we need a separate channel to get the FAR data from?

I looked at this a while back, and I seem to remember that the data we get is the same that FAR gives.

Link to comment
Share on other sites

There's actually a FARAPI that ferram4 has that would allow kOS to pull some of the data directly from FAR. What I don't know is if it's different than the same info we can already get from KSP. In other words, when we get the aerodynamic data from KSP, has it already been through FAR, or do we need a separate channel to get the FAR data from?

I looked at this a while back, and I seem to remember that the data we get is the same that FAR gives.

Depending on your use case you are right, as soon as you want to do something like limit Q with throttle you wont be able to get what you need with kOS as it is today. It really shouldnt be that much work so anyone who loves c# work is welcome to jump in :)

Link to comment
Share on other sites

Depending on your use case you are right, as soon as you want to do something like limit Q with throttle you wont be able to get what you need with kOS as it is today. It really shouldnt be that much work so anyone who loves c# work is welcome to jump in :)

Sorry about this, but stupid question coming, is Q some reserve variabled from kOS, or is just a random to-be variable??

Link to comment
Share on other sites

Depending on your use case you are right, as soon as you want to do something like limit Q with throttle you wont be able to get what you need with kOS as it is today. It really shouldnt be that much work so anyone who loves c# work is welcome to jump in :)

Ahemm ... My ascent algorithm does MaxQ throttle buckets... It's quite simple actually...

Your rocket has some amount of thrust Ft (MAXTHRUST * THROTTLE) which is negated by the gravitational acceleration Fg (SHIPMASS * G * (SHIP:BODY:MASS / SHIP:BODY:RADIUS^2)) ... that you can derive the maximum net acceleration you can put out, taking into account the resulting vector from the pitch relative to the gravity vector ... Then, you record the vertical acceleration, if no sensor is present you can use dead reckoning with a time step (Ts) of a fraction of a second with a WAIT x command, the longer the better, with (Velocity(T+time interval) - Velocity(T=0)) / Ts yielding the average acceleration during that time step... Then Drag (D) is F - (Average Acceleration * SHIP:MASS) ... Just keep track of the maximum amount of drag (which I will call MaxQ even if it's not exactly the same thing, but since drag is the integration of dynamic pressure over the expose area, let's use it from now on as similiar) and when it exceeds some value (I use a Drag to Thrust ratio of 0.5 as my cutoff value), you throttle back while the drag still is equal to MaxQ... when Drag < MaxQ, you throttle back up, and if you hit the MaxQ wall again later on ascent, it throttles back down.

I keep track of the altitude where it happens also for fine tuning purposes... Later I can publish the code if anyone's interested, but here's a snipped of it:


UNTIL VELPITCH < 0{
RUN ASCDPLY.
IF ATM {
IF DRAG > MAXQ {
SET MAXQ TO DRAG.
SET MAXQALT TO SHIP:ALTITUDE.
}.
IF SHIP:MAXTHRUST > 0 {
IF DTR > 0.5 AND DRAG = MAXQ {
SET THRTGT TO MAX(THRMIN, THRTGT - 0.1).
PRINT "MAX Q" AT (2,2).
} ELSE {
SET THRTGT TO MIN(THRMAX, THRTGT + 0.1).
}.
}.
}.
}.

Edited by Cairan
Link to comment
Share on other sites

Ahemm ... My ascent algorithm does MaxQ throttle buckets... It's quite simple actually...

Your rocket has some amount of thrust Ft (MAXTHRUST * THROTTLE) which is negated by the gravitational acceleration Fg (SHIPMASS * G * (SHIP:BODY:MASS / SHIP:BODY:RADIUS^2)) ... that you can derive the maximum net acceleration you can put out, taking into account the resulting vector from the pitch relative to the gravity vector ... Then, you record the vertical acceleration, if no sensor is present you can use dead reckoning with a time step (Ts) of a fraction of a second with a WAIT x command, the longer the better, with (Velocity(T+time interval) - Velocity(T=0)) / Ts yielding the average acceleration during that time step... Then Drag (D) is F - (Average Acceleration * SHIP:MASS) ... Just keep track of the maximum amount of drag (which I will call MaxQ even if it's not exactly the same thing, but since drag is the integration of dynamic pressure over the expose area, let's use it from now on as similiar) and when it exceeds some value (I use a Drag to Thrust ratio of 0.5 as my cutoff value), you throttle back while the drag still is equal to MaxQ... when Drag < MaxQ, you throttle back up, and if you hit the MaxQ wall again later on ascent, it throttles back down.

I keep track of the altitude where it happens also for fine tuning purposes... Later I can publish the code if anyone's interested, but here's a snipped of it:


UNTIL VELPITCH < 0{
RUN ASCDPLY.
IF ATM {
IF DRAG > MAXQ {
SET MAXQ TO DRAG.
SET MAXQALT TO SHIP:ALTITUDE.
}.
IF SHIP:MAXTHRUST > 0 {
IF DTR > 0.5 AND DRAG = MAXQ {
SET THRTGT TO MAX(THRMIN, THRTGT - 0.1).
PRINT "MAX Q" AT (2,2).
} ELSE {
SET THRTGT TO MIN(THRMAX, THRTGT + 0.1).
}.
}.
}.
}.

Ah, but with FARAPI integration, you can get the Q, Cl, Cd, Cm, Ballistic Coefficient, AoA, side slip, stall fraction, term vel, air density, and mach number that FAR's already computed.

https://github.com/ferram4/Ferram-Aerospace-Research/blob/master/FerramAerospaceResearch/FARAPI.cs

Link to comment
Share on other sites

Ah, but with FARAPI integration, you can get the Q, Cl, Cd, Cm, Ballistic Coefficient, AoA, side slip, stall fraction, term vel, air density, and mach number that FAR's already computed.

https://github.com/ferram4/Ferram-Aerospace-Research/blob/master/FerramAerospaceResearch/FARAPI.cs

then i believe my script is already done haha, i just need to write it, and test it... and maybe still talk to ferram for some math...!

how do I use that .cs?? do i need to compile it? please don't tell me i need to compile it haha!

Edited by GabeTeuton
.cs (?)
Link to comment
Share on other sites

Ah, but with FARAPI integration, you can get the Q, Cl, Cd, Cm, Ballistic Coefficient, AoA, side slip, stall fraction, term vel, air density, and mach number that FAR's already computed.

https://github.com/ferram4/Ferram-Aerospace-Research/blob/master/FerramAerospaceResearch/FARAPI.cs

That's really nifty, but it somehow feels a bit like cheating. Some of those are easily measured in real life, others are nigh on impossible. They do allow for some pretty neat stuff though.

BIG FAT TINY DISCLAIMER: THIS IS A PERSONAL OPINION, EVERYONE SHOULD PLAY AS HE OR SHE LIKES.

Edited by Camacha
Link to comment
Share on other sites

then i believe my script is already done haha, i just need to write it, and test it... and maybe still talk to ferram for some math...!

how do I use that .cs?? do i need to compile it? please don't tell me i need to compile it haha!

Worse, you'll have to modify and compile the kOS code to use it. I linked it to show what's available...

Link to comment
Share on other sites

Ah, but with FARAPI integration, you can get the Q, Cl, Cd, Cm, Ballistic Coefficient, AoA, side slip, stall fraction, term vel, air density, and mach number that FAR's already computed.

https://github.com/ferram4/Ferram-Aerospace-Research/blob/master/FerramAerospaceResearch/FARAPI.cs

I agree it's nice to get these values "magically" (I really, really appreciate it when it comes to fine tuning control algorithms), but as another poster mentionned, in RealLife, you often can not, except in post-flight analysis, determine where the centers of lift and drag are located, specially when it comes to "real" aerodynamics... STS-1 was an humbling mission as Columbia didn't quite behave like it was modelled to, Young and Crippen had to take control to limit side slip on the first S-turn...

As for integrating Ferram's FAR or NEAR, maybe it would be easier instead of modifying the kOS code to make a standalone module which would augment the atmospheric sensor parts (nosecone, among others) with all these magic values, by using ModuleManager? Then you could hook from kOS by calling SENSOR:READOUT... to read the values... wouldn't that work?

Edited by Cairan
Link to comment
Share on other sites

Actually, reflecting back on the fact that kOS 0.15 brings with it the ability to read values from the right-click GUI menus of parts, you could just cook together a module that dumps these values in the GUI menu of the atmospheric sensor part, or MechJEB, or the kOS part itself, whatever floats your boat, and read it from there... :)

Link to comment
Share on other sites

After starting the development of the precise autopilot (PAP) i believe i will only need (things i don't have or know if i do)=

-level flight AoA for user selected Altitude and Speed.

-Relation between Altitude and Air Density.

-Conversion of Pitch (in terms of -1 to 1) to AoA.

I already asked those in the FAR thread and already have some answers, once i have all the data i need it's just a matter of making the script do the calculation with the provided data, assuming is static data and not something that varies from time to time, and if I can't make the script read that data by itself, it's just a matter of asking the user to input those by hand, again as long as it's a static value, yeah it's not that fun to have to be writing data, but if it works, it will work for me haha!

Link to comment
Share on other sites

Yet another bug report I'd like to discuss...

I've been puzzled as to why sometime my boot script executes, sometimes it doesnt...

Turns out, I think it is case sensitive... I'm on Linux BTW. I'm linking the files in ../Archive from another directory ( ln -s ....../boot.txt . )

When the boot script is called boot.txt, it doesn't get executed at the launch pad, but the toggle "Boot" 0 or 1 is available in the VAB... Changing this value has no effect.

Renaming the link to Boot.txt ( ln -s ....../boot.txt Boot.txt ) now it executes relatively correctly. I say "relatively" because the case sensitiveness remains in the terminal...

I did this test:



[I]// In BASH on Linux:[/I]
ln -s ....../boot.txt Boot.txt

[I]// In kOS terminal:[/I]
SWITCH TO Archive.
LIST.

Volume #0: "Archive"
Name ...
--------...
Boot
ascent
[I][...][/I]

RUN boot.
File 'boot' not found
At interpreter history, line 3.
run boot.
^
RUN Boot.
File 'boot' not found
At interpreter history, line 4.
run boot.
^

Now, remember what I said, with an uppercase "B", the Boot.txt script gets executed. Without it (boot.txt), kOS doesn't boot it at initialization. Then it gets funny:


SWITCH TO 1.
LIST.
Volume #1: "hd1"
Name ...
--------...
boot
ascent
[I][...][/I]

run boot.
[I][...][/I]
Number of kOS-CPUs: 1

Volumes
ID Name ...
0 Archive ...
1* hd1 ...
[I][...][/I]
File 'boot' not found
At temp on hd1, line 2
COPY Boot FROM Archive
^
Called from boot on hd1, line 45.
RUN temp.

run Boot.
[I][...][/I]
Number of kOS-CPUs: 1

Volumes
ID Name ...
0 Archive ...
1* hd1 ...
[I][...][/I]
File 'boot' not found
At temp on hd1, line 2
COPY Boot FROM Archive
^
Called from boot on hd1, line 45.
RUN temp.

So, it is case insensitive on volumes other than Archive, but it seems case sensitive in Archive, yet there is a break in the consistency of case sensitiveness...

Just to test if it was related to using a link versus an hard copy, I also did the test with cp instead of ln ... same result ... with a lowercase b, boot.txt doesn't get run at the launch pad, with an uppercase B, it works but then the file is considered missing when recalled after the initial boot despite being listed in the volume's file list.

To make things even weirder, by fiddling around with the boot filename's case, I ended up with one kOS CPU in the VAB which had "Boot" for it's toggle, and another one with "boot" for it's toggle, and a third one with "BOOT"... on the same ship. :rolleyes:

Edited by Cairan
Link to comment
Share on other sites

I will just confirm that case matters on linux.

This is from work and is not from my KSP experience but how the file systems are handled is different.

3 files: boot.cfg Boot.cfg boot.CFG

On linux: Those are 3 distinct files that the file system considers as different as bootTheFirst.cfg and bootTheSecond.cfg

On Windows: Those 3 files are the same and trying to put all 3 of them in the same directory will trigger the file overwrite warning dialog box.

Now, I'm not sure how much kOS depends on accessing files on the hard drive (and so uses the operating system's file access), but it is something to be aware of.

D.

Link to comment
Share on other sites

To make things even weirder, by fiddling around with the boot filename's case, I ended up with one kOS CPU in the VAB which had "Boot" for it's toggle, and another one with "boot" for it's toggle, and a third one with "BOOT"... on the same ship. :rolleyes:

Is this some kind of trick or treat thing? you are giving me heartburn.

trick-or-treat-how-bout-aliens.jpg

Added a new issue to the tracker

https://github.com/KSP-KOS/KOS/issues/311

Link to comment
Share on other sites

I will just confirm that case matters on linux.

This is from work and is not from my KSP experience but how the file systems are handled is different.

3 files: boot.cfg Boot.cfg boot.CFG

On linux: Those are 3 distinct files that the file system considers as different as bootTheFirst.cfg and bootTheSecond.cfg

On Windows: Those 3 files are the same and trying to put all 3 of them in the same directory will trigger the file overwrite warning dialog box.

Now, I'm not sure how much kOS depends on accessing files on the hard drive (and so uses the operating system's file access), but it is something to be aware of.

D.

I've had this uppercase/lowercase issue on some other mods, usually the culprit is the dev not making sure to be consistent on his file naming conventions... then zip everything up for download, and then *it* hits the fan...

As far as kOS goes, just consider the files in the Archive to be case sensitive but expose a forced all-lowercase filename when operating on these files internally, with some mapping.

did you just call me fat!!! im going to just remove the boot feature!!!!!

:P No I did not... May I suggest cutting down coffee too :sticktongue: Just kiddin'.

...in real life I do work in my business involving crossplatform weather data processing and database management, uppercase and lowercase consistencies are giving me plenty of fun on my side too... :)

Edited by Cairan
Link to comment
Share on other sites

Guys i'm already working in the FAR's thread and it's not very good, the way FAR's work is quite complicated, in terms of my knowledge, and it's not that easy to make a kOS script calculate this unless a mod gives me the numbers i need from FAR... But there is a workaround to it, i'm still asking them for help on that...

Now i have another question for you guys, under FAR's in flight GUI, under Flight Data, one of the items is AoA, the current AoA, is that value gettable?

Link to comment
Share on other sites

So, just a small idea that I think might make some more complex codes (specifically ones that require many setup values) a little more efficient. Obviously, if you have a code that requires values to be used later to be specified ahead of time, you declare them at the beginning of your program. Like this:



A = SomeValue1
B = SomeString1
C = SomeBool1

PROGRAM.DOSTUFF(A,B,C)

(Forgive the non-kOS syntax, but it gets the point across.)

The only issue is that the code is going to waste time redeclaring A, B, and C every time it loops. For the example program above, it isn't too much of an issue, but for more complex programs it can inefficient. Back when I played Garry's mod, there was (still is) a mod called WireMod, which adds a part called an E2 chip, which is similar to the kOS computer in that it is capable of executing computer code. One of the functions available to the E2 was a function called first(). It returned true if the current execution was the first execution of the program since the last time it was terminated, false otherwise. Typically, a code with a lot of setup would look like this:



if(first()) {
A = SomeValue1
B = SomeString1
C = SomeBool1
}

else {
program.DoStuff(A,B,C)
}

With the above code, it will initialize A, B, and C on the first execution, then loop back to the beginning, check if first() is true (which it won't be) and proceed to the else part of the statement, containing the rest of the program. Then, it only needs to make a single comparative operation every execution as opposed to repeatedly declaring many values every iteration of the program.

Link to comment
Share on other sites

Hi. I need some advice for my code. The circularizing part of the code doesn't work like I intended. the main problem is the code doesn't know when the ship its way beyond its apoapsis. I will be wery grateful for any tip regarding this issue.



wait 8.
toggle ag10.
LOCK THROTTLE TO 1.0.
set k to 0. set wys to 0.
set l to 0. set gie to 0.
set b to 0.
set f to 0.
set p to 0.
//declare parameter orbita.
clearscreen.
print "Welcome Commander.".
print "Setting flight parameters.".
print "Flight target: Kerbin orbit..".
print "Altitude: " + orbita + "M.".
wait 3.
clearscreen.


stage.
until l = 1 {


set salt to ship:altitude.
set twr to ship:MAXTHRUST/ship:mass.
set wys to kerbin:radius + salt.
set gie to kerbin:mu.

if k = 0 {lock steering to up + R(0,0,180).}.
print "Altitude: " + round(salt) + "m " at (0,0). print k at (0,8).
print "Program:" at (0,2). print "Eccentricity: " + round(ship:obt:ECCENTRICITY,4) at (0,1).
if salt < 10000 {print "Going up " at (10,2).}.
print "TWR: " + round(twr,2) at (0,6).
print "ISP: " + b at (0,7).
LIST ENGINES IN myVariable.
FOR eng IN myVariable {set b to eng:ISP. }.



if stage:solidfuel < 1 and k = 0 {stage. set k to 1.}.
if salt > 10000 and k < 2 { print "gravite turn" at (10,2). lock steering to up + R(0,-45,180).}.
if throttle = 0 {print "waiting for circulisation" at (10,2).}.


when ship:apoapsis >= orbita + (orbita * 0.005) and k < 2 then {lock throttle to 0. }.


if eta:apoapsis < 55 and salt > 40000 and k < 2 {lock steering to up +R(0,-90,180).}.
if eta:apoapsis < 50 and salt > 40000 and k < 2 {lock throttle to 1. print "circilizing " at (10,2). set k to 4.}.
if ship:apoapsis > orbita + (orbita * 0.008) and k = 4 { Print "1down" at (10,8). lock steering to up +R(0,-95,180).}.
if ship:apoapsis < orbita and k = 4 { print "1up " at (10,8). lock steering to up +R(0,-75,180).}.

if eta:apoapsis < 2 and k=4 {set k to 5.}. if eta:apoapsis > 51 and k=5 and VERTICALSPEED > 0 {set k to 4.}. if eta:apoapsis > 100 and k=4 and VERTICALSPEED < -100 {set k to 5.}.

if ship:apoapsis > orbita and k = 5 and eta:apoapsis < 30 { Print "2down" at (10,8). lock steering to up +R(0,-70,180).}.
if ship:apoapsis < orbita + (orbita * 0.005) and k = 5 { print "2up " at (10,8). lock steering to up +R(0,-90,180).}.


when ship:obt:ECCENTRICITY < 0.028 then {set l to 1. lock throttle to 0.}.
wait 0.001.
}.

lock throttle to 0.
clearscreen.
print "orbit acheived".
stage.
wait 2.
toggle panels.
stage.
sas on.
set orbita to 100000.

Link to comment
Share on other sites

Hi. I need some advice for my code. The circularizing part of the code doesn't work like I intended. the main problem is the code doesn't know when the ship its way beyond its apoapsis. I will be wery grateful for any tip regarding this issue.

Try verticalspeed?

If periapsis is behind you and apoapsis is ahead of you, then you are ascending.

If apoapsis is behind you and periapsis is ahead of you, then you are descending.

Or, alternatively, compare eta:apoapsis to eta:periapsis. Whichever is smaller is the one that's in front of you. Whichever is larger is the one that's behind you.

Link to comment
Share on other sites

One of the functions available to the E2 was a function called first(). It returned true if the current execution was the first execution of the program since the last time it was terminated, false otherwise.

Is there some reason you can't use your own flag value for this?

Link to comment
Share on other sites

@any of the devs, i usually use notepad ++ to mess with most games files, and i just realized there's a way to load a "languages", it asks me for xlm file, is there such a file for the language kOS uses? Will loading such a file, if it exists, help not make mistakes when coding?

TY

PS: i'm still developing the precise autopilot, though the answers flow is very low right now haha, but i believe i have what i need... still testing!

In regards to this, how to calculate Vertical Acceleration? I know it's the change of speed in vertical Speed, but i don't know how to calculate it, tried to look on google but it was not clarifying...

Edited by GabeTeuton
Link to comment
Share on other sites

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