Pin down more of the logic for flight control.
This commit is contained in:
parent
5b9da6f0f1
commit
34ddc42b37
5 changed files with 78 additions and 17 deletions
|
@ -1,56 +0,0 @@
|
|||
// Functions for calculating navigational and guidance values.
|
||||
@lazyglobal off.
|
||||
|
||||
// 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).
|
||||
}
|
||||
|
||||
// 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).
|
||||
}
|
||||
|
||||
// Check for various sensors and set appropriate global constants.
|
||||
// Currently only checks for grav sensor, as that's the only one used by this library.
|
||||
global HAS_GRAV_SENSOR is false.
|
||||
function SensorCheck {
|
||||
local SensorList is 0.
|
||||
list SENSORS in SensorList.
|
||||
for s in SensorList {
|
||||
if s:type = "grav" {
|
||||
print "Gravometric sensor detected".
|
||||
set HAS_GRAV_SENSOR to true.
|
||||
return.
|
||||
}
|
||||
}
|
||||
set HAS_GRAV_SENSOR to false.
|
||||
}
|
||||
|
||||
// adapted from https://github.com/sporadisk/KSP-KOS-scripts/blob/master/modules/GravityTurn.ks
|
||||
// todo: I don't think I actually like this code...
|
||||
function GravityTurn {
|
||||
parameter TargetDirection is 90.
|
||||
parameter TargetApoapsis is 80000.
|
||||
parameter Factor is 1.
|
||||
|
||||
local remFactor is (2 / Factor).
|
||||
local remHeight is (SHIP:APOAPSIS/TargetApoapsis).
|
||||
local angle is (90 * (1 - (remHeight ^ remFactor))).
|
||||
return heading(TargetDirection, angle, 90).
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue