Jump to content

[1.3] kOS Scriptable Autopilot System v1.1.3.0


erendrake

Recommended Posts

So I spent all this afternoon squezing out my brains potential to come up with a generic launch algorithm to use with my rockets.

Check out my code please and how does this fare, if there could be some faults and improvements.

One notable part is the terminal velocity which won't correspond with my used FAR data giving inaccurate speed. Any suggestion how to change that?


// General Launch Script
// attempt 1 by Gfurst

SET thr0 TO 0.
SET thr1 TO 1.
LOCK throttle TO thr0.
SET cntd0 TO 5.
SET drct TO ship:facing.
SET time0 TO TIME.
SET stg0 TO 0.


// Pre-launch countdown begin
PRINT "Beginning Launch:"
UNTIL cntd0 = 0 {
PRINT "..." + cntd.
SET cntd0 TO cntd0 - 1.
WAIT 1.
}.
PRINT "Launching.".
LOCK throttle TO thr1.
LOCK steering TO drct.
LOCK sfrvlc TO ship:surfacespeed.
LOCK trmvlc TO ship:termvelocity.

// Launching up
WAIT 1.
STAGE.
SET stg0 TO stg0 + 1.
PRINT "Engines on.".
WAIT 2.
STAGE.
SET stg0 TO stg0 + 1.
PRINT "Releasing clamps.".

// Time delta for loop control interval
SET time1 TO TIME.
LOCK timed TO TIME - time1.
WHEN timed > 1 THEN {
SET time1 TO TIME.
preserve.
}.

// Thurst correction
SET thrcrt TO true.
WHEN (timed >= 1) AND (sfrvlc / trmvlc >= 0.90) THEN {
SET thr1 TO thr1 - 0.05.
WAIT 0.1.
IF thrcrt { preserve. }.
}.
WHEN (timed >= 1) AND (sfrvlc / trmvlc <= 0.85) THEN {
SET thr1 TO thr1 + 0.05.
WAIT 0.1.
IF thrcrt { preserve. }.
}.

// If staged with solid fuel boosters
IF stage:solidfuel > 0.1 {
WHEN (timed >= 1) AND (stage:solidfuel < 1) THEN {
PRINT "Releasing SolidFuel boosters.".
STAGE.
SET stg0 TO stg0 + 1.
}.
}.

// Regular stages
WHEN (timed >= 1) AND (stage:liquidfuel < 0.1) THEN {
PRINT "Fuel depleted, activating next stage.".
STAGE.
SET stg0 TO stg0 + 1.
IF ship:liquid:fuel > 0.1 { preserve }.
}.



// Direction correction after 5000 height.
WAIT UNTIL ship:altitude >= 5000.
SET drctcrt1 TO true.
SET drctpitch TO 45
WHEN ( timed >= 1 ) AND ( drct:pitch <> drctpitch ) THEN {
IF (drct:ptich > drctpitch) {
SET drct:pitch TO drct:pitch - 1.
}.
IF (drct:ptich < drctpitch) {
SET drct:pitch TO drct:pitch + 1.
}.
WAIT 2.
IF drctcrt1 { preserve }.
}.

// Correction for 25000 altitude
WAIT UNTIL ship:altitude >= 24000.
SET drctpitch TO 0.
WHEN (timed >= 1) AND (thr1 = 1.0) THEN {
SET thrcrt TO false.
PRINT "Ending throttle control".
}.

// Now waiting for Apoapsis
WAIT UNTIL ship:apoapsis >= 69000.
PRINT "Escaped the atmosphere.".
PRINT "Shuting down engines.".
SET thr1 TO 0.0.
SET drctcrt1 TO false.

// Wait for circulizing burn

In general there should be external chunks of code to make kOS work with other mods that can be updated by other modders easily enough. I.E. a way to let other modders write kOS function calls that kOS scripts can use. In the meantime there is the ability to read things on a PartModule's fields, but not necessarily everything every other mod calculates.

Good to know you will consider this. There are all sorts of useful data that makes life that much easier without having to bang your head doing all the calculations yourself. Some simple stuff like delta V, current TWR, terminal velocity, but more complex stuff like impact time, closest approach, and such.

Unfortunately the part I've mentioned is only to enable the Engineer window to be viewable in flight, but doesn't show anything it self.

Link to comment
Share on other sites

@erendrake gave me permissions to issue a bugfix while he's away, so here it is:

Bug fix is NOT on curse yet, because I don't think his attempt to give me co-author permissions took hold. At any rate I don't seem to be allowed to update it on curse.

However, it is on Github and Kerbalstuff.

v0.15.3

BugFixes:

* Issue #417: No error message on nonexistent function.

* Issue #413: Name tag window should get keyboard focus when invoked.

* Issue #405: Equality operator is broken for Wrapped structure objects.

* Issue #393: Files on local volume do not persist through save/load.

The last issue is the important one. #393. It should fix the "zero size" files on the local volumes when you save the game.

I have another update with what I think are very useful features to help with dealing with Directions, but as those are not bug fixes but new features, I held off on including them in this update.

Link to comment
Share on other sites

Awesome!! :)

Steven, are you or erendrake going to take a look into #389 anytime soon? For now my rockets are flying quite well with hidden torque wheels so I'm not trying to urge anyone, just thought it'd be nice to know if this is a fix that one could expect to see within a couple days, or rather something that requires a major rework.

Link to comment
Share on other sites

Awesome!! :)

Steven, are you or erendrake going to take a look into #389 anytime soon? For now my rockets are flying quite well with hidden torque wheels so I'm not trying to urge anyone, just thought it'd be nice to know if this is a fix that one could expect to see within a couple days, or rather something that requires a major rework.

I was keeping mostly out of the steering code and leaving it up to erendrake, but he may be out for a while so I might look at it. But I don't think it's realistic to expect anything in "just a few days".

Link to comment
Share on other sites

I do think the documentation pages are in need of tidy up.

Yesterday I've found this page http://ksp-kos.github.io/KOS_DOC/command/variable/index.html and for the life of me couldn't find it again today.

Only way to reach it is through the file I/O command page.

Ps: I'm aware of the coding fault in the file I've posted above, got a bit confused first time reading those docs.

Link to comment
Share on other sites

Just got these log messages starting with the latest kOS 0.15.3 under KSP 0.25 Linux


[LOG 10:51:59.345] KOSToolBarWindow: Now making instance number 1 of KOSToolBarWindow
[WRN 10:51:59.352] UnityEngine.GUISkin must be instantiated using the ScriptableObject.CreateInstance method instead of new GUISkin.

For reference:


Kerbal Space Program - 0.25.0.0 (LinuxPlayer)




OS: Linux 3.13 Ubuntu 14.04 64bit
CPU: AMD A10-6800K APU with Radeon(tm) HD Graphics (4)
RAM: 15907
GPU: Gallium 0.4 on AMD PITCAIRN (256MB)
SM: 30 (OpenGL 3.0 [3.0 Mesa 10.1.3])
RT Formats: ARGB32, Depth, ARGBHalf, RGB565, ARGB4444, ARGB1555, Default, DefaultHDR, ARGBFloat, RGFloat, RGHalf, RFloat, RHalf, R8

...

[LOG 10:51:58.974] AssemblyLoader: KSPAssembly 'kOS' V0.15

Link to comment
Share on other sites

Iv been trying learn this mod since someone told me about it on reddit, i was asking about ways to do things in Inferno robotics that are slightly un humman.

My idea was to make a rotor move each time i would be at a certain position while rotation..

(and to be specific, i have a wing attached to the rotor which needs to change its angle while it spins around another rotor, creating differential lift, changing the attitude of the craft)

Any idea if this is possible? (im still learning coding little steps at the time, lots of fun)

Link to comment
Share on other sites

I do think the documentation pages are in need of tidy up.

Yesterday I've found this page http://ksp-kos.github.io/KOS_DOC/command/variable/index.html and for the life of me couldn't find it again today.

Only way to reach it is through the file I/O command page.

Ps: I'm aware of the coding fault in the file I've posted above, got a bit confused first time reading those docs.

Hi there,

i am going to do a complete reorganization of the documentation site in the next couple weeks. This should solve the lost pages problem and hopefully make the site a better "reference" once you have gone through the tutorials. I was just waiting till the 0.15 bugs were settled which it looks like they are now.

Link to comment
Share on other sites

There's still a bug with the local filesystems. Files are saved but what you get back when you reload them has mangled the spaces and end-of-lines. I've fixed it but I'm reluctant to issue the fix and up the rev number for just one single fix, and would rather wait to incorporate more stuff into it. If you need the fix immediately let me know and I might reconsider.

Link to comment
Share on other sites

maybe it can be, a "unofficial" bug fix, witch no number and after more bugs are smashed, incorporate it into a official v0.15.3 update. Or call the fix for just this single issue v0.15.2.1. I don't know what are the numbering rules in the dev team, so that's just a suggestion.

Link to comment
Share on other sites

Hello fellow Kerbonauts,

while working on this script:


//Parameter declaration
declare parameter alt. //if you launch the script with scriptname(1000) alt is set to 1000




//General Variables
set kr to kerbin:radius. //Radius of Kerbin
set km to kerbin:mass. //Mass of Kerbin
set kmu to Kerbin:mu. //Gravital parameter of Kerbin (Gravity Constant * Mass)
set e to constant():e. //Set e to Eulers number
set long to longitude.


//Internal Variables
lock throttle to thr. //Locks the throttle to thr.
lock steering to heading ( 90, 90 ). //Locks the rockets direction up.
set thrust to 0.1. //Throttle at lift off where 1 is 100% throttle and 0 is 0%
set ttw to (maxthrust/(mass*9.81)). //Setting Thrust to weight ratio
set st1 to 0. //Booster status where 0=off, 1=ignited, 2=empty 3=discoupled
set st2 to 0. //Stage 1 status where 0=off, 1=ignited, 2=empty 3=discoupled
set st3 to 0. //Stage 2 status where 0=off, 1=ignited, 2=empty 3=discoupled
set st4 to 0. //And so on and so fourth. If you have more stage add more variables.
set vo to 0. //Optimal velocity in dependency of altitude
set v to 0. //airspeed
set thr to 0.2. //Initial throttle
set r to 0. //Determines if roll has occurred
set p to 0. //helps setting the speed below 20 km.
clearscreen.


//Launch Sequence
print "Launch Sequence started.". wait 1. //Displays "Launch Sequence started" in the terminal
print "T-" + missiontime + 9. wait 1.
print "T-" + missiontime + 8. wait 1.
print "T-" + missiontime + 7. wait 1.
print "T-" + missiontime + 6. wait 1.
print "T-" + missiontime + 5. wait 1.
print "T-" + missiontime + 4. wait 1.
print "T-" + missiontime + 3. wait 1.
print "T-" + missiontime + 2. wait 1.
print "T-" + missiontime + 1. wait 1.
Print "T-" + missiontime + " Lift off".
stage. //Launches the first stage.
set st1 to 1.
set st2 to 1.


//Stage decoupling
when stage:solidfuel < 1 then {set st1 to 2.}. //Checks booster fuel status
when stage:liquidfuel < 1 then {set st2 to 2.}. //Checks stage 1's fuel status
when stage:liquidfuel < 1 and st2 = 3 then {set st3 to 2.}. //Checks stage 2's fuel status (if more stage add more of this)


when st1 = 2 then {wait 2. stage. set st1 to 3. Print "T+"
+ round(missiontime) + " Booster separated.".}. //Decouples the boosters if empty




when st2 = 2 then {wait 2. stage. set st2 to 3. Print "T+"
+ round(missiontime) + " Stage 1 separated.". //Decouples stage 1 if empty
wait 1. stage. Print "T+" + round(missiontime)
+ " Stage 2 Ignited.". set st3 to 1. //Ignites stage 2
}.


when st3 = 2 then { wait 1. stage. set st3 to 3. Print "T+"
+ round(missiontime) + " Stage 2 separated.". //You see where this is going
wait 1. stage. Print "T+" + round(missiontime)
+ " Stage 3 Ignited.". set st4 to 1. //Ignites stage 3
}.


//Rolls the rocket by 45° when reaching 200m
when ca > 200 and r = 0 then {
lock steering to up + R(0,0,0).
print "T+" + round(missiontime) + " Rolling.".
set r to 1.
}.


if altitude < 20000
{
lock throttle to (throttle+p).
when altitude > 20000 then {lock throttle to thr.}.
}.


//Loop below 20km altitude.
until altitude > 20000 {


set ca to altitude. //Sets ca to altitude (because im to lazy to write altitude all the time)
set a1 to altitude/1000. //Sets a1 to altitude/1000
set v to airspeed. //Sets v to current ship velocity
set vo to 95.688*(E^(0.096*a1)). //Sets v0 to perfect velocity based on http://bit.ly/15hQOy2
[COLOR=#404040][FONT=arial]
print round(vo - v).[/FONT][/COLOR]

if v > vo {if throttle > 0 {set p to -0.1.}.} else {if throttle < 1 {set p to 0.1.}.}. //Throttles down if too fast




wait 0.5.
}.

i issued a strange freeze/crash. It froze right after displaying this

[COLOR=#404040][FONT=arial]print vo - v.[/FONT][/COLOR]

with a correct output in the terminal. I'm quite new to KOS and this is my first attempt in making my completely own script. Could anybody please help me with this?

Link to comment
Share on other sites

I'm quite new to KOS and this is my first attempt in making my completely own script. Could anybody please help me with this?

No idea, but I can say that this is wrong:


print round(vo-v).

Because the round function takes 2 arguments. You're missing the second one that says what digit to round to. That might cause a problem?

Link to comment
Share on other sites

Hi, does anybody know how I can print the radar altitude? Not the "normal altitude". And also, does anybody know how to get the actual velocity (Surface/Orbit) without that it shows off the velocity in the three dimensions? Just as the velocity marker in the navball? :)

Not sure about radar altitude, but you can get the magnitude of a vector by taking sqrt(x^2 + y^2 + z^2). In kOS terms it would probably look something like this: SQRT(VEL:X*VEL:X + VEL:Y*VEL:Y + VEL:Z*VEL:Z), where VEL is your velocity vector.

Link to comment
Share on other sites

Hi, does anybody know how I can print the radar altitude? Not the "normal altitude". And also, does anybody know how to get the actual velocity (Surface/Orbit) without that it shows off the velocity in the three dimensions? Just as the velocity marker in the navball? :)

You can find an example here:

http://ksp-kos.github.io/KOS_DOC/structure/geocoordinates/index.html

Link to comment
Share on other sites

Hi, does anybody know how I can print the radar altitude? Not the "normal altitude". And also, does anybody know how to get the actual velocity (Surface/Orbit) without that it shows off the velocity in the three dimensions? Just as the velocity marker in the navball? :)

ALT:RADAR 

The altitude of the current ship above the terrain, rather than above the sea level. Does not have an alias anywhere.

if it comes to velocity there is a :VELOCITY suffix, it can be

 SHIP:VELOCITY:ORBIT or SHIP:VELOCITY:SURFACE 

or You cand use :mag suffix on Your vector and You will have a magnitude of the vector, as a scalar number.

Link to comment
Share on other sites

No idea, but I can say that this is wrong:


print round(vo-v).

Because the round function takes 2 arguments. You're missing the second one that says what digit to round to. That might cause a problem?

I don't think thats the problem, because i use it often in the script and if you don't give a second arument it just rounds to a whole number. Also the output is shown correctly in the terminal, it just freezes after the output.

Link to comment
Share on other sites

Fox Smith i think changing "E" to "e" might help. its the only possible error i can see there.

set vo to 95.688*(e^(0.096*a1)). 

but what really interest me is how You get the "ce" for the line 76 when You tell the script in line 94.

Link to comment
Share on other sites

Fox Smith i think changing "E" to "e" might help. its the only possible error i can see there.

set vo to 95.688*(e^(0.096*a1)). 

but what really interest me is how You get the "ce" for the line 76 when You tell the script in line 94.

Okay, i now set the initial value of ca to 0, added a "wait 0.5." to the if script that controls the throttle below 20 km.

if altitude < 20000 {
lock throttle to (throttle+p).
when altitude > 20000 then {lock throttle to thr.}.
wait 0.5.
}.

I also changed "e" to "E", now the script freezes right after the last output from the launch sequence. Really strange occurrences on my side... :confused:

Link to comment
Share on other sites

My A vector is my target:position.

My B Vector is my SHIP:SRFPROGRADE.

How to explain to the KOS that i want to build a vector C witch C+B=A? Because what ever i do the missile don't compensate for the gravity enough and hits in the ground in front of the target.

And can someone explain to me what Trim is (in sense of :YAWTRIM) because the translator is useless, and goggle just shows some articles about hard drives.

Link to comment
Share on other sites

Is there a way to read player imputed ship controls? (pitch, yaw, roll) has the player changes the controls, is it possible to read it and do something with it (so say in this case, more pitch would activate more IR rotors, giving finer controls... (maybe if i figure it out it could tweak there speed but that's something else....))

(just been reading the wiki for the last week and was wondering if you guys can help with a few things.... just trying to see if it can help me control things with IR or not....)

Edited by simonwoodburyforget
Link to comment
Share on other sites

Is there a way to read player imputed ship controls? (pitch, yaw, roll) has the player changes the controls, is it possible to read it and do something with it (so say in this case, more pitch would activate more IR rotors, giving finer controls... (maybe if i figure it out it could tweak there speed but that's something else....))

(just been reading the wiki for the last week and was wondering if you guys can help with a few things.... just trying to see if it can help me control things with IR or not....)

http://ksp-kos.github.io/KOS_DOC/structure/control/index.html#pilot-commands

Link to comment
Share on other sites

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