Initial transfer file and some other improvements
This commit is contained in:
+3
-1
@@ -92,6 +92,7 @@ function basicAscent {
|
||||
|
||||
wait 0.1.
|
||||
|
||||
// this isn't always true, figure out a way around
|
||||
panels on.
|
||||
radiators on.
|
||||
for a in antennas {
|
||||
@@ -129,7 +130,8 @@ function basicAscent {
|
||||
|
||||
// if we're using a booster to get to orbit drop it before finishing the cirularization
|
||||
when ship:periapsis > 30000 then {
|
||||
if ship:stagenum <> 0 and ship:stagedeltav(ship:stagenum - 1):current > 0 {
|
||||
// use RCS as a condition to not stage the booster
|
||||
if ship:stagenum <> 0 and ship:stagedeltav(ship:stagenum - 1):current > 0 and not brakes {
|
||||
print "Dropping booster".
|
||||
|
||||
// shutdown engines before dropping them
|
||||
|
||||
+3
-1
@@ -79,9 +79,11 @@ until h < 1 {
|
||||
wait 0.
|
||||
}
|
||||
|
||||
lock throttle to 0.
|
||||
unlock throttle.
|
||||
clearscreen.
|
||||
print "Holding position".
|
||||
lock steering to groundSlope().
|
||||
lock steering to lookDirUp(groundSlope(), ship:facing:upvector).
|
||||
wait until ship:angularvel:mag < 0.1.
|
||||
wait 5.
|
||||
print "Stable".
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
|
||||
function hohmannDeltaV {
|
||||
parameter r1 is 1, r2 is 1, mu is 1.
|
||||
|
||||
local vCirc to sqrt(mu / r1).
|
||||
local vHohmann to sqrt(mu * (2 / r1 - 2 / (r1 + r2))).
|
||||
return vHohmann - vCirc.
|
||||
}
|
||||
|
||||
function angleBetween {
|
||||
parameter posA to V(1, 1, 0), posB to V(1, 1, 0).
|
||||
|
||||
local angle to arcTan2(posB:y, posB:x) - arcTan2(posA:y, posA:x).
|
||||
if angle < 0 set angle to angle + 2 * constant:pi.
|
||||
return angle.
|
||||
}
|
||||
|
||||
|
||||
function hohmannTransfer {
|
||||
// parameter targetPeriapsis is 60000.
|
||||
parameter tgtBody is Mun.
|
||||
|
||||
// get the approximate required deltav for a transfer
|
||||
local r1 to ship:orbit:semimajoraxis.
|
||||
local r2 to tgtBody:orbit:semimajoraxis.
|
||||
local vTransfer to hohmannDeltaV(r1, r2, kerbin:mu).
|
||||
|
||||
// compute the transfer time
|
||||
local transferSMA to (r1 + r2) / 2.
|
||||
local transferPeriod to 2 * constant:pi * sqrt(transferSMA^3 / kerbin:mu).
|
||||
local transitTime to transferPeriod / 2.
|
||||
|
||||
// get lead angle (how far ahead the tgtBody must be)
|
||||
local tgtAV to 2 * constant:pi / tgtBody:orbit:period.
|
||||
local leadAngle to tgtAV * transitTime.
|
||||
local transferAngle to constant:pi - leadAngle.
|
||||
|
||||
// find the next time the phase angle condition is satisfied
|
||||
local shipAV to 2 * constant:pi / ship:orbit:period.
|
||||
local relativeAV to tgtAV - shipAV.
|
||||
|
||||
// get the phase angle to the target
|
||||
local bodyToShip to (ship:position - body:position):normalized.
|
||||
local obtNorm to vCrs(bodyToShip, ship:velocity:orbit:normalized):normalized.
|
||||
local bodyToTgt to vXcl(obtNorm, (tgtBody:position - body:position):normalized):normalized.
|
||||
local signVec to vCrs(obtNorm, bodyToShip):normalized.
|
||||
local phaseSign to vDot(bodyToTgt, signVec).
|
||||
local currentPhaseAngle to vAng(ship:position - body:position, tgtBody:position - body:position) * (constant:pi / 180).
|
||||
if phaseSign < 0 set currentPhaseAngle to -1 * currentPhaseAngle + 2 * constant:pi.
|
||||
|
||||
// get the time to start the maneuver
|
||||
local phaseError is transferAngle - currentPhaseAngle.
|
||||
if phaseError < 0 set phaseError to phaseError + 2 * constant:pi.
|
||||
local waitTime to phaseError / relativeAV.
|
||||
if waitTime < 0 set waitTime to waitTime + ship:orbit:period.
|
||||
|
||||
set nd to node(time:seconds + waitTime, 0, 0, vTransfer).
|
||||
add nd.
|
||||
|
||||
// print "Transfer DeltaV (m/s) : " + round(vTransfer, 2).
|
||||
// print "Transit Time (s) : " + round(transitTime*57.3, 0).
|
||||
// print "Lead Angle (deg) : " + round(transferAngle*57.3, 2).
|
||||
// print "Relative AV (deg/s) : " + relativeAV*57.3.
|
||||
// print "Phase Angle (deg) : " + round(currentPhaseAngle*57.3, 2).
|
||||
// print "Phase Error (deg) : " + round(phaseError*57.3, 2).
|
||||
// print "Wait Time (s) : " + round(waitTime, 0).
|
||||
}
|
||||
|
||||
hohmannTransfer(Mun).
|
||||
Reference in New Issue
Block a user