Add node execution code.

This commit is contained in:
Anna Rose 2021-07-19 03:43:07 -04:00
parent 34ddc42b37
commit e0d1c34b46
6 changed files with 71 additions and 26 deletions

View File

@ -5,6 +5,7 @@ compile "0:/os/rocketos" to "1:/boot/rocketos".
compile "0:/lib/navigation" to "1:/lib/navigation".
compile "0:/lib/throttle" to "1:/lib/throttle".
compile "0:/launch" to "1:/launch".
compile "0:/nextnode" to "1:/nextnode".
// Set OS to boot and restart.
set core:bootfilename to "boot/rocketos".

View File

@ -35,14 +35,6 @@ lock THROTTLE to 1.0.
lock STEERING to heading(90,90,270).
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.
lock STEERING to heading(90, GRAVITY_PITCH, 270).
@ -76,9 +68,10 @@ until SHIP:ORBIT:APOAPSIS > 80000 {
wait 0.001.
}
SHIP:ADD(CreateCircularizationNode(SHIP:ORBIT:ETA:APOAPSIS)).
print "Releasing controls. Good luck, Kerman!".
lock THROTTLE to 0.0.
wait 0.001.
set SHIP:CONTROL:PILOTMAINTHROTTLE to 0.
unlock THROTTLE.
unlock STEERING.
SAS on.

View File

@ -1,6 +1,30 @@
// functions for calculating steering values.
@lazyglobal off.
function GetPitch {
parameter v is SHIP:FACING:FOREVECTOR.
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.
}

View File

@ -1,4 +1,4 @@
// Functions for calculating navigational and guidance values.
// Functions for calculating thrust values.
@lazyglobal off.
// Returns the throttle value you should use to achieve the
@ -42,15 +42,16 @@ function SensorCheck {
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.
function BurnTime {
parameter dV.
local remFactor is (2 / Factor).
local remHeight is (SHIP:APOAPSIS/TargetApoapsis).
local angle is (90 * (1 - (remHeight ^ remFactor))).
return heading(TargetDirection, angle, 90).
list ENGINES in en.
local f is en[0]:MAXTHRUST * 1000. // Engine Thrust (kg * m/s²)
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
View 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.

View File

@ -6,9 +6,15 @@ run "launch"(
).
}
function nodeButtonPressed {
run "executenode".
}
// Button panel
CreateGUI().
local interface is gui(200).
set interface:X to 150.
set interface:X to 200.
set interface:Y to 900.
// Launch button
@ -31,6 +37,9 @@ local targetApo is hBox:AddTextField("80000").
local launchButton is interface:AddButton("Launch").
set launchButton:onClick to launchButtonPressed@.
local nodeButton is interface:AddButton("Execute Node").
set launchButton:onClick to nodeButtonPressed@.
interface:show().
wait until false.