101 lines
3.7 KiB
Plaintext
101 lines
3.7 KiB
Plaintext
//import functions
|
|
run once "lib/isp".
|
|
set nd to nextnode.
|
|
|
|
//print out node's basic parameters - eta and deltav
|
|
print "node in: " + round(nd:eta) + ", deltav: " + round(nd:deltav:mag).
|
|
|
|
//calculate ship's max acceleration
|
|
set maxacc to ship:availablethrust/ship:mass.
|
|
|
|
// calculate exaust velocity of all active engines
|
|
set ev to evcalc().
|
|
set thrust to ship:availablethrust.
|
|
set dv to nd:deltav:mag.
|
|
//magic equasion to figure burnduration.
|
|
set burnduration to ((ship:mass*ev)/thrust)*(1-constant:e^(-(dv/ev))).
|
|
print "estimated burn duration: " + round(burnduration) + "s".
|
|
|
|
sas off.
|
|
set steeringmanager:maxstoppingtime to 10.
|
|
set steeringmanager:pitchpid:kd to 2.
|
|
set steeringmanager:yawpid:kd to 2.
|
|
set steeringmanager:rollpid:kd to 2.
|
|
lock steering to lookdirup(nd:deltav, sun:position). //points to node, roll so that solar panels are facing towards sun.(design craft so solar panels are pointing out of vab door and directly away from vab door.)
|
|
// sas is better at steering craft with very little control.
|
|
//sas on.
|
|
//sas needs 1 tick between turning on and setting mode.
|
|
//wait until true.
|
|
//set sasmode to "maneuver".
|
|
//now we need to wait until the burn vector and ship's facing are aligned
|
|
wait until vang(nd:deltav, ship:facing:vector) < 0.25.
|
|
|
|
//warp to 60 seconds before the burn, if we are more than 90 seconds away from it. otherwise, we wait.
|
|
if nd:eta-(burnduration/2) > 90 {
|
|
set unwarptime to time:seconds+nd:eta-(burnduration/2)-60.
|
|
kuniverse:timewarp:warpto(unwarptime).
|
|
}
|
|
|
|
//give some time for our sunroll.
|
|
wait until nd:eta <= ((burnduration/2)+55).
|
|
|
|
set steeringmanager:maxstoppingtime to 2.
|
|
set steeringmanager:pitchpid:kd to 2.
|
|
set steeringmanager:yawpid:kd to 2.
|
|
set steeringmanager:rollpid:kd to 2.
|
|
//lock the steering, so we wont be chasing the manuver node.
|
|
//points to node, roll so that solar panels are facing towards sun.(design craft so solar panels are pointing out of vab door and directly away from vab door.)
|
|
set dir to lookdirup(nd:deltav, sun:position).
|
|
lock steering to dir.
|
|
|
|
//the ship is facing the right direction, let's wait for our burn time
|
|
wait until nd:eta <= (burnduration/2).
|
|
|
|
//we only need to lock throttle once to a certain variable in the beginning of the loop, and adjust only the variable itself inside it
|
|
set tset to 0.
|
|
lock throttle to tset.
|
|
|
|
set done to false.
|
|
//initial deltav
|
|
set dv0 to nd:deltav.
|
|
until done
|
|
{
|
|
//recalculate current maxacceleration, as it changes while we burn through fuel
|
|
set maxacc to ship:availablethrust/ship:mass.
|
|
|
|
//throttle is 100% until there is less than 1 second of time left to burn
|
|
//when there is less than 1 second - decrease the throttle linearly
|
|
set tset to min(nd:deltav:mag/maxacc, 1).
|
|
|
|
//here's the tricky part, we need to cut the throttle as soon as our nd:deltav and initial deltav start facing opposite directions
|
|
//this check is done via checking the dot product of those 2 vectors
|
|
if vdot(dv0, nd:deltav) < 0
|
|
{
|
|
print "end burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
|
|
lock throttle to 0.
|
|
break.
|
|
}
|
|
|
|
//we have very little left to burn, less then 0.1m/s
|
|
if nd:deltav:mag < 0.1 {
|
|
print "finalizing burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
|
|
//we burn slowly until our node vector starts to drift significantly from initial vector
|
|
//this usually means we are on point
|
|
wait until vdot(dv0, nd:deltav) < 0.5.
|
|
|
|
lock throttle to 0.
|
|
print "end burn, remain dv " + round(nd:deltav:mag,1) + "m/s, vdot: " + round(vdot(dv0, nd:deltav),1).
|
|
set done to true.
|
|
}
|
|
}
|
|
unlock steering.
|
|
unlock throttle.
|
|
wait 1.
|
|
|
|
//we no longer need the maneuver node
|
|
remove nd.
|
|
|
|
//set throttle to 0 just in case.
|
|
set ship:control:pilotmainthrottle to 0.
|
|
sas on.
|