Forget using a PID loop, just lock to the throttle function and simplify it.
This commit is contained in:
parent
45ca153f2f
commit
401f51425f
|
@ -8,6 +8,7 @@ deletepath("/boot/rocket").
|
|||
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:/launch" to "1:/launch".
|
||||
copypath("0:/execnode", "1:/execnode"). // larger when compiled
|
||||
|
||||
|
|
16
launch.ks
16
launch.ks
|
@ -1,5 +1,5 @@
|
|||
run once "lib/throttle".
|
||||
run once "lib/navigation".
|
||||
runoncepath("lib/throttle").
|
||||
runoncepath("lib/navigation").
|
||||
|
||||
parameter APOAPSIS_TARGET is 80000.
|
||||
parameter GRAVITY_TURN_START is 8000.
|
||||
|
@ -20,16 +20,10 @@ from { local x is 5. } until x = 0 step { set x to x - 1. } do {
|
|||
wait 0.5.
|
||||
}
|
||||
|
||||
// throttle controls
|
||||
when TWR() > 1.5 then {
|
||||
if SHIP:ALTITUDE > 32000 {
|
||||
lock THROTTLE to 1.0.
|
||||
return false.
|
||||
}
|
||||
|
||||
// Hold throttle to maintain 1.5 TWR.
|
||||
// We do *not* use a PID Loop here because we can
|
||||
// calculate the correct value discretely.
|
||||
lock THROTTLE to ThrottleToTWR(1.5).
|
||||
return true.
|
||||
}
|
||||
|
||||
// Main ascent control.
|
||||
lock THROTTLE to 1.0.
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
// Functions for calculating thrust values.
|
||||
@lazyglobal off.
|
||||
|
||||
local G is 9.81.
|
||||
lock G to GetGravAcc().
|
||||
|
||||
function GetGravAcc {
|
||||
if HAS_GRAV_SENSOR = true {
|
||||
return SHIP:SENSORS:GRAV:MAG.
|
||||
}
|
||||
return SHIP:BODY:MU / ((SHIP:BODY:RADIUS+SHIP:ALTITUDE)^2).
|
||||
}
|
||||
|
||||
// Returns the throttle value you should use to achieve the
|
||||
// target TWR. If TWR can't be achieved, returns 1.0. (full throttle)
|
||||
function ThrottleToTWR {
|
||||
parameter targetTWR is 1.5.
|
||||
|
||||
local m is SHIP:MASS.
|
||||
local g is 9.81.
|
||||
if HAS_GRAV_SENSOR = true {
|
||||
set g to SHIP:SENSORS:GRAV:MAG.
|
||||
}
|
||||
return min((targetTWR*m*g)/SHIP:AVAILABLETHRUST, 1.0).
|
||||
return min((targetTWR*m*G)/SHIP:AVAILABLETHRUST, 1.0).
|
||||
}
|
||||
|
||||
// Calculates the ship's current TWR.
|
||||
function TWR {
|
||||
local m is ship:mass.
|
||||
local g is 9.81. // fallback to this approximation that doesn't deal with
|
||||
// altitude change.
|
||||
if HAS_GRAV_SENSOR = true {
|
||||
set g to SHIP:SENSORS:GRAV:MAG.
|
||||
}
|
||||
local t is THROTTLE * SHIP:AVAILABLETHRUST.
|
||||
return t/(m*g).
|
||||
return t/(m*G).
|
||||
}
|
||||
|
||||
// Check for various sensors and set appropriate global constants.
|
||||
|
@ -51,7 +52,6 @@ function BurnTime {
|
|||
local m is SHIP:MASS * 1000. // Starting mass (kg)
|
||||
local e is CONSTANT():E. // Base of natural log
|
||||
local p is en[0]:ISP. // Engine ISP (s)
|
||||
local g is 9.80665. // Gravitational acceleration constant (m/s²)
|
||||
|
||||
return g * m * p * (1 - e^(-dV/(g*p))) / f.
|
||||
return G * m * p * (1 - e^(-dV/(G*p))) / f.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user