Get full automation to orbit functioning.

This commit is contained in:
Anna Rose 2021-07-20 02:38:29 -04:00
parent 2cceb5c0c1
commit 45cd517a2a
6 changed files with 55 additions and 31 deletions

View File

@ -5,10 +5,9 @@
deletepath("/boot/rocket"). deletepath("/boot/rocket").
// Install software. // Install software.
compile "0:/ui/rocket" to "1:/init".
compile "0:/lib/navigation" to "1:/lib/navigation". compile "0:/lib/navigation" to "1:/lib/navigation".
compile "0:/lib/throttle" to "1:/lib/throttle". compile "0:/lib/throttle" to "1:/lib/throttle".
copypath("0:/lib/math", "1:/lib/math"). // larger when compiled compile "0:/ui/rocket" to "1:/init".
compile "0:/launch" to "1:/launch". compile "0:/launch" to "1:/launch".
copypath("0:/execnode", "1:/execnode"). // larger when compiled copypath("0:/execnode", "1:/execnode"). // larger when compiled

View File

@ -1,19 +1,35 @@
runpathonce("lib/navigation"). runoncepath("lib/navigation").
runpathonce("lib/throttle"). runoncepath("lib/throttle").
SAS off. SAS off.
local n is SHIP:NEXTNODE. local t is BurnTime(NEXTNODE:DELTAV:MAG)/2.
local t is BurnTime(n:MAG)/2.
lock STEERING to n:DELTAV. print "Adjusting heading".
wait until VectorAngle(SHIP:VELOCITY, STEERINGMANAGER:TARGET) <= 0.1. lock STEERING to NEXTNODE:DELTAV.
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
print "Warping to node". print "Warping to node".
KUNIVERSE:WARP:WarpTo(n:TIME - t - 5). KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - t - 5).
wait until n:ETA <= t. wait until NEXTNODE:ETA <= t.
// todo: pid loop here or nah? overshoot would be tricky to deal with...
print "Executing burn".
local throt is 1.0.
lock THROTTLE to throt.
local dvLast is NEXTNODE:DELTAV:MAG.
// Execute the burn, throttling down by half every time we're
// consuming more than 25% of our dV in one update.
until NEXTNODE:DELTAV:MAG <= 0.25 {
local dvRem is NEXTNODE:DELTAV:MAG.
if dvRem < dvLast * 0.75 {
set throt to throt / 2.
}
set dvLast to dvRem.
wait 0.001.
}
lock THROTTLE to 1.0.
wait until n:DELTAV:MAG <= 0.1. // todo: pid loop here or no?
unlock THROTTLE. unlock THROTTLE.
unlock STEERING. unlock STEERING.
print "Node Executed. Have a nice day." SAS on.
print "Node Executed. Have a nice day".

View File

@ -15,7 +15,7 @@ RCS off.
SAS off. SAS off.
// Countdowns are cute. // Countdowns are cute.
print "Initiating automated launch sequence". print "Initiating automated launch sequence.".
from { local x is 5. } until x = 0 step { set x to x - 1. } do { from { local x is 5. } until x = 0 step { set x to x - 1. } do {
print "..." + x. print "..." + x.
wait 0.5. wait 0.5.
@ -32,11 +32,11 @@ lock STEERING to heading(90,90,270).
stage. stage.
wait until SHIP:ALTITUDE > 200. wait until SHIP:ALTITUDE > 200.
print "Vectoring away from launchpad". print "Vectoring away from launchpad.".
lock STEERING to heading(90, INITIAL_PITCH, 270). lock STEERING to heading(90, INITIAL_PITCH, 270).
wait until SHIP:ALTITUDE > GRAVITY_TURN_START. wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
print "Pitching for gravity turn". print "Pitching for gravity turn.".
// Pitch over... // Pitch over...
lock STEERING to heading(90, GRAVITY_PITCH, 270). lock STEERING to heading(90, GRAVITY_PITCH, 270).
// Wait until we have rotated to (approximately) that pitch... // Wait until we have rotated to (approximately) that pitch...
@ -62,14 +62,12 @@ lock THROTTLE to 0.0.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0. set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
wait 0.001. // make sure these control updates get applied wait 0.001. // make sure these control updates get applied
print "Target apoapsis acquired. Creating maneuver node". print "Target apoapsis acquired. Creating maneuver node.".
AddCircularizationNode(). AddCircularizationNode().
print "Releasing controls. Circularization maneuver added. Good luck, Kerman!". runpath("/execnode").
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
unlock THROTTLE. unlock THROTTLE.
unlock STEERING. unlock STEERING.
SAS on. SAS on.
wait 5.
// todo - automatically execute the node // todo - automatically execute the node
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").

View File

@ -29,14 +29,15 @@ function AddCircularizationNode {
local n is Node(t, 0, 0, 0). local n is Node(t, 0, 0, 0).
add(n). add(n).
local delta is 1. local epsilon is 100.
local diff is n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS. lock diff to n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS.
until (diff < 1000) { local pid is PIDLoop(0.05, 0.006, 0.006).
set n:PROGRADE to n:PROGRADE + delta. set pid:EPSILON to epsilon.
local newDiff is n:ORBIT:APOAPSIS - n:ORBIT:PERIAPSIS. set pid:SETPOINT to n:ORBIT:APOAPSIS.
if newDiff > diff {
set delta to (delta * -1) / 10. until abs(diff) < epsilon {
} print diff.
set diff to newDiff. set n:PROGRADE to pid:Update(TIME:SECONDS, n:ORBIT:PERIAPSIS).
wait 0.001.
} }
} }

View File

@ -23,6 +23,7 @@ function TWR {
function BurnTime { function BurnTime {
parameter dV. parameter dV.
local en is list().
list ENGINES in en. list ENGINES in en.
local f is en[0]:MAXTHRUST * 1000. // Engine Thrust (kg * m/s²) local f is en[0]:MAXTHRUST * 1000. // Engine Thrust (kg * m/s²)

View File

@ -58,6 +58,15 @@ set nodeButton:onClick to nodeButtonPressed@.
local termButton is interface:AddButton("Terminal"). local termButton is interface:AddButton("Terminal").
set termButton:onClick to terminalButtonPressed@. set termButton:onClick to terminalButtonPressed@.
// debug
function circButtonPressed {
runpath("/lib/navigation").
AddCircularizationNode().
}
local cButton is interface:AddButton("Circularize").
set cButton:onClick to circButtonPressed@.
// end debug
interface:show(). interface:show().
wait until false. wait until false.