Move execnode into a library function.
This commit is contained in:
parent
2d7e23a311
commit
cd8f82de5d
|
@ -13,16 +13,6 @@ on AG9 {
|
|||
return true.
|
||||
}
|
||||
|
||||
function launchButtonPressed {
|
||||
run "/launch"(
|
||||
targetApo:TEXT:ToNumber(),
|
||||
gravTurnStart:TEXT:ToNumber(),
|
||||
gravPitch:TEXT:ToNumber(),
|
||||
initialPitch:TEXT:ToNumber(),
|
||||
minimumPitch:TEXT:ToNumber()
|
||||
).
|
||||
}
|
||||
|
||||
// Main UI.
|
||||
local iface is gui(250, 300).
|
||||
set iface:X to 200.
|
||||
|
@ -98,7 +88,15 @@ set row to makeRow(box).
|
|||
row:AddLabel("Gravity Turn Pitch").
|
||||
local gravPitch is row:AddTextField("75").
|
||||
|
||||
set top:AddButton("Execute"):onClick to launchButtonPressed@.
|
||||
makeButton(top, "Execute", {
|
||||
run "/launch"(
|
||||
targetApo:TEXT:ToNumber(),
|
||||
gravTurnStart:TEXT:ToNumber(),
|
||||
gravPitch:TEXT:ToNumber(),
|
||||
initialPitch:TEXT:ToNumber(),
|
||||
minimumPitch:TEXT:ToNumber()
|
||||
).
|
||||
}).
|
||||
// End Launch Menu
|
||||
|
||||
// Build conf menu
|
||||
|
@ -115,10 +113,10 @@ set row to makeRow(box).
|
|||
row:AddLabel("Max Stopping Time").
|
||||
local maxStopTime is row:AddTextField("2.0").
|
||||
|
||||
set top:AddButton("Apply"):onClick to {
|
||||
makeButton(top, "Apply", {
|
||||
set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber().
|
||||
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
|
||||
}.
|
||||
}).
|
||||
// end conf menu
|
||||
|
||||
// twr menu
|
||||
|
@ -129,7 +127,7 @@ set row to makeRow(top).
|
|||
row:AddLabel("Target TWR").
|
||||
local twrLock is row:AddTextField("1.6").
|
||||
|
||||
set top:AddButton("Lock TWR"):onClick to {
|
||||
makeButton(top, "Lock TWR", {
|
||||
local done is false.
|
||||
on AG9 {
|
||||
set done to true.
|
||||
|
@ -140,13 +138,12 @@ set top:AddButton("Lock TWR"):onClick to {
|
|||
lock THROTTLE to ThrottleToTWR(tgt).
|
||||
wait until done.
|
||||
print "Throttle unlocked.".
|
||||
}.
|
||||
}).
|
||||
// end twr menu
|
||||
|
||||
// node menu
|
||||
local top is stk:AddVLayout().
|
||||
panes:Add("node", top).
|
||||
local box is top:AddScrollBox().
|
||||
|
||||
set row to makeRow(top).
|
||||
row:AddLabel("Node dV").
|
||||
|
@ -156,9 +153,7 @@ set row to makeRow(top).
|
|||
row:AddLabel("Node Burn Time").
|
||||
local nodeBT is row:AddLabel().
|
||||
|
||||
set top:AddButton("Execute"):onClick to {
|
||||
run "/execnode".
|
||||
}.
|
||||
makeButton(top, "Execute", { ExecNode(). }).
|
||||
// end node menu
|
||||
|
||||
iface:show().
|
||||
|
|
39
lib/node.ks
Normal file
39
lib/node.ks
Normal file
|
@ -0,0 +1,39 @@
|
|||
runoncepath("lib/navigation").
|
||||
runoncepath("lib/throttle").
|
||||
|
||||
function ExecNode {
|
||||
SAS off.
|
||||
local t is BurnTime(NEXTNODE:DELTAV:MAG).
|
||||
|
||||
print "Adjusting heading".
|
||||
lock STEERING to NEXTNODE:DELTAV.
|
||||
wait until VAng(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
|
||||
|
||||
print "Warping to node.".
|
||||
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - (t/2) - 5).
|
||||
wait until NEXTNODE:ETA <= (t/2).
|
||||
|
||||
print "Executing burn.".
|
||||
local dvMin is NEXTNODE:DELTAV:MAG.
|
||||
lock THROTTLE to 1.0.
|
||||
|
||||
// Execute the burn, throttling down by half every time we're
|
||||
// consuming more than 25% of our dV in one update.
|
||||
local droppedOnce is false.
|
||||
until NEXTNODE:DELTAV:MAG <= 0.25 or (dVMin < NEXTNODE:DELTAV:MAG and droppedOnce) {
|
||||
|
||||
if NEXTNODE:DELTAV:MAG > dVMin {
|
||||
set droppedOnce to true.
|
||||
} else {
|
||||
set dvMin to NEXTNODE:DELTAV:MAG.
|
||||
set droppedOnce to false.
|
||||
}
|
||||
|
||||
wait 0.01.
|
||||
}
|
||||
|
||||
unlock THROTTLE.
|
||||
unlock STEERING.
|
||||
SAS on.
|
||||
print "Node execution complete.".
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
runoncepath("lib/navigation").
|
||||
runoncepath("lib/throttle").
|
||||
|
||||
SAS off.
|
||||
local t is BurnTime(NEXTNODE:DELTAV:MAG).
|
||||
|
||||
print "Adjusting heading".
|
||||
lock STEERING to NEXTNODE:DELTAV.
|
||||
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
|
||||
|
||||
print "Warping to node.".
|
||||
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - (t/2) - 5).
|
||||
wait until NEXTNODE:ETA <= (t/2).
|
||||
|
||||
// todo: pid loop here or nah? overshoot would be tricky to deal with...
|
||||
print "Executing burn.".
|
||||
|
||||
local dvMin is NEXTNODE:DELTAV:MAG.
|
||||
local throt is 1.0.
|
||||
lock THROTTLE to throt.
|
||||
|
||||
// debug
|
||||
print "dVMin = " + dvMin.
|
||||
print "dV = " + NEXTNODE:DELTAV:MAG.
|
||||
|
||||
// Execute the burn, throttling down by half every time we're
|
||||
// consuming more than 25% of our dV in one update.
|
||||
local droppedOnce is false.
|
||||
until NEXTNODE:DELTAV:MAG <= 0.25 or (dVMin < NEXTNODE:DELTAV:MAG and droppedOnce) {
|
||||
// debug
|
||||
print "dVMin = " + dvMin.
|
||||
print "dV = " + NEXTNODE:DELTAV:MAG.
|
||||
|
||||
if NEXTNODE:DELTAV:MAG > dVMin {
|
||||
set droppedOnce to true.
|
||||
} else {
|
||||
set dvMin to NEXTNODE:DELTAV:MAG.
|
||||
set droppedOnce to false.
|
||||
}
|
||||
|
||||
wait 0.01.
|
||||
}
|
||||
|
||||
unlock THROTTLE.
|
||||
unlock STEERING.
|
||||
SAS on.
|
||||
print "Node execution complete.".
|
||||
|
||||
// debug
|
||||
print "Final dVMin = " + dvMin.
|
||||
print "Final dV = " + NEXTNODE:DELTAV:MAG.
|
||||
|
Loading…
Reference in New Issue
Block a user