Add node execution code.
This commit is contained in:
parent
34ddc42b37
commit
e0d1c34b46
|
@ -5,6 +5,7 @@ compile "0:/os/rocketos" to "1:/boot/rocketos".
|
||||||
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:/launch" to "1:/launch".
|
compile "0:/launch" to "1:/launch".
|
||||||
|
compile "0:/nextnode" to "1:/nextnode".
|
||||||
|
|
||||||
// Set OS to boot and restart.
|
// Set OS to boot and restart.
|
||||||
set core:bootfilename to "boot/rocketos".
|
set core:bootfilename to "boot/rocketos".
|
||||||
|
|
13
launch.ks
13
launch.ks
|
@ -35,14 +35,6 @@ lock THROTTLE to 1.0.
|
||||||
lock STEERING to heading(90,90,270).
|
lock STEERING to heading(90,90,270).
|
||||||
stage.
|
stage.
|
||||||
|
|
||||||
// // DEBUG
|
|
||||||
// until false {
|
|
||||||
// lock STEERING to heading(90,90,-90).
|
|
||||||
// wait 3.
|
|
||||||
// lock STEERING to SHIP:SRFPROGRADE.
|
|
||||||
// wait 3.
|
|
||||||
// }
|
|
||||||
|
|
||||||
wait until SHIP:ALTITUDE > 200.
|
wait until SHIP:ALTITUDE > 200.
|
||||||
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
lock STEERING to heading(90, GRAVITY_PITCH, 270).
|
||||||
|
|
||||||
|
@ -76,9 +68,10 @@ until SHIP:ORBIT:APOAPSIS > 80000 {
|
||||||
wait 0.001.
|
wait 0.001.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHIP:ADD(CreateCircularizationNode(SHIP:ORBIT:ETA:APOAPSIS)).
|
||||||
|
|
||||||
print "Releasing controls. Good luck, Kerman!".
|
print "Releasing controls. Good luck, Kerman!".
|
||||||
lock THROTTLE to 0.0.
|
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
|
||||||
wait 0.001.
|
|
||||||
unlock THROTTLE.
|
unlock THROTTLE.
|
||||||
unlock STEERING.
|
unlock STEERING.
|
||||||
SAS on.
|
SAS on.
|
||||||
|
|
|
@ -1,6 +1,30 @@
|
||||||
|
// functions for calculating steering values.
|
||||||
@lazyglobal off.
|
@lazyglobal off.
|
||||||
|
|
||||||
function GetPitch {
|
function GetPitch {
|
||||||
parameter v is SHIP:FACING:FOREVECTOR.
|
parameter v is SHIP:FACING:FOREVECTOR.
|
||||||
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
|
return 90 - vectorangle(SHIP:UP:FOREVECTOR, v).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CreateCircularizationNode {
|
||||||
|
parameter usePeriapsis is false.
|
||||||
|
local target is SHIP:ORBIT:APOAPSIS.
|
||||||
|
local t is SHIP:ORBIT:ETA:APOAPSIS.
|
||||||
|
if usePeriapsis {
|
||||||
|
set target to SHIP:ORBIT:PERIAPSIS.
|
||||||
|
set t to SHIP:ORBIT:ETA:PERIAPSIS.
|
||||||
|
}
|
||||||
|
local n is Node(t, 0, 0, 0).
|
||||||
|
|
||||||
|
// move fast until we pass our target.
|
||||||
|
until (usePeriapsis and n:ORBIT:APOAPSIS < target) or n:ORBIT:PERIAPSIS > target {
|
||||||
|
set n:PROGRADE to n:PROGRADE + 1.
|
||||||
|
}
|
||||||
|
|
||||||
|
// now bring it back in real slow until we come back.
|
||||||
|
until (usePeriapsis and n:ORBIT:APOAPSIS > target) or n:ORBIT:PERIAPSIS < target {
|
||||||
|
set n:PROGRADE to n:PROGRADE - 0.01.
|
||||||
|
}
|
||||||
|
|
||||||
|
return n.
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// Functions for calculating navigational and guidance values.
|
// Functions for calculating thrust values.
|
||||||
@lazyglobal off.
|
@lazyglobal off.
|
||||||
|
|
||||||
// Returns the throttle value you should use to achieve the
|
// Returns the throttle value you should use to achieve the
|
||||||
|
@ -42,15 +42,16 @@ function SensorCheck {
|
||||||
set HAS_GRAV_SENSOR to false.
|
set HAS_GRAV_SENSOR to false.
|
||||||
}
|
}
|
||||||
|
|
||||||
// adapted from https://github.com/sporadisk/KSP-KOS-scripts/blob/master/modules/GravityTurn.ks
|
function BurnTime {
|
||||||
// todo: I don't think I actually like this code...
|
parameter dV.
|
||||||
function GravityTurn {
|
|
||||||
parameter TargetDirection is 90.
|
|
||||||
parameter TargetApoapsis is 80000.
|
|
||||||
parameter Factor is 1.
|
|
||||||
|
|
||||||
local remFactor is (2 / Factor).
|
list ENGINES in en.
|
||||||
local remHeight is (SHIP:APOAPSIS/TargetApoapsis).
|
|
||||||
local angle is (90 * (1 - (remHeight ^ remFactor))).
|
local f is en[0]:MAXTHRUST * 1000. // Engine Thrust (kg * m/s²)
|
||||||
return heading(TargetDirection, angle, 90).
|
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.
|
||||||
}
|
}
|
||||||
|
|
17
nextnode.ks
Normal file
17
nextnode.ks
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
runpathonce("lib/navigation").
|
||||||
|
runpathonce("lib/throttle").
|
||||||
|
|
||||||
|
SAS off.
|
||||||
|
local n is SHIP:NEXTNODE.
|
||||||
|
local t is BurnTime(n:MAG)/2.
|
||||||
|
|
||||||
|
lock STEERING to n:DELTAV.
|
||||||
|
wait until VectorAngle(SHIP:VELOCITY, STEERINGMANAGER:TARGET) <= 0.1.
|
||||||
|
|
||||||
|
KUNIVERSE:WARP:WarpTo(n:TIME - t - 5).
|
||||||
|
wait until n:ETA <= t.
|
||||||
|
|
||||||
|
lock THROTTLE to 1.0.
|
||||||
|
wait until n:DELTAV:MAG <= 0.1.
|
||||||
|
unlock THROTTLE.
|
||||||
|
unlock STEERING.
|
|
@ -1,14 +1,20 @@
|
||||||
function launchButtonPressed {
|
function launchButtonPressed {
|
||||||
run "launch"(
|
run "launch"(
|
||||||
targetApo:TEXT:ToNumber(),
|
targetApo:TEXT:ToNumber(),
|
||||||
gravTurnStart:TEXT:ToNumber(),
|
gravTurnStart:TEXT:ToNumber(),
|
||||||
initialPitch:TEXT:ToNumber()
|
initialPitch:TEXT:ToNumber()
|
||||||
).
|
).
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nodeButtonPressed {
|
||||||
|
run "executenode".
|
||||||
|
}
|
||||||
|
|
||||||
// Button panel
|
// Button panel
|
||||||
|
CreateGUI().
|
||||||
|
|
||||||
local interface is gui(200).
|
local interface is gui(200).
|
||||||
set interface:X to 150.
|
set interface:X to 200.
|
||||||
set interface:Y to 900.
|
set interface:Y to 900.
|
||||||
|
|
||||||
// Launch button
|
// Launch button
|
||||||
|
@ -31,6 +37,9 @@ local targetApo is hBox:AddTextField("80000").
|
||||||
local launchButton is interface:AddButton("Launch").
|
local launchButton is interface:AddButton("Launch").
|
||||||
set launchButton:onClick to launchButtonPressed@.
|
set launchButton:onClick to launchButtonPressed@.
|
||||||
|
|
||||||
|
local nodeButton is interface:AddButton("Execute Node").
|
||||||
|
set launchButton:onClick to nodeButtonPressed@.
|
||||||
|
|
||||||
interface:show().
|
interface:show().
|
||||||
|
|
||||||
wait until false.
|
wait until false.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user