Lots of changes everywhere.

This commit is contained in:
Anna Rose 2021-08-01 01:23:39 -04:00
parent b3a6105cbe
commit 13018f75aa
11 changed files with 186 additions and 25 deletions

View File

@ -7,6 +7,7 @@ deletepath("/boot/rocket").
// Install software.
compile "0:/lib/navigation" to "1:/lib/navigation".
compile "0:/lib/throttle" to "1:/lib/throttle".
compile "0:/lib/stabilize_rocket" to "1:/lib/stabilize_rocket".
compile "0:/rocket/init" to "1:/init".
compile "0:/rocket/launch" to "1:/launch".
copypath("0:/rocket/execnode", "1:/execnode").

9
boot/rocket_debug.ks Normal file
View File

@ -0,0 +1,9 @@
// Install software.
copypath("0:/lib/navigation", "1:/lib/navigation").
copypath("0:/lib/throttle", "1:/lib/throttle").
copypath("0:/lib/stabilize_rocket", "1:/lib/stabilize_rocket").
copypath("0:/rocket/init", "1:/init").
copypath("0:/rocket/launch", "1:/launch").
copypath("0:/rocket/execnode", "1:/execnode").
run "init".

View File

@ -1,10 +1,29 @@
// Intended to be run from volume 0 for checking compiled sizes.
for file in FILES {
if file:ISFILE and file:EXTENSION = "ks" {
compile file:NAME.
switch to 0.
compileHere().
function compileDir {
parameter dir.
cd("dir").
compileHere().
cd("..").
}
function compileHere {
local fileList is list().
list files in fileList.
for f in fileList {
if f:ISFILE {
compile f.
} else {
compileDir(f).
}
}
}
// TODO: might be neat to actually do a filesize comparison and print a report or something,
// specifically iterating files NOT to compile.
// TODO: We could hypothetically even integrate this with the bootstrapper.
}

View File

@ -73,8 +73,12 @@ function RenderDirAxes {
}
if vec <> V(0,0,0) {
// RenderVectorShipRelative(vec).
RenderDirAxes(vec).
if vec:istype("vector") {
RenderVectorWithComponents(vec).
}
if vec:istype("direction") {
RenderDirAxes(vec).
}
}
function ClearRenders {

View File

@ -1,4 +1,4 @@
// This script assumes you have bound collective (aka deploy angle) to main throttle.
runoncepath("lib/control").
Stabilize().
PointStabilizeH().

View File

@ -17,7 +17,7 @@ local y is interface:AddVLayout().
local x is y:AddHLayout().
set x:AddButton("HOVER"):onClick to {
Stabilize().
PointStabilizeH().
}.
set x:AddButton("LAND"):onClick to {
@ -29,7 +29,7 @@ set x:AddButton("LAND"):onClick to {
toggle AG10.
BRAKES on.
}
Stabilize(-5).
PointStabilizeH(-5).
}.

View File

@ -4,10 +4,11 @@
// set externally when they should return.
// Helicopter-style point stability control.
// Hover, ascend, or descend at a fixed rate.
// Adjusts the throttle to control ascent or descent.
// Adjusts pitch and roll to maintain zero lateral velocity.
function Stabilize {
function PointStabilizeH {
parameter vertSpeed is 0.0.
set done to false.

98
lib/stabilize_rocket.ks Normal file
View File

@ -0,0 +1,98 @@
// Provides stabilization functions, including Hover.
// Stabilizes a rocket relative to the surface, with optional vertical
// velocity. Do not include both this and helicopter_stabilize.ks in one
// program.
function Hover {
parameter vertSpeed is 0.0.
set done to false.
SAS off.
lock THROTTLE to 0.0.
if SHIP:SENSORS:PRES = 0 {
// In a vacuum, perform a more efficient vacuum maneuver.
// This will call hoverAtmo after initial stabilization, to make sure
// we don't flip upside down.
hoverVac(vertSpeed).
} else {
hoverAtmo(vertSpeed).
}
set SHIP:CONTROL:PILOTMAINTHROTTLE to THROTTLE.
unlock THROTTLE.
unlock STEERING.
SAS on.
print "Stabilized operation ended. Returning control to pilot.".
set done to false.
}
function hoverAtmo {
parameter vertSpeed.
local headingV is V(0,0,0).
lock headingV to VectorExcl(SHIP:UP:FOREVECTOR, SHIP:SRFRETROGRADE).
// set up PID controllers
local pitchPID is PIDLoop(5, 0.1, 0.01, 0, 90).
set pitchPID:SETPOINT to 0.
local throttlePID is PIDLoop(0.1, 0.1, 0.001, 0, 1).
set throttlePID:SETPOINT to vertSpeed.
// we use the inverse of GROUNDSPEED because pitch and acceleration are
// inversely proportional here.
local newPitch is 0.0.
lock newPitch to pitchPID:Update(TIME:SECONDS, -SHIP:GROUNDSPEED).
lock STEERING to AngleAxis(-newPitch, SHIP:FACING:STARVECTOR) * headingV.
lock THROTTLE to throttlePID:Update(TIME:SECONDS, SHIP:VERTICALSPEED).
wait until done.
}
function hoverVac {
parameter vertSpeed.
// TODO: implement me!
hoverAtmo(vertSpeed).
}
// Convenience function for landing operations. Hover over a point with a negative velocity, shutting down on landing.
function Land {
set done to false.
when SHIP:STATUS = "LANDED" then {
set done to true.
}
Hover(-0.5).
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.0.
set done to false.
}
// Rocket-style point stability control.
// Hover, ascend, or descend at a fixed rate.
// Adjusts the throttle to control target vertical speed.
// Uses retrograde lock to cancel horizontal velocity.
// TODO: how does this work
// function PointStabilizeR {
// parameter vertSpeed is 0.0.
// set done to false.
// SAS off.
// lock STEERING to SHIP:RETROGRADE.
// wait until VectorAngle(
// SHIP:FACING:FOREVECTOR,
// SHIP:SRFRETROGRADE:FOREVECTOR) < 0.05.
// local throttlePID is PIDLoop(0.1, 0.001, 0.001, 0, 1).
// set throttlePID:SETPOINT to vertSpeed.
// lock THROTTLE to throttlePID:Update(TIME:SECONDS, SHIP:VERTICALSPEED).
// wait until done.
// set SHIP:CONTROL:PILOTMAINTHROTTLE to THROTTLE.
// unlock THROTTLE.
// unlock STEERING.
// SAS on.
// set done to false.
// print "Stabilized operation ended. Returning control to pilot.".
// }

View File

@ -1,4 +1,5 @@
// Functions for calculating thrust values.
// Functions for calculating values related to throttle and thrust.
@lazyglobal off.
// point gravity for TWR calculations.

View File

@ -1,6 +1,6 @@
parameter BOOT_FILE is "rocket".
clearguis().
copypath("0:/boot/"+BOOT_FILE+".ks", "1:/boot").
copypath("0:/boot/"+BOOT_FILE+".ks", "1:/boot/"+BOOT_FILE+".ks").
switch to 1.
runpath("/boot/"+BOOT_FILE).
runpath("/boot/"+BOOT_FILE+".ks").

View File

@ -1,14 +1,14 @@
runoncepath("/lib/navigation").
runoncepath("/lib/throttle").
runoncepath("/lib/stabilize_rocket").
global done is false.
on AG9 {
set done to true.
return true.
}
function launchButtonPressed {
// adjust torque settings here...
local oldEpsilon is STEERINGMANAGER:TORQUEEPSILONMAX.
set STEERINGMANAGER:TORQUEEPSILONMAX to maxEpsilon:TEXT:ToNumber().
local oldStopTime is STEERINGMANAGER:MAXSTOPPINGTIME.
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
run "/launch"(
targetApo:TEXT:ToNumber(),
gravTurnStart:TEXT:ToNumber(),
@ -16,9 +16,6 @@ function launchButtonPressed {
initialPitch:TEXT:ToNumber(),
minimumPitch:TEXT:ToNumber()
).
set STEERINGMANAGER:TORQUEEPSILONMAX to oldEpsilon.
set STEERINGMANAGER:MAXSTOPPINGTIME to oldStopTime..
}
// Main UI.
@ -48,17 +45,28 @@ set x:AddButton("CONF"):onClick to {
set x to y:AddHLayout().
set x:AddButton("HOVER"):onClick to {
Hover().
}.
set x:AddButton("LAND"):onClick to {
Land().
}.
set x to y:AddHLayout().
set x:AddButton("LNCH"):onClick to {
stk:ShowOnly(launchmenu).
}.
set x:AddButton("NODE"):onClick to {
run "/execnode".
set nodeDV:TEXT to NEXTNODE:DELTAV:MAG:ToString.
set nodeBT:TEXT to BurnTime(NEXTNODE:DELTAV:MAG):ToString.
stk:ShowOnly(nodeMenu).
}.
set x:AddButton("TWR"):onClick to {
stk:ShowOnly(twrMenu).
}.
local stk is interface:AddStack().
@ -130,13 +138,33 @@ set twrMenu:AddButton("Lock TWR"):onClick to {
set done to true.
}
print "Locking throttle to target TWR.".
local tgt is twrLock:TEXT:ToNumber().
lock THROTTLE to ThrottleToTWR(tgt).
wait until done.
print "Throttle unlocked.".
}.
// end twr menu
// node menu
local nodeMenu is stk:AddVLayout().
local nodeBox is nodeMenu:AddScrollBox().
set sbox to nodeBox:AddHLayout().
sbox:AddLabel("Node dV").
local nodeDV is sbox:AddLabel().
set sbox to nodeBox:AddHLayout().
sbox:AddLabel("Node Burn Time").
local nodeBT is sbox:AddLabel().
set nodeMenu:AddButton("Execute"):onClick to {
run "/execnode".
}.
// end node menu
interface:show().
wait until false.