Fighting with pid loops. WIP.
This commit is contained in:
parent
a39f5fa328
commit
dd6f3d528b
12
boot/helicopter.ks
Normal file
12
boot/helicopter.ks
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// helicopter bootstrapping sequence
|
||||||
|
|
||||||
|
deletepath("/boot/helicopter").
|
||||||
|
|
||||||
|
// Install software.
|
||||||
|
compile "0:/helicopter/ui" to "1:/init".
|
||||||
|
compile "0:/helicopter/hover" to "1:/hover".
|
||||||
|
|
||||||
|
// Set OS to boot and restart.
|
||||||
|
set core:bootfilename to "/init".
|
||||||
|
|
||||||
|
reboot.
|
5
boot/helicopter_debug.ks
Normal file
5
boot/helicopter_debug.ks
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
copypath("0:/helicopter/ui", "1:/init").
|
||||||
|
copypath("0:/helicopter/hover", "1:/hover").
|
||||||
|
|
||||||
|
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||||
|
run "1:/init".
|
|
@ -8,8 +8,8 @@ deletepath("/boot/rocket").
|
||||||
compile "0:/lib/navigation" to "1:/lib/navigation".
|
compile "0:/lib/navigation" to "1:/lib/navigation".
|
||||||
compile "0:/lib/throttle" to "1:/lib/throttle".
|
compile "0:/lib/throttle" to "1:/lib/throttle".
|
||||||
compile "0:/rocket/ui" to "1:/init".
|
compile "0:/rocket/ui" to "1:/init".
|
||||||
compile "0:/rocket/launch" to "1:/rocket/launch".
|
compile "0:/rocket/launch" to "1:/launch".
|
||||||
copypath("0:/rocket/execnode", "1:/rocket/execnode"). // larger when compiled
|
copypath("0:/rocket/execnode", "1:/execnode").
|
||||||
|
|
||||||
// Set OS to boot and restart.
|
// Set OS to boot and restart.
|
||||||
set core:bootfilename to "/init".
|
set core:bootfilename to "/init".
|
||||||
|
|
|
@ -1,17 +1,54 @@
|
||||||
// This script assumes you have bound collective (aka deploy angle) to main throttle.
|
// This script assumes you have bound collective (aka deploy angle) to main throttle.
|
||||||
|
|
||||||
SAS off.
|
// SAS off. // debug: re-enable when adjusting heading
|
||||||
local pitchPID is PIDLoop(0.01, 0.01, 0.01).
|
local pitchPID is PIDLoop(0.01, 0.001, 0.001, -45, 45).
|
||||||
local rollPID is PIDLoop(0.01, 0.01, 0.01).
|
set pitchPID:SETPOINT to 0.
|
||||||
local collectivePID is PIDLoop(0.01, 0.01, 0.01).
|
local rollPID is PIDLoop(0.01, 0.001, 0.001, -70, 70).
|
||||||
|
set rollPID:SETPOINT to 0.
|
||||||
|
local collectivePID is PIDLoop(0.1, 0.1, 0.001, 0, 1).
|
||||||
|
set collectivePID:SETPOINT to 0.
|
||||||
|
|
||||||
local yaw is SHIP:FACING:
|
|
||||||
|
|
||||||
until SHIP:VELOCITY:SURFACE:MAG < 0.01 {
|
local vel is 0. lock vel to SHIP:BODY:UP * SHIP:VELOCITY:SURFACE.
|
||||||
|
set vecDraw(V(0,0,0), vel):show to true. // debug
|
||||||
|
|
||||||
|
local x is 0. lock x to SHIP:FACING:FOREVECTOR * SHIP:VELOCITY:SURFACE.
|
||||||
|
local y is 0. lock y to (SHIP:UP:FOREVECTOR * SHIP:VELOCITY:SURFACE) / (SHIP:VELOCITY:SURFACE:MAG * cos(VectorAngle(SHIP:UP:FOREVECTOR, SHIP:VELOCITY:SURFACE))).
|
||||||
|
local z is 0. lock z to SHIP:FACING:RIGHTVECTOR * SHIP:VELOCITY:SURFACE.
|
||||||
|
local spd is 0. lock spd to SHIP:VELOCITY:SURFACE:MAG.
|
||||||
|
|
||||||
|
local done is false.
|
||||||
|
|
||||||
|
on AG9 {
|
||||||
|
set done to true.
|
||||||
|
}
|
||||||
|
|
||||||
|
until done {
|
||||||
|
// debug
|
||||||
|
// print x + " " + y + " " + z.
|
||||||
|
print "Vertical Speed = " + y.
|
||||||
|
|
||||||
|
local newPitch is pitchPID:Update(TIME:SECONDS, spd). // was x
|
||||||
|
local newRoll is rollPid:Update(TIME:SECONDS, spd). // was z
|
||||||
|
local newThrot is collectivePID:Update(TIME:SECONDS, y). // was y
|
||||||
|
|
||||||
|
// debug
|
||||||
|
print "Yaw = " + mod(360 - SHIP:BEARING, 360).
|
||||||
|
print "Pitch = " + newPitch.
|
||||||
|
print "Roll = " + newRoll.
|
||||||
|
print "Throt = " + newThrot.
|
||||||
|
print "Spd = " + spd.
|
||||||
|
|
||||||
|
set SHIP:CONTROL:PILOTMAINTHROTTLE to newThrot.
|
||||||
LOCK throttle to
|
// lock STEERING to Heading(
|
||||||
|
// mod(360 - SHIP:BEARING, 360),
|
||||||
|
// newPitch,
|
||||||
|
// newRoll
|
||||||
|
// ).
|
||||||
|
wait 0.001.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because helicopters can hover stably, once we achieve a hover we should be able to turn SAS on and call it good.
|
// Because helicopters can hover stably, once we achieve a hover we should be able to turn SAS on and call it good.
|
||||||
|
unlock STEERING.
|
||||||
SAS on.
|
SAS on.
|
||||||
|
print "Hover operation canceled. Returning control.".
|
||||||
|
|
16
helicopter/ui.ks
Normal file
16
helicopter/ui.ks
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// Main UI.
|
||||||
|
local interface is gui(250, 300).
|
||||||
|
set interface:X to 200.
|
||||||
|
set interface:Y to 700.
|
||||||
|
|
||||||
|
// Main menu elements in here.
|
||||||
|
local y is interface:AddVLayout().
|
||||||
|
local x is y:AddHLayout().
|
||||||
|
|
||||||
|
set x:AddButton("HOVER"):onClick to {
|
||||||
|
run "hover".
|
||||||
|
}.
|
||||||
|
|
||||||
|
interface:show().
|
||||||
|
|
||||||
|
wait until false.
|
|
@ -61,7 +61,7 @@ wait 0.001. // make sure these control updates get applied
|
||||||
|
|
||||||
print "Target apoapsis acquired. Creating maneuver node.".
|
print "Target apoapsis acquired. Creating maneuver node.".
|
||||||
add CreateCircularizationNode().
|
add CreateCircularizationNode().
|
||||||
runpath("/rocket/execnode").
|
runpath("/execnode").
|
||||||
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
|
print "Orbit acquired. Releasing controls. Good luck, Kerman.".
|
||||||
unlock THROTTLE.
|
unlock THROTTLE.
|
||||||
unlock STEERING.
|
unlock STEERING.
|
||||||
|
|
|
@ -8,7 +8,7 @@ function launchButtonPressed {
|
||||||
local oldStopTime is STEERINGMANAGER:MAXSTOPPINGTIME.
|
local oldStopTime is STEERINGMANAGER:MAXSTOPPINGTIME.
|
||||||
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
|
set STEERINGMANAGER:MAXSTOPPINGTIME to maxStopTime:TEXT:ToNumber().
|
||||||
|
|
||||||
run "/rocket/launch"(
|
run "/launch"(
|
||||||
targetApo:TEXT:ToNumber(),
|
targetApo:TEXT:ToNumber(),
|
||||||
gravTurnStart:TEXT:ToNumber(),
|
gravTurnStart:TEXT:ToNumber(),
|
||||||
gravPitch:TEXT:ToNumber(),
|
gravPitch:TEXT:ToNumber(),
|
||||||
|
@ -51,7 +51,7 @@ set x:AddButton("LNCH"):onClick to {
|
||||||
stk:ShowOnly(launchmenu).
|
stk:ShowOnly(launchmenu).
|
||||||
}.
|
}.
|
||||||
set x:AddButton("NODE"):onClick to {
|
set x:AddButton("NODE"):onClick to {
|
||||||
run "/rocket/execnode".
|
run "/execnode".
|
||||||
}.
|
}.
|
||||||
|
|
||||||
local stk is interface:AddStack().
|
local stk is interface:AddStack().
|
||||||
|
|
Loading…
Reference in New Issue
Block a user