diff --git a/lib/navigation.ks b/lib/navigation.ks index b23f1ed..5c76c9b 100644 --- a/lib/navigation.ks +++ b/lib/navigation.ks @@ -1,5 +1,7 @@ // functions for calculating steering values. +runoncepath("/lib/node"). + function GetPitch { parameter v is SHIP:FACING:FOREVECTOR. return 90 - vectorangle(SHIP:UP:FOREVECTOR, v). @@ -46,6 +48,41 @@ function CreateCircularizationNode { return n. } +// The distance at which to start burning to reach a target on the ground. +// REQUIRES a circular orbit. +// TODO: it would be great to semi-automate this... +function TargetBurnDistance { + return Sqrt(StoppingDistance()^2 + (SHIP:ORBIT:SEMIMAJORAXIS - SHIP:BODY:RADIUS - TARGET:ALTITUDE)^2). +} + +// Stopping distance at current velocity. For a circular orbit this is valid at any point in the orbit. +function StoppingDistance { + local dV is SHIP:VELOCITY:SURFACE:MAG. + return dV*BurnTime(dV)/2. +} + +// Figure out our closest approach to our current target within the next +// N seconds. (default orbital_period * 2) +// This is a horrible, terrible, no good, very bad brute force hack. +// function timeAtClosestApproach { +// parameter maxSeconds is SHIP:ORBIT:PERIOD * 2. + +// // find the closest approach to pos +// local t is TIME. +// local minD is (PositionAt(TARGET, t) - PositionAt(SHIP, t)):MAG. +// local minT is t. +// until false { +// local d is (PositionAt(TARGET, t) - PositionAt(SHIP, t)):MAG. +// if d < minD { +// set minD to d. +// set minT to t. +// } +// set t to t+1. +// } + +// return minT. +// } + // function PredictGeo { // parameter t. diff --git a/lib/ui.ks b/lib/ui.ks index 4b1a5d8..a472a52 100644 --- a/lib/ui.ks +++ b/lib/ui.ks @@ -49,5 +49,7 @@ function MakeMenu { stack:ShowOnly(top). }. - set top:AddButton(execLabel):onClick to callback:Bind(optionList). + if execLabel <> "" { + set top:AddButton(execLabel):onClick to callback:Bind(optionList). + } } diff --git a/prog/rocket.ks b/prog/rocket.ks index 5ba6c67..597c000 100644 --- a/prog/rocket.ks +++ b/prog/rocket.ks @@ -39,8 +39,8 @@ set btn:ONTOGGLE to { MakeMenu( stk, - MakeButton(rows[0], "SENSOR"), - List( + MakeButton(rows[0], "SENS"), + List( List("Pressure", "RO", "-1"), List("Temperature", "RO", "-1"), List("Acceleration", "RO", "-1"), @@ -54,16 +54,21 @@ MakeMenu( MakeMenu( stk, - MakeButton(rows[0], "CONF"), + MakeButton(rows[0], "GRND"), List( - List("Torque Epsilon Max", "SCALAR", "0.001"), - List("Max Stopping Time", "SCALAR", "2.0") + List("Burn Distance", "RO", "-1"), + List("Stopping Time", "RO", "-1"), + List("Stopping Distance", "RO", "-1"), + List("Stopping dV", "RO", "-1") ), - "Apply", + "", + { parameter options. }, { parameter options. - set STEERINGMANAGER:TORQUEEPSILONMAX to options["Torque Epsilon Max"]:TEXT:ToNumber(). - set STEERINGMANAGER:MAXSTOPPINGTIME to options["Max Stopping Time"]:TEXT:ToNumber(). + set options["Burn Distance"]:TEXT to TargetBurnDistance():TOSTRING. + set options["Stopping dV"]:TEXT to SHIP:VELOCITY:SURFACE:MAG:TOSTRING. + set options["Stopping Time"]:TEXT to BurnTime(SHIP:VELOCITY:SURFACE:MAG):TOSTRING. + set options["Stopping Distance"]:TEXT to StoppingDistance():TOSTRING. } ). @@ -138,6 +143,22 @@ MakeMenu( } ). +MakeMenu( + stk, + MakeButton(rows[2], "CONF"), + List( + List("Torque Epsilon Max", "SCALAR", "0.001"), + List("Max Stopping Time", "SCALAR", "2.0") + ), + "Apply", + { + parameter options. + set STEERINGMANAGER:TORQUEEPSILONMAX to options["Torque Epsilon Max"]:TEXT:ToNumber(). + set STEERINGMANAGER:MAXSTOPPINGTIME to options["Max Stopping Time"]:TEXT:ToNumber(). + } +). + + iface:show(). wait until false.