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").
// Install software.
compile "0:/ui/rocket" to "1:/init".
compile "0:/lib/navigation" to "1:/lib/navigation".
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".
copypath("0:/execnode", "1:/execnode"). // larger when compiled

View File

@ -1,19 +1,35 @@
runpathonce("lib/navigation").
runpathonce("lib/throttle").
runoncepath("lib/navigation").
runoncepath("lib/throttle").
SAS off.
local n is SHIP:NEXTNODE.
local t is BurnTime(n:MAG)/2.
local t is BurnTime(NEXTNODE:DELTAV:MAG)/2.
lock STEERING to n:DELTAV.
wait until VectorAngle(SHIP:VELOCITY, STEERINGMANAGER:TARGET) <= 0.1.
print "Adjusting heading".
lock STEERING to NEXTNODE:DELTAV.
wait until VectorAngle(SHIP:FACING:FOREVECTOR, STEERINGMANAGER:TARGET:FOREVECTOR) <= 0.1.
print "Warping to node".
KUNIVERSE:WARP:WarpTo(n:TIME - t - 5).
wait until n:ETA <= t.
KUNIVERSE:TIMEWARP:WarpTo(NEXTNODE:TIME - t - 5).
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 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.
// 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 {
print "..." + x.
wait 0.5.
@ -32,11 +32,11 @@ lock STEERING to heading(90,90,270).
stage.
wait until SHIP:ALTITUDE > 200.
print "Vectoring away from launchpad".
print "Vectoring away from launchpad.".
lock STEERING to heading(90, INITIAL_PITCH, 270).
wait until SHIP:ALTITUDE > GRAVITY_TURN_START.
print "Pitching for gravity turn".
print "Pitching for gravity turn.".
// Pitch over...
lock STEERING to heading(90, GRAVITY_PITCH, 270).
// Wait until we have rotated to (approximately) that pitch...
@ -62,14 +62,12 @@ lock THROTTLE to 0.0.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
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().
print "Releasing controls. Circularization maneuver added. Good luck, Kerman!".
runpath("/execnode").
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
unlock THROTTLE.
unlock STEERING.
SAS on.
wait 5.
// todo - automatically execute the node
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").

View File

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

View File

@ -23,6 +23,7 @@ function TWR {
function BurnTime {
parameter dV.
local en is list().
list ENGINES in en.
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").
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().
wait until false.