Skip to content

Commit

Permalink
full checkin of KSP repo
Browse files Browse the repository at this point in the history
  • Loading branch information
appenz committed May 5, 2020
1 parent 229a7e4 commit 3ac8953
Show file tree
Hide file tree
Showing 36 changed files with 5,378 additions and 0 deletions.
4 changes: 4 additions & 0 deletions boot/myboot.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
set terminal:width to 80.
set terminal:height to 50.
print "Hello Guido.".
8 changes: 8 additions & 0 deletions burn.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// burn the next maneuver node
run once libguido.

myinit().
set mynode to nextnode.
exec_n(mynode).
myexit().

85 changes: 85 additions & 0 deletions dock.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Dock Two Vessels

run once libguido.

declare parameter v_max is 1.

function rcs_ctl {
parameter d.
parameter v.
if d > 0.1 { set tv to -max(min(v_max, d/30),0.1). }
else if d < -0.1 { set tv to max(min(v_max,-d/30),0.1). }
else {set tv to 0.}
if v > tv {return -0.1.}
if v < tv {return 0.1.}
return 0.
}

myinit().

rcs off.

set tr to target.
set cp to ship:controlpart.

print "Docking to : "+tr:name.
print "Control from: "+cp:name.
print "Port status : "+cp:state.

// Adjust direction

print "adjusting direction.".
lock steering to lookdirup(-tr:portfacing:forevector, tr:portfacing:upvector).

set da1 to 9.
set da2 to 9.
until da1 < 1 AND da2 < 1 {
set da1 to vang(ship:facing:forevector, -tr:portfacing:forevector).
set da2 to vang(ship:facing:upvector, tr:portfacing:upvector).
print "ang diff:" + round(da1,1) + "/" + round(da2,1).
wait 0.2.
}

// Align horizontally and vertically.

rcs on.

set done to false.

until cp:state <> "Ready" {
set tr_dis to tr:portfacing:forevector.
set tr_ver to tr:portfacing:upvector.
set tr_hor to tr:portfacing:rightvector.

set tr_vec to tr:position-cp:position.
set tr_vel to tr:ship:velocity:orbit-ship:velocity:orbit.

set d_dis to vdot(tr_vec, tr_dis).
set d_ver to vdot(tr_vec, tr_ver).
set d_hor to vdot(tr_vec, tr_hor).

set v_dis to vdot(tr_vel, tr_dis).
set v_ver to vdot(tr_vel, tr_ver).
set v_hor to vdot(tr_vel, tr_hor).

print1s("dis/ver/hor: "+round(d_dis,1)+" / "+round(d_ver,1)+" / "+round(d_hor,1)+" "+
round(v_dis,1)+" / "+round(v_ver,1)+" / "+round(v_hor,1)).

set ship:control:starboard to rcs_ctl(d_hor,v_hor).
set ship:control:top to -rcs_ctl(d_ver,v_ver).

if abs(d_hor) > 0.2 or abs(d_ver) > 0.2 {
set ship:control:fore to rcs_ctl(0, v_dis).
} else {
set ship:control:fore to rcs_ctl(d_dis,v_dis).
}
wait 0.1.
}

set ship:control:neutralize to true.
rcs off.
lock throttle to 0.
unlock steering.
sas on.

print "done.".
26 changes: 26 additions & 0 deletions go_dres.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Launch from Kerbin to Dres
print "Dres 1.0".

KUniverse:QUICKSAVETO("x0-prelaunch").
if body = Kerbin {
if ship:altitude < 65000 {
run go_orb(250000).
lock throttle to 0.
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x1-orbit").
}
if ship:orbit:inclination > 0.01 {
run incl.
}
if ship:apoapsis < 1000000*0.99 {
run reorb(1000000).
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x2-pretransfer").
}
run tr_pl(Dres).
} else {
// In SOI, but not yet on a stable orbit.
if ship:apoapsis < 0 OR ship:apoapsis > 200000 { run tr_pl(Dres). }
}
print "You arrived at Dres!".

29 changes: 29 additions & 0 deletions go_dun.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Launch from Kerbin to Duna
print "Duna 1.0".

KUniverse:QUICKSAVETO("x0-prelaunch").
if body = Kerbin {
if ship:altitude < 65000 {
run go_orb(250000).
lock throttle to 0.
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x1-orbit").
}
if ship:orbit:inclination > 0.01 {
run incl.
}
if ship:apoapsis < 1000000*0.99 {
run reorb(1000000).
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x2-pretransfer").
}
run tr_pl(Duna).
} else {
// In SOI, but not yet on a stable orbit.
if ship:apoapsis < 0 OR ship:apoapsis > 200000 { run tr_pl(Duna). }
}

wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x3-dstorbit").
print "You arrived at Duna!".

28 changes: 28 additions & 0 deletions go_eve.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
print "Eve 1.0".

KUniverse:QUICKSAVETO("x0-prelaunch").
if body = Kerbin {
if ship:altitude < 65000 {
run go_orb(250000).
lock throttle to 0.
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x1-orbit").
}
if ship:orbit:inclination > 0.01 {
run incl.
}
if ship:apoapsis < 1000000*0.99 {
run reorb(1000000).
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x2-pretransfer").
}
run tr_pl(Eve).
} else {
// In SOI, but not yet on a stable orbit.
if ship:apoapsis < 0 OR ship:apoapsis > 200000 { run tr_pl(Eve). }
}

wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x5-dstlow").
print "You arrived at Eve!".

33 changes: 33 additions & 0 deletions go_min.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Launch from Kerbin to Minmus
print "Minmus 1.0".

KUniverse:QUICKSAVETO("x0-prelaunch").
if body = Kerbin {
if ship:altitude < 65000 {
run go_orb.
}
lock throttle to 0.
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x1-orbit").
if ship:orbit:inclination < 5 {
run reorb(80000).
run incl.
run incl(6,Minmus:orbit:lan).

}
run reorb(80000).
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x2-pretransfer").
run tr_min.
} else {
// In SOI of Minimus, but not yet on a stable orbit.
if ship:apoapsis < 0 OR ship:apoapsis > 100000 { run tr_min. }
}

if ship:apoapsis > 11000 { run reorb(10000). }
//if ship:orbit:inclination > 0.1 { run incl. }
wait until KUniverse:CANQUICKSAVE.
KUniverse:QUICKSAVETO("x3-dstorbit").
//run hit(0,6).
print "You arrived on Minmus!".

9 changes: 9 additions & 0 deletions go_mun.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Launch from Kerbin to the Mun
print "Mun 1.0".

run go_orb.
run reorbit2(80000).
run tr_mun.

print "done.".

147 changes: 147 additions & 0 deletions go_orb-v1.ks
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Orbital Launch Control

run once libguido.
myinit().

set incl to 0.
set apoa to 80000.

clearscreen.print "Orbital Launch Control v0.1".
print "Orbit: " + apoa + " m, " + incl + " deg".

set alt_s to 1000.

// Vessel specific setup
set n to ship:name.
set e_cur to 0.
list engines in e.

if n = "orbital-1" OR n = "MunOrbiter" OR n = "Mun-1" OR n = "Mun-2" {
set elist to list(e[2],e[1],e[0]).
print "Type: 3-Stage (3 stage, SLL)".
} else if n = "Mun-3-Minimus1" {
set elist to list(e[5],e[4],e[3]).
} else if n:startswith("Mun-3") {
set elist to list(e[3],e[2],e[1],e[0]).
print "Type: 4-Stage (3 stage, SLLL)".
} else if n = "KSS-2" {
set elist to list(e[2]).
print "Type: KSS-2 (single stage L)".
} else if n:startswith("KSS-") {
set elist to list(e[1],e[0]).
print "Type: KSS Launcher (LL).".
} else if n = "Minimus-Lab" {
set elist to list(e[6],e[5],e[4],e[3]).
} else {
print "Unknown vessel. Abort!".
}

for e in elist {
print " "+e:title.
}

// Functions --------------------------------------------------

function calc_angle {
parameter alt.

if alt < 500 {return 90.}
if alt < 1000 {return 85.}
if alt < 3000 {return 80.}
if alt < 7000 {return 70.}
if alt < 15000 {return 60.}
if alt < 20000 {return 50.}
if alt < 30000 {return 40.}
if alt < 40000 {return 35.}
return 35.
}

// Check for flameout and stage if needed
function eng_check {
set ce to elist[e_cur].
if ce:maxthrust = 0 {
set e_cur to e_cur+1.
print "Fuel for "+ce:title+" exhausted. Staging.".
stage.
wait 0.1.
}
}

// Main --------------------------------------------------

print " ". print "Launching.".
print "3". wait 1. print "2". wait 1. print "1". wait 1.

// Launch
stage.
lock throttle to 1.0.
lock steering to heading(90,90).

// Initiate gravity turn
print "climb to grav turn at "+alt_s.
wait until ship:altitude > alt_s.


// Raise orbit to 10k below apoapsis, wait until out of the athmosphere, stage if necessary
print "gravity turn.".
print "raising AP to 75% of target: "+floor(apoa*0.75).

until ship:altitude > 50000 AND eta:apoapsis < 120 {
// Check if ascent stage is done, decouple and start transfer stage
eng_check().

set app to ship:apoapsis/apoa.
if app > .75 {lock throttle to 0.0.}
else {lock throttle to 1.0.}

lock steering to heading(90,calc_angle(ship:altitude)).
wait 0.2.
}

// Now we are out of the athmosphere and high. Raise orbit to apoapsis, stage if necessary
print "raising AP to 100% of target: "+floor(apoa).

until eta:apoapsis < 35 {
// Check if ascent stage is done, decouple and start transfer stage
eng_check().

set app to ship:apoapsis/apoa.
if app > .999 {lock throttle to 0.0.}
else if app > .99 {lock throttle to 0.1.}
else {lock throttle to 1.0.}

lock steering to ship:prograde.
wait 0.2.
}

print "turning for PE raise.".
lock throttle to 0.0.
lock steering to heading (90,0).

// Raise Periapsis, stage if necessary
set t to eta:apoapsis-30.
print "Waiting "+floor(t)+" seconds for Periapsis raise.".
wait t.

// burn
until ship:periapsis > apoa {
lock steering to heading (90,0).
set ea to eta:apoapsis.
if ship:periapsis < 0 {
if ea > 25 AND ea < 120 { set thr to 0.1. }
else {set thr to 1.0.}
} else {
if ea > 5 AND ea < 120 { set thr to 0. }
else if ea < 5 { set thr to 0.2.}
else { set thr to 1.}
}
lock throttle to thr.

eng_check().
wait 0.2.
}

lock throttle to 0.

print "Orbit reached: A/P/T "+floor(ship:apoapsis)+" / "+floor(ship:periapsis)+" / "+apoa.
myexit().
Expand Down
Loading

0 comments on commit 3ac8953

Please sign in to comment.