Jump to content

kOS Scriptable Autopilot System 0.9


KevinLaity

Recommended Posts

Where are the files saved in the 0.5 version? I can't seem to find my saved files from within the game, and it doesn't recognize the files I'm placing in the "Plugin/PluginData/Archive" folder.

Try "Plugins/PluginData/Archive"

Link to comment
Share on other sites

Yeah, keyboard problem. I don't have any Plugin folder, only a Plugins one. But still kOS can't find the files put there, and it doesn't seem to save the files I create ingame.

It doesn't natively use the archive folder as it's volume. If you want to edit things in there or run them then you will have to either copy it from the archive or switch to the archive volume.

Link to comment
Share on other sites

There has been a lot of discussion lately about how to control your rocket's angle in an acceptable manner. Had this simple information been included in the read me, we could have avoided all the problems from the very beginning. Of course now that I have a handle on it, I fully expect the new update will come as I write this post. If not, then here is an example of how to use the V(,,) instead of the R(,,) system. You can use this until the new update rolls out to gain full and accurate control of your rocket. I'm pretty sure there are a few people that actually knew this from the beginning. All I can say is shame on you. This took me five minutes once I actually found an accurate description of the formulas.


set yaw to 0.
set pitch to 90.
set x to 0.
set y to 0.
set z to 0.


set q to 0.
set tAngle to up + V(x,y,z).
lock steering to tAngle.
clearscreen.

until q = 1
{
on ag9 set q to 1.
set pitch to pitch + 5.
set x to cos(yaw) * cos(pitch).
set y to sin(yaw) * cos(pitch).
set z to sin(pitch).
wait 1.
if pitch > 359 { set pitch to 0. }.
if pitch < 0 { set pitch to 359. }.
if yaw > 359 { set yaw to 0. }.
if yaw < 0 { set yaw to 359. }.
print "x " + x at (0,1).
print "y " + y at (0,2).
print "z " + z at (0,3).
print "Yaw " + yaw at (0,5).
print "Pitch " + pitch at (0,7).
set tAngle to up + V(x,y,z).
}.

Edited by Payload
Forgot pitch and yaw limits.
Link to comment
Share on other sites


until 0 {
if RCS { print "RCS on." }.
if SAS { print "SAS on." }.
wait 1.
clearscreen.
}.

This works, so yes.

I don't even bother with SAS while running my orbit program, as when steering is locked, it's not really needed. I did find out the hardway that unless you unlock steering when the program ends, you can't seem to change direction. So what I do is at the end of my program, I lock steering to prograde, then unlock steering then turn sas on. It seems to work in the bits of testing I've done.

Link to comment
Share on other sites

There has been a lot of discussion lately about how to control your rocket's angle in an acceptable manner. Had this simple information been included in the read me, we could have avoided all the problems from the very beginning. Of course now that I have a handle on it, I fully expect the new update will come as I write this post. If not, then here is an example of how to use the V(,,) instead of the R(,,) system. You can use this until the new update rolls out to gain full and accurate control of your rocket. I'm pretty sure there are a few people that actually knew this from the beginning. All I can say is shame on you. This took me five minutes once I actually found an accurate description of the formulas.


set yaw to 0.
set pitch to 90.
set x to 0.
set y to 0.
set z to 0.


set q to 0.
set tAngle to up + V(x,y,z).
lock steering to tAngle.
clearscreen.

until q = 1
{
on ag9 set q to 1.
set pitch to pitch + 5.
set x to cos(yaw) * cos(pitch).
set y to sin(yaw) * cos(pitch).
set z to sin(pitch).
wait 1.
if pitch > 359 { set pitch to 0. }.
if pitch < 0 { set pitch to 359. }.
if yaw > 359 { set yaw to 0. }.
if yaw < 0 { set yaw to 359. }.
print "x " + x at (0,1).
print "y " + y at (0,2).
print "z " + z at (0,3).
print "Yaw " + yaw at (0,5).
print "Pitch " + pitch at (0,7).
set tAngle to up + V(x,y,z).
}.

I'm going to try putting this into my launch/orbit program, I suspect I may have some issues, mostly just wrapping my head around the numbers though lol :) I've gotten by using R (just to get into a normal orbit) but it doesn't hurt to try something else....hopefully lol.

Link to comment
Share on other sites

I don't even bother with SAS while running my orbit program, as when steering is locked, it's not really needed.

I pretty much only have "SAS OFF." lines in my programs. Pretty much any time there's a maneuver to be made, I turn it off, just to make sure. That's why I wrote a little program just to check if SAS could be used as a boolean condition.

I did find out the hardway that unless you unlock steering when the program ends, you can't seem to change direction. So what I do is at the end of my program, I lock steering to prograde, then unlock steering then turn sas on. It seems to work in the bits of testing I've done.

I've never had a problem with not unlocking steering. I do turn SAS on at the end of most programs, but I don't think I've ever used "unlock steering" or "unlock throttle". It appears to me that control is released when the program ends.

Link to comment
Share on other sites

I'm going to try putting this into my launch/orbit program, I suspect I may have some issues, mostly just wrapping my head around the numbers though lol :) I've gotten by using R (just to get into a normal orbit) but it doesn't hurt to try something else....hopefully lol.

It's really easy. Just have your loop update the xyz values as shown. You may not need the limits for function. They are there for the print out. I haven't tested to see what happens when you go beyond the 360 limit. My program doesn't have limits. I assume most people will know that >360 and <0 are invalid. 90 degree yaw equates to North on the Nav Ball. I have wrapped my yaw value in a target heading. Which is just set yaw to 90 + tHeading. You can then set tHeading to whatever you wish and that corresponds to the Nav Ball heading. Pitch is 90 up so that works out. Pitch is set via heading.

I set a heading of 45 at my first turn and ended up in an inclination of 44.6deg. I'd say that's not too bad. I have not tested adding roll into the mix as of yet. I feel it might be the only thing R(,,) is good for.

Link to comment
Share on other sites

OK now, I don't get this.. I am trying to make my space station always face UP and if I make a program with "lock steering to UP." the station starts constantly spinning indefinitely.. Adding R(...) or V(0,1,0) doesn't do anything either...

The way the steering system works it seems to need a bit of time to find its own head when you first use a "LOCK STEERING TO...." command. It will spin about all axes before settling on the direction you gave it. I suspect it's doing something to "learn" its rotational controls by trying them out and seeing what happens. But after it's rotated through all three axes it will settle down and work right. It just means you need your program to take over the steering a good 5 to 10 seconds before it's actually needed.

Link to comment
Share on other sites

Hello, i put this code together for my VTOL thrust controll and it works perfect for me.

is it possibel to lock steering but override it when i maually input controls? like SAS behavieor just with more lock force?

set currentbody to body.

clearscreen.

print "Aktiver Planet: " + currentbody.
print "Hovering..".

if currentbody = "Kerbin" { set radiusplanet to 600000. set gplanet to 9.81. }.
if currentbody = "Mun" { set radiusplanet to 200000. set gplanet to 1.63. }.
if currentbody = "Minmus" { set radiusplanet to 60000. set gplanet to 0.491. }.
if currentbody = "Eve" { set radiusplanet to 700000. set gplanet to 16.7. }.
if currentbody = "Gilly" { set radiusplanet to 13000. set gplanet to 0.049. }.
if currentbody = "Moho" { set radiusplanet to 250000. set gplanet to 2.70. }.
if currentbody = "Duna" { set radiusplanet to 320000. set gplanet to 2.94. }.
if currentbody = "Ike" { set radiusplanet to 130000. set gplanet to 1.10. }.
if currentbody = "Dres" { set radiusplanet to 138000. set gplanet to 1.13. }.
if currentbody = "Laythe" { set radiusplanet to 500000. set gplanet to 7.85. }.
if currentbody = "Vall" { set radiusplanet to 300000. set gplanet to 2.31. }.
if currentbody = "Tylo" { set radiusplanet to 600000. set gplanet to 7.85. }.
if currentbody = "Bop" { set radiusplanet to 65000. set gplanet to 0.589. }.
if currentbody = "Pol" { set radiusplanet to 44000. set gplanet to 0.373. }.
if currentbody = "Eeloo" { set radiusplanet to 210000. set gplanet to 1.69. }.

set radius to radiusplanet.
set g to gplanet.
set TargetH to (ALT:RADAR)+12.

set I to 0.
set deactivateFlag to 0.
on AG7 set deactivateFlag to 1.
sas on.

until deactivateFlag=1 {

on AG4 set TargetH to (ALT:RADAR)+d.
on AG5 set TargetH to (ALT:RADAR)+20.

set WTR to (mass*g*((radius/(radius+altitude))^2)/maxthrust).
set E to (TargetH - ALT:RADAR) - (verticalspeed*2).
set P to (0.1*(E))*WTR.
set I to (0.03*(E + I))*WTR.
lock throttle to P+I.
if verticalspeed < (((TargetH - alt:radar)/10)-20) { lock throttle to 1. }.
if verticalspeed > (((TargetH - alt:radar)/10)+25) { lock throttle to 0. }.

print "------------------------" at (10,4).
print "Alt: " + alt:radar at (10,6).
print "Hover auf: " + TargetH at (10,9).


if alt:radar < 20 and currentbody = "Kerbin" {
gear on.
set d to 5.
}.

if alt:radar > 20 and currentbody = "Kerbin" {
gear off.
set d to 0.
}.

if alt:radar < 12 and currentbody = "Kerbin" {
set d to 5.6.
}.

if alt:radar < 1.7 and currentbody = "Kerbin" {
set deactivateFlag to 1.
lock throttle to 0.
}.

if alt:radar < 20 and currentbody = "Mun" {
gear on.
set d to -0.5.
}.

if alt:radar > 20 and currentbody = "Mun" {
gear on.
set d to -5.
}

if alt:radar > 3 and currentbody = "Mun" {
gear on.
set d to -0.
}

if alt:radar < 1.7 and currentbody = "Mun" {
set deactivateFlag to 1.
lock throttle to 0.
}.

}.


print "Exiting..".

Edited by whaaw
Link to comment
Share on other sites

So I was able to make a Curiosity+Skycrane lik EDL system (minus the tether) , fully automated using kOS. Check out the video:

If starts by launching a rocket on a suborbital trajectory. It automatically adjusts the thrust of the rocket to match the terminal velocity, based on an empirical formula I got from a line of best fit from the table on the KSP wiki...

It throws the rover/skycrane up to about 113 km and then proceeds with a landing sequence (500 km away) which includes:

Drogue chute deployment,

Heatshield jettison.

Chute release.

Deviation.

Nulling horizontal velocity.

Slowing to -30 m/s, then -12 m/s/

Nulling horizontal velocity with pitch and rolls.

Slowing velocity to ~ -1 m/s.

Dropping the rover at 2.5 m above the ground.

Deviating and shooting off the skycrane into the distance.

Yaowzers!

I love this mod.

The script:



clearscreen.
Set ln to 0.
Set lt to 0.
set flag1 to 0.
set t to 1.
Print "EXECUTING PROGRAM...".
Print "Rover Landing by check.".
Print "".


lock steering to up + R(0,0,180).
lock throttle to 1.
Print missiontime + " Launching...".
Stage.
Wait until alt:radar > 200.
Lock steering to up + R(0,0,270).
Print missiontime + " ROLL Prog.".

Until altitude > 8000 {
if verticalspeed > 102.9 * (1.0001005^altitude) {
set t to t - 0.05.}.
if verticalspeed < 102.9 * (1.0001005^altitude) {
set t to t + 0.05.}.
If stage:liquidfuel < 450 AND flag1 = 0 {
stage.
set t to 1.
set flag1 to 1.
Print missiontime + " Booster Separation.".
}.
If t < 0 {set t to 0.}.
If t > 1 {set t to 1.}.
Lock throttle to t.
}.
Lock throttle to 1.
Lock steering to up + R(-45,1,180).
Print missiontime + " Gravity turn.".
Wait until stage:liquidfuel = 0.
Stage.
Lock throttle to 0.
Print missiontime + " Stage 1 Sep.".
Wait until verticalspeed < 0 AND altitude < 75000.
Lock steering to retrograde +R(0,0,180).
Wait until altitude <8000.
Stage.
Print missiontime+ " Drogue Deployed".
Unlock steering.
Wait until alt:radar < 2200 and alt:radar > -1.
Stage.
Print missiontime + " HEATSHEILD Sep.".
Wait until alt:radar < 1000.
stage.
Print missiontime + " BACKSHELL Sep.".
Wait 1.


Lock steering to up + R(10,45,180).
Wait 1.
Lock throttle to 0.3.
Stage.
Print missiontime + " Deviation mnvr.".
wait 2.

Until surfacespeed < 1 OR alt:radar < 510{

Set long1 to longitude.
Set long2 to longitude.
Set lat1 to latitude.
Set lat2 to latitude.
If long2 < long1 {set ln to -15.}.
If long2 > long1 {set ln to 15.}.

If lat2 < lat1 {set lt to -15.}.
If lat2 > lat1 {set lt to 15.}.

if abs(lat2-lat1) < 0.000005 {set lt to 0.}.
if abs(long2-long1) < 0.000005 {set ln to 0.}.
Lock steering to up + R(lt,ln,180).
}.

Set ln to 0.
Set lt to 0.

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



Wait until alt:radar < 500.
Print missiontime + " Approach.".
Lock throttle to (1.8 * 9.81 * mass/maxthrust).
Wait until verticalspeed >-30.



Until alt:radar < 120 {
If verticalspeed <-15 {Lock throttle to (1.7 * 9.81 * mass/maxthrust).}.
If verticalspeed >-10 {Lock throttle to (9.81 * mass/maxthrust).}.
}.

Print missiontime + " Final approach.".
Until alt:radar < 2.5 {

Set long1 to longitude.
Set long2 to longitude.
Set lat1 to latitude.
Set lat2 to latitude.
If long2 < long1 {set ln to -2.}.
If long2 > long1 {set ln to 2.}.

If lat2 < lat1 {set lt to -2.}.
If lat2 > lat1 {set lt to 2.}.

if abs(lat2-lat1) < 0.000005 {set lt to 0.}.
if abs(long2-long1) < 0.000005 {set ln to 0.}.

Lock steering to up + R(lt,ln,180).

If verticalspeed <-3 {Lock throttle to (1.4 * 9.81 * mass/maxthrust).}.
If verticalspeed >-1 {Lock throttle to (1.1* 9.81 * mass/maxthrust).}.
}.


Lock steering to up+R(-5,0,180).

Lock throttle to (2 * 9.81 * mass/maxthrust).
Brakes on.
Stage.
Lock throttle to 0.
Unlock throttle.
Unlock steering.
Wait 5.



Toggle AG1.
Print missiontime +" Landed.".

Edited by check
Link to comment
Share on other sites

any chance you can annotate it, im not sure what exactly you're doing with the lat/long and how you're minimising the horizontal velocity.

Great video by the way.

And squad need to hire Kevin, this so needs to be baked into ksp, and be able to use g sensors, heat sensors, air density sensors etc.

Link to comment
Share on other sites

any chance you can annotate it, im not sure what exactly you're doing with the lat/long and how you're minimising the horizontal velocity.

Great video by the way.

The program is checking to see if longitude and latitude are increasing/decreasing. If they are, it pitches and rolls in the opposite direction to compensate until the change between the two measured longitudes/latitudes is < 0.000005 degrees... which is kind of arbitrary because what velocity that corresponds to entirely depends on how quickly the program is executing..which varies all the time... but it puts it in roughly the 0.25 m/s range if theres a 200 ms delay between each command. (I've found that it varies between 100 ms and 250 ms).

Anyway, some hastily annotated code:



clearscreen.
Set ln to 0.
Set lt to 0.
set flag1 to 0.
set t to 1.
Print "EXECUTING PROGRAM...".
Print "Rover Landing by check.".
Print "".

//Launch program

lock steering to up + R(0,0,180).
lock throttle to 1.
Print missiontime + " Launching...".
Stage.

// Rolls rocket 90 degrees... for fun. Useful in some situations

Wait until alt:radar > 200.
Lock steering to up + R(0,0,270).
Print missiontime + " ROLL Prog.".

//While in flight, auto throttles based on current velocity vs ideal velocity. If current vertical speed
// > ideal velocity, throttle down, else throttle up.
// When boosters are drained, ditched them.


Until altitude > 8000 {
if verticalspeed > 102.9 * (1.0001005^altitude) {
set t to t - 0.05.}.
if verticalspeed < 102.9 * (1.0001005^altitude) {
set t to t + 0.05.}.

//So when the rocket has < 450 fuel, it means the boosters are dry, so stage. BUT you only want to stage once,
// so that's where the flag comes in. after you staged once, change the flag value so you don't stage again.

If stage:liquidfuel < 450 AND flag1 = 0 {
stage.
set t to 1.
set flag1 to 1.
Print missiontime + " Booster Separation.".
}.
If t < 0 {set t to 0.}.
If t > 1 {set t to 1.}.
Lock throttle to t.
}.
Lock throttle to 1.

// Gravity turn

Lock steering to up + R(-45,1,180).
Print missiontime + " Gravity turn.".
Wait until stage:liquidfuel = 0.
Stage.
Lock throttle to 0.
// Ditch the booster when it's dry.

Print missiontime + " Stage 1 Sep.".

// Coast past apoapsis and reorient retrograde the craft when it's below 7500 m.


Wait until verticalspeed < 0 AND altitude < 75000.
Lock steering to retrograde +R(0,0,180).

// deploy the chute at 8000m and unlock the steering

Wait until altitude <8000.
Stage.
Print missiontime+ " Drogue Deployed".
Unlock steering.

// jettison the heatsheild at 2200m
Wait until alt:radar < 2200 and alt:radar > -1.
Stage.
Print missiontime + " HEATSHEILD Sep.".
Wait until alt:radar < 1000.
stage.
// detach from chute/backshell at 1000m

Print missiontime + " BACKSHELL Sep.".
Wait 1.
// deviate by 10 degrees (yaw / roll?) + 45 degrees pitch and fire engines. Numbers kind of arbitrary. mostly wanted
// to test the horizontal velocity killing technique.
// This is to move away from the parachute/backshell and not have it land on us later.

Lock steering to up + R(10,45,180).
Wait 1.
Lock throttle to 0.3.
Stage.
Print missiontime + " Deviation mnvr.".
wait 2.

// Measures horizontal 'velocity' direction (not magnitude) and pitches/rolls the craft to compensate.
// If longitude/latitude is increasing/decreasing, roll to fire engine in the opposite direction.
// orient UP when surface velocity is < 1m/s.

Until surfacespeed < 1 OR alt:radar < 510{

Set long1 to longitude.
Set long2 to longitude.
Set lat1 to latitude.
Set lat2 to latitude.
If long2 < long1 {set ln to -15.}.
If long2 > long1 {set ln to 15.}.

If lat2 < lat1 {set lt to -15.}.
If lat2 > lat1 {set lt to 15.}.

if abs(lat2-lat1) < 0.000005 {set lt to 0.}.
if abs(long2-long1) < 0.000005 {set ln to 0.}.
Lock steering to up + R(lt,ln,180).
}.

Set ln to 0.
Set lt to 0.

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


// After 500 m, fire the throttle at 1.8 Gs.
Wait until alt:radar < 500.
Print missiontime + " Approach.".
Lock throttle to (1.8 * 9.81 * mass/maxthrust).

// wait until veritcal speed >-30.... self explainitory.
Wait until verticalspeed >-30.

// Adjust throttle to either 1.7Gs or 1.0 Gs depending on if vertical speed is <-15 m/s or >-10 m/s until 120 m

Until alt:radar < 120 {
If verticalspeed <-15 {Lock throttle to (1.7 * 9.81 * mass/maxthrust).}.
If verticalspeed >-10 {Lock throttle to (9.81 * mass/maxthrust).}.
}.

// Adjust throttle to either 1.4Gs or 1.1 Gs depending on if vertical speed is <-3 m/s or >-1 m/s until 2.5 m
// Adjust pitch/roll based on horizontal velocity direction, like in deviation mod but with finer adjustments


Print missiontime + " Final approach.".
Until alt:radar < 2.5 {

Set long1 to longitude.
Set long2 to longitude.
Set lat1 to latitude.
Set lat2 to latitude.
If long2 < long1 {set ln to -2.}.
If long2 > long1 {set ln to 2.}.

If lat2 < lat1 {set lt to -2.}.
If lat2 > lat1 {set lt to 2.}.

if abs(lat2-lat1) < 0.000005 {set lt to 0.}.
if abs(long2-long1) < 0.000005 {set ln to 0.}.

Lock steering to up + R(lt,ln,180).

If verticalspeed <-3 {Lock throttle to (1.4 * 9.81 * mass/maxthrust).}.
If verticalspeed >-1 {Lock throttle to (1.1* 9.81 * mass/maxthrust).}.
}.

// At 2.5 m, pitch over 5 degrees, lock throttle to 2Gs, put the brakes on the rover wheels, jettison the skycrane.


Lock steering to up+R(-5,0,180).

Lock throttle to (2 * 9.81 * mass/maxthrust).
Brakes on.
Stage.
Lock throttle to 0.
Unlock throttle.
Unlock steering.
Wait 5.

// After 5 seconds, open the com dish and extend the antennae.

Toggle AG1.
Print missiontime +" Landed.".

Available here too: https://docs.google.com/file/d/0BwrMAqirhs-BZTlLWlFMTGF5UXM

Link to comment
Share on other sites

Thanks for the skycrane example, check, some interesting applications in there. Very good motivation and inspiration for potential other usages. Can't wait for next weekend when I have time to play with kOS :) .

Link to comment
Share on other sites

Hello,

I check all mods i d like to use. Of course Kos is one of them. Thanks for this amazing work.

I d like to get also RemoteTech Relay Network. Some say it s not compatible with Kos.

By the way, could it be possible to use Kos without RT transfer delay?

A Kos probe doesn't use RT, so no reason to get a delay. No datas sent from Kerbal.

Don't know if this fix depends on you. But now you know^^

Link to comment
Share on other sites

If starts by launching a rocket on a suborbital trajectory. It automatically adjusts the thrust of the rocket to match the terminal velocity, based on an empirical formula I got from a line of best fit from the table on the KSP wiki...

Pretty awesome, I was thinking of doing exactely that, but basing it on a measured density of the atmosphere by barometer. Of course, kOS can not communicate with those kinds of instruments yet, but I think that would ensure it working optimally regardless of which planet you are on and thus which atmosphere you are in.

I will refrain from looking at your code and build my own to compare them later :)

Link to comment
Share on other sites

Pretty awesome, I was thinking of doing exactely that, but basing it on a measured density of the atmosphere by barometer. Of course, kOS can not communicate with those kinds of instruments yet, but I think that would ensure it working optimally regardless of which planet you are on and thus which atmosphere you are in.

I will refrain from looking at your code and build my own to compare them later :)

Throttle limits are a great idea and it can really help keep you from wasting fuel. I have setup a TWR hold in my script. It works better than I could have imagined. I say go for it. It will only help. It doesn't have to be very elaborate to get the job done.

Link to comment
Share on other sites

Throttle limits are a great idea and it can really help keep you from wasting fuel. I have setup a TWR hold in my script. It works better than I could have imagined. I say go for it. It will only help. It doesn't have to be very elaborate to get the job done.

I've always paid quite some attention to ascent profiles and power/throttle control. I have been using empirical evidence pretty much from the start to get efficient launches and have been dreaming about better ways of doing this. kOS seems to provide the instrument for this, as MechJeb felt a bit too cheaty for my liking. What can be done is already amazing, but as soon as we can use input from instruments and modparts and can control modparts through kOS the sky will not even be the limit anymore.

Also, kOS provides a way of getting pretty much identical launches, increasing the accuracy and value of empirical testing once more.

If you lovely gentlemen would all please excuse me, I have a gaming rig to fix.

Link to comment
Share on other sites

So I was able to make a Curiosity+Skycrane lik EDL system (minus the tether) , fully automated using kOS. Check out the video:

Ah man, you beat me to it. It looks great.

I'm making a very similar skycrane deployment program and was trying to test it with different craft on different planets before posting it - it's supposed to work with any craft but the sticking point is that it only works on craft I designed. When I tried using it by attaching a KOS unit to the stock skycrane rover example that KSP comes with (and add a bit more fuel rings because of the KOS's weight), the crane's idea of which way is the "top" of the craft suddenly flips upside down the moment the rover is dropped. I have no idea why (i wonder if the stock design is built with an upside down command module in the skycrane? When the rover decouples the upside down command module takes over?)

I wish I had the full paid version of FRAPS because it really needed to be recorded. It's rather funny. The crane descends beautifully, nice and gentle, comes down and hovers just right, deposits the rover gently on the ground.... and then flips upside down and angrily slams itself as hard as it can into the rover at full throttle. (It's executing the safe escape sequence, but with an inverted idea of which end of the craft is the top.)

At any rate as part of this I have some code to get around the fact that there's no surface-based prograde vector. I found a solution to that problem that works that I'll probably post on the wiki's examples page.

Link to comment
Share on other sites

Ah man, you beat me to it. It looks great.

I'm making a very similar skycrane deployment program and was trying to test it with different craft on different planets before posting it - it's supposed to work with any craft but the sticking point is that it only works on craft I designed. When I tried using it by attaching a KOS unit to the stock skycrane rover example that KSP comes with (and add a bit more fuel rings because of the KOS's weight), the crane's idea of which way is the "top" of the craft suddenly flips upside down the moment the rover is dropped. I have no idea why (i wonder if the stock design is built with an upside down command module in the skycrane? When the rover decouples the upside down command module takes over?)

That's bizarre about the skycrane flipping over. Is your kOS control pod on the skycrane or the rover?

I think my code is robust enough to work on different designs. It 'mostly' adjust throttle settings to achieve specific TWR rather than an absolute value, so the same code should work on heavier and lighter landers. I haven't tried it out yet.

At any rate as part of this I have some code to get around the fact that there's no surface-based prograde vector. I found a solution to that problem that works that I'll probably post on the wiki's examples page.

I've been thinking of a workaround for this too, though not too seriously because I'm sure a 'surfaceprograde' code is probably coming very soon. I suppose you could determine your surface prograde direction by subtracting your 'orbital velocity' from the rotation speed of kerbin, based on your latitude and extended up to your altitude... and then taking into account the change in longitude and latitude over time... (which won't be precise... it'll be jittery based on how long it takes your computer to run each command in kOS). Anyway, I'd be interested to see your solution.

Link to comment
Share on other sites

I don't know how much utility there will be for this, because maybe there will be a proper surface:prograde vector in the language some day.

But until there is I made a program that (sort of) can calculate it. It's dead-on accurate when used over the mun, but it becomes way off when used in an atmosphere because the air drag is throwing off the calculations, I think. (It's measuring it based on how the craft is actually moving, not on how it WOULD have been moving had there been no air.)

It's a longwinded thing, so instead of posting a wall of text here, I put it over on the wiki as a tutorial and example: If you just want the code and want to skip the explanations, pan down to the parts labeled "File 1", "File 2", and "File 3".

Link --> http://kos.wikia.com/wiki/Tutorial_-_Finding_surface-relative_data_(prograde/retrograde_directions)..

Edited by Steven Mading
Link to comment
Share on other sites

That's bizarre about the skycrane flipping over. Is your kOS control pod on the skycrane or the rover?

On the skycrane.

I think my code is robust enough to work on different designs. It 'mostly' adjust throttle settings to achieve specific TWR rather than an absolute value, so the same code should work on heavier and lighter landers. I haven't tried it out yet.

Yeah it sounds similar to what I did. I run some quadratic math to guess out what a preferred speed would be at a particular altitude in the descent. I don't just want to linearly slow down as that eats a lot of fuel. I want to do most of the retro burn at the bottom. If you descend too slow then you're wasting fuel but you shouldn't descend faster than the TWR is capable of correcting for at the bottom. So I sort of fudge it by comparing maxthrust to mass to decide how to "shape" the descent speed envelope - low TWR means I want to slow down from higher up even though it wastes fuel, and high TWR means I want to let it drop more quickly and do all the braking at the end.

But at any rate after working out the 'ideal' preferred speed at a given altitude, I check the actual speed to see if it's above or below that, and calculate at the current mass how much thrust would provide me with "nuetral boyancy" against gravity, and if I'm going faster than I wanted then I thrust more than that neutral amount, or slower than I wanted means I thrust less than that. It's a bit fudgy but it seems to work. Getting it to be gentle enough to perform the hover stage right, while at the same time being harsh enough to thrust high when it needs to on the descent was a bit of guesswork. Basically the amount by which it deviates from the neutral thrust level depends on how far off the actual speed is from the desired speed. The further off it is, the more it deviates away from neutral thrust, with the degenerate cases being max thrust if it really has a lot of slowing down to do, or no thrust if it's not falling anywhere near fast enough.

Anyway, I'd be interested to see your solution.

I just posted it in the above post. Give it a look and let me know what you think.

Link to comment
Share on other sites

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