Add code to estimate at what distance from a grounded target we should burn to come to a stop over the target.

This commit is contained in:
Anna Rose 2021-08-10 18:08:00 -04:00
parent 224a076b8b
commit aa7e50cfff
3 changed files with 69 additions and 9 deletions

View File

@ -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.

View File

@ -49,5 +49,7 @@ function MakeMenu {
stack:ShowOnly(top).
}.
if execLabel <> "" {
set top:AddButton(execLabel):onClick to callback:Bind(optionList).
}
}

View File

@ -39,7 +39,7 @@ set btn:ONTOGGLE to {
MakeMenu(
stk,
MakeButton(rows[0], "SENSOR"),
MakeButton(rows[0], "SENS"),
List(
List("Pressure", "RO", "-1"),
List("Temperature", "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.