Fix up hover script and improve bootloading.
This commit is contained in:
parent
75a7dfec22
commit
2099d0a284
6 changed files with 105 additions and 61 deletions
|
@ -5,6 +5,24 @@
|
|||
//
|
||||
// Do not include both this and stabilize_helicopter.ks in one program.
|
||||
|
||||
runoncepath("/lib/sensors").
|
||||
|
||||
// Convenience function for landing operations. Hover over a point with a negative velocity, shutting down on landing.
|
||||
function Land {
|
||||
set done to false.
|
||||
|
||||
alignForHover().
|
||||
local pid is hoverPID().
|
||||
lock THROTTLE to pid:Update(TIME:SECONDS, SHIP:VERTICALSPEED).
|
||||
until done or SHIP:STATUS = "LANDED" {
|
||||
set pid:SETPOINT to (-1 * (SHIP:ALTITUDE - SHIP:GEOPOSITION:TERRAINHEIGHT) / 10) - 5.
|
||||
wait 0.001.
|
||||
}
|
||||
|
||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.0.
|
||||
set done to false.
|
||||
}
|
||||
|
||||
// Stabilizes a rocket relative to the surface, with optional vertical
|
||||
// velocity.
|
||||
function Hover {
|
||||
|
@ -12,33 +30,47 @@ function Hover {
|
|||
|
||||
set done to false.
|
||||
SAS off.
|
||||
|
||||
lock THROTTLE to 0.0.
|
||||
|
||||
if SHIP:SENSORS:PRES = 0 {
|
||||
lock STEERING to SHIP:SRFRETROGRADE.
|
||||
wait until VAng(SHIP:FACING:FOREVECTOR, SHIP:SRFRETROGRADE:FOREVECTOR) < 10.
|
||||
} else {
|
||||
// debug
|
||||
print "Making vector visualization.".
|
||||
local d1 is VecDraw(V(0,0,0), V(0,0,0), BLUE, "", 1.0, true).
|
||||
set d1:VECUPDATER to {
|
||||
return atmoSafeRetrograde() * 100.
|
||||
}.
|
||||
print "Vector visualization created.".
|
||||
// end debug
|
||||
alignForHover().
|
||||
local throttlePID is hoverPID(vertSpeed).
|
||||
lock THROTTLE to throttlePID:Update(TIME:SECONDS, SHIP:VERTICALSPEED).
|
||||
wait until done.
|
||||
|
||||
lock STEERING to atmoSafeRetrograde().
|
||||
wait until done or VAng(SHIP:FACING:FOREVECTOR, atmoSafeRetrograde()) < 10.
|
||||
}
|
||||
|
||||
local throttlePID is PIDLoop(0.1, 0.1, 0.001, 0, 1).
|
||||
set throttlePID:SETPOINT to vertSpeed.
|
||||
|
||||
lock THROTTLE to throttlePID:Update(TIME:SECONDS, -SHIP:VELOCITY:SURFACE:MAG). // this is still wrong, we just burn hard and spin out of control.
|
||||
|
||||
|
||||
// Unwind everything.
|
||||
restoreControls().
|
||||
}
|
||||
|
||||
function hoverPID {
|
||||
parameter initSetpoint is 0.
|
||||
local pid is PIDLoop(0.01, 0.01, 0.001, 0, 1).
|
||||
set pid:SETPOINT to initSetpoint.
|
||||
return pid.
|
||||
}
|
||||
|
||||
function alignForHover {
|
||||
if ReadSensor("pres") = 0 {
|
||||
// if we're in a vacuum, cancel all velocity first...
|
||||
lock STEERING to SHIP:SRFRETROGRADE.
|
||||
print "Aligning with retrograde.".
|
||||
wait until done or VAng(SHIP:FACING:FOREVECTOR, SHIP:SRFRETROGRADE:FOREVECTOR) < 0.1.
|
||||
if done {
|
||||
restoreControls().
|
||||
return.
|
||||
}
|
||||
} else {
|
||||
// ... otherwise just cancel vertical velocity
|
||||
lock STEERING to SHIP:UP.
|
||||
print "Aligning vertical.".
|
||||
wait until done or VAng(SHIP:FACING:FOREVECTOR, SHIP:UP:FOREVECTOR) < 1.
|
||||
if done {
|
||||
restoreControls().
|
||||
return.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restoreControls {
|
||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to THROTTLE.
|
||||
unlock THROTTLE.
|
||||
unlock STEERING.
|
||||
|
@ -46,22 +78,3 @@ function Hover {
|
|||
print "Stabilized operation ended. Returning control to pilot.".
|
||||
set done to false.
|
||||
}
|
||||
|
||||
// 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(-4).
|
||||
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.0.
|
||||
set done to false.
|
||||
}
|
||||
|
||||
function atmoSafeRetrograde {
|
||||
if VAng(SHIP:SRFRETROGRADE:FOREVECTOR, SHIP:UP:FOREVECTOR) < 45 {
|
||||
return SHIP:SRFRETROGRADE:FOREVECTOR.
|
||||
}
|
||||
local planeRetro is VXCL(SHIP:UP:FOREVECTOR, SHIP:SRFRETROGRADE:FOREVECTOR).
|
||||
return AngleAxis(45, SHIP:FACING:STARVECTOR) * planeRetro.
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue