ascend + basic auto landing + misc
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import("library/lib_vessel_utils").
|
||||
import("library/lib_ascent").
|
||||
import("library/lib_orbits").
|
||||
|
||||
|
||||
|
||||
|
||||
WaitForEngineStart().
|
||||
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||
|
||||
set profile to 1.2.
|
||||
set turn_start to 1000.
|
||||
set target_orbit to 100000.
|
||||
|
||||
Ascent(target_orbit, turn_start, profile).
|
||||
|
||||
print "Orbit Achieved, Releasing Controls".
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
|
||||
SHUTDOWN.
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
run "defaults".
|
||||
clearscreen.
|
||||
run poweredLanding.
|
||||
|
||||
wait until AG9.
|
||||
WaitForEngineStart().
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||
|
||||
WaitFalling(100).
|
||||
Descent().
|
||||
Landing().
|
||||
+37
-3
@@ -1,5 +1,6 @@
|
||||
run "defaults".
|
||||
|
||||
run "library/lib_orbits".
|
||||
run "library/lib_vessel_utils".
|
||||
run "poweredLanding".
|
||||
|
||||
declare function Reentry{
|
||||
@@ -14,12 +15,45 @@ declare function Reentry{
|
||||
rcs on.
|
||||
lock steering to srfRetrograde.
|
||||
}
|
||||
|
||||
declare function DeorbitBurn{
|
||||
if periapsis < 0
|
||||
{
|
||||
return.
|
||||
}
|
||||
set kscPad to location_constants:kerbin:launchpad.
|
||||
|
||||
// wait until ag10.
|
||||
sas off.
|
||||
rcs on.
|
||||
CreateDeorbit(kscPad, -300, 0, 0).
|
||||
lock steering to nextNode:burnvector.
|
||||
local lock align to vDot(ship:facing:vector, nextNode:burnvector).
|
||||
wait until align > 0.95.
|
||||
unlock steering.
|
||||
sas on.
|
||||
set sasMode to "MANEUVER".
|
||||
wait 0.001.
|
||||
warpTo(time:seconds + nextNode:eta - 15).
|
||||
sas off.
|
||||
local dur to CalculateBurnDuration(nextNode:burnvector:mag, GetIsp(), ship:mass, GetMaxMassFlow() * 1000).
|
||||
print "duration " + dur.
|
||||
lock steering to nextNode:burnvector.
|
||||
wait until nextNode:eta < 1.
|
||||
local end to time:seconds + dur.
|
||||
lock throttle to 1.
|
||||
wait until end <= time:seconds.
|
||||
lock throttle to 0.
|
||||
unlock throttle.
|
||||
unlock steering.
|
||||
remove nextNode.
|
||||
}
|
||||
|
||||
DeorbitBurn().
|
||||
wait until (altitude > 70000 and periapsis > 70000) or (verticalSpeed < -100 and periapsis < 0).
|
||||
wait until (periapsis < 0 and throttle = 0).
|
||||
print "Prep for re-entry".
|
||||
print "Dont forget to Turn of MechJob Q Limit".
|
||||
sas off.
|
||||
rcs on.
|
||||
// set mj to addons:mj.
|
||||
// set asc to mj:ascent.
|
||||
// set asc:limitqaenabled to false.
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
wait until ship:unpacked.
|
||||
clearscreen.
|
||||
copyPath("0:/defaults", "").
|
||||
run "defaults".
|
||||
|
||||
import("an").
|
||||
@@ -0,0 +1,3 @@
|
||||
wait until ship:unpacked.
|
||||
switch to 0.
|
||||
run autoLand.
|
||||
@@ -0,0 +1,6 @@
|
||||
wait until ship:unpacked.
|
||||
clearscreen.
|
||||
copyPath("0:/defaults", "").
|
||||
run "defaults".
|
||||
|
||||
import("faris").
|
||||
@@ -0,0 +1,9 @@
|
||||
wait until ship:unpacked.
|
||||
switch to 0.
|
||||
|
||||
run "defaults".
|
||||
run "library/lib_capacitors".
|
||||
|
||||
|
||||
AutoManageCapacitors().
|
||||
until false.
|
||||
+4
-1
@@ -1 +1,4 @@
|
||||
set terminal:charheight to 20.
|
||||
set terminal:charheight to 20.
|
||||
|
||||
copyPath("0:/library/lib_import", "1:/library/lib_import").
|
||||
run "library/lib_import".
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
import("library/lib_vessel_utils").
|
||||
import("library/lib_ascent").
|
||||
import("library/lib_orbits").
|
||||
|
||||
WaitForEngineStart().
|
||||
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Open Terminal").
|
||||
|
||||
set profile to 1.2.
|
||||
set turn_start to 1000.
|
||||
set target_orbit to 100000.
|
||||
|
||||
Ascent(target_orbit, turn_start, profile).
|
||||
|
||||
print "Orbit Achieved, Releasing Controls".
|
||||
print "Circ DV" + CalculateCircularizationDV().
|
||||
CORE:PART:GETMODULE("kOSProcessor"):DOEVENT("Close Terminal").
|
||||
SHUTDOWN.
|
||||
@@ -0,0 +1,87 @@
|
||||
import("library/lib_staging").
|
||||
import("library/lib_math").
|
||||
import("library/lib_vessel_utils").
|
||||
import("library/lib_orbits").
|
||||
|
||||
|
||||
declare function Ascent{
|
||||
parameter targetOrbit is 100.
|
||||
parameter vericalAscent is 1000.
|
||||
parameter ascentProfile is 1.2.
|
||||
|
||||
print "Vertical Climb to " + vericalAscent.
|
||||
|
||||
set tgtPitch to 90.
|
||||
|
||||
lock throttle to 1.
|
||||
lock steering to heading(90, tgtPitch, 270).
|
||||
|
||||
local lock asccent_prog to Map(apoapsis, 0, targetOrbit, 0.0, 1.0).
|
||||
|
||||
wait until altitude > vericalAscent and asccent_prog > 0.
|
||||
print "Start Gravity turn. Target Apoapsis: " + targetOrbit.
|
||||
|
||||
local lock ease to EaseOutExp(asccent_prog, ascentProfile).
|
||||
local lock tgtPitch to (1 - ease) * 90.
|
||||
|
||||
when periapsis < targetOrbit then {
|
||||
print "P: " + round(asccent_prog, 2) + " T:" + round(ease, 2) + " Pitch: " + round(tgtPitch, 2) + " " at(0, 2).
|
||||
print "Ap: " + round(apoapsis, 2) + " Pe:" + round(periapsis, 2) + " Alt: " + round(altitude, 2) + " " at(0, 3).
|
||||
wait 0.1.
|
||||
preserve.
|
||||
}
|
||||
|
||||
//Auto Staging
|
||||
when periapsis < targetOrbit then{
|
||||
AutoStage().
|
||||
wait 0.01.
|
||||
preserve.
|
||||
}
|
||||
|
||||
wait until apoapsis >= targetOrbit.
|
||||
|
||||
unlock tgt_pitch.
|
||||
lock tgtPitch to 0.
|
||||
unlock steering.
|
||||
|
||||
|
||||
CircularizeBrute(targetOrbit).
|
||||
|
||||
|
||||
unlock steering.
|
||||
unlock throttle.
|
||||
}
|
||||
|
||||
|
||||
local function Circularize{
|
||||
parameter targetOrbit.
|
||||
|
||||
lock throttle to 0.
|
||||
lock steering to heading(90, 0, 270).
|
||||
|
||||
local warpTime is eta:apoapsis.
|
||||
|
||||
local burnDv is CalculateCircularizationDV().
|
||||
local burnDuration is CalculateMultiStageBurnDuration(burnDv).
|
||||
print "Warping to Circularization. " + round(burnDv) + "m/s. T: " + round(burnDuration, 2) + "s" at(0, 4).
|
||||
set warpTime to warpTime - burnDuration.
|
||||
if warpTime > 0 {
|
||||
wait until throttle = 0.
|
||||
wait 0.01. //Wait for accelleration to stop
|
||||
warpTo(time:seconds + warpTime).
|
||||
}
|
||||
wait until eta:apoapsis <= burnDuration.
|
||||
|
||||
lock throttle to 1.
|
||||
wait until periapsis >= targetOrbit.
|
||||
lock throttle to 0.
|
||||
}
|
||||
|
||||
|
||||
local function CircularizeBrute{
|
||||
parameter targetOrbit.
|
||||
lock throttle to 1.
|
||||
lock steering to heading(90, 0, 270).
|
||||
wait until periapsis >= targetOrbit.
|
||||
lock throttle to 0.
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
declare function AutoManageCapacitors{
|
||||
print "start".
|
||||
local capacitors to ship:partsnamedpattern("capacitor").
|
||||
local lock electricity to GetTotalElectiricity().
|
||||
when electricity < 100 then {
|
||||
for cap in capacitors {
|
||||
local capR to cap:resources[0].
|
||||
|
||||
if capR:amount = capR:capacity{
|
||||
local discharge is cap:getmodule("DischargeCapacitor").
|
||||
discharge:doaction("Discharge Capacitor", true).
|
||||
wait 1.
|
||||
break.
|
||||
}
|
||||
}
|
||||
preserve.
|
||||
}
|
||||
when throttle = 0 then {
|
||||
for cap in capacitors {
|
||||
local capR to cap:resources[0].
|
||||
local discharge is cap:getmodule("DischargeCapacitor").
|
||||
|
||||
if capR:amount = capR:capacity{
|
||||
discharge:doaction("Disable Recharge", true).
|
||||
}else{
|
||||
discharge:doaction("Enable Recharge", true).
|
||||
}
|
||||
}
|
||||
preserve.
|
||||
}
|
||||
when throttle > 0 then{
|
||||
for cap in capacitors {
|
||||
local capR to cap:resources[0].
|
||||
local discharge is cap:getmodule("DischargeCapacitor").
|
||||
|
||||
discharge:doaction("Disable Recharge", true).
|
||||
}
|
||||
preserve.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declare function GetTotalElectiricity{
|
||||
LIST RESOURCES IN res.
|
||||
local e is 0.
|
||||
FOR resPart IN res {
|
||||
if resPart:name = "ElectricCharge" {
|
||||
set e to e + resPart:amount.
|
||||
}
|
||||
}
|
||||
return e.
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
declare function import {
|
||||
parameter import_path.
|
||||
copyPath("0:/" + import_path, "1:/" + import_path).
|
||||
runOncePath(import_path).
|
||||
|
||||
}
|
||||
+22
-1
@@ -27,4 +27,25 @@ declare function ApproximateExp {
|
||||
SET result TO result + (xPower / nFact).
|
||||
}
|
||||
RETURN result.
|
||||
}
|
||||
}
|
||||
|
||||
declare function EaseOutExpo {
|
||||
parameter x.
|
||||
parameter p is 10.
|
||||
if x = 1 {
|
||||
return 1.
|
||||
} else{
|
||||
return 1 - (2 ^ (-p * x)).
|
||||
}
|
||||
}
|
||||
|
||||
declare function EaseOutCirc{
|
||||
parameter x.
|
||||
return sqrt(1 - (x - 1)^2).
|
||||
}
|
||||
|
||||
declare function EaseOutExp{
|
||||
parameter x.
|
||||
parameter n is 2.0.
|
||||
return x ^ (2.0 * n).
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
|
||||
declare function CreateDeorbit{
|
||||
parameter target.
|
||||
parameter dv is 300.
|
||||
parameter offsetX is 0.0.
|
||||
parameter offsetZ is 0.0.
|
||||
|
||||
local tol to 100.
|
||||
|
||||
lock steering to retrograde.
|
||||
local lock align to vDot(ship:facing:vector, retrograde:vector).
|
||||
wait until align > 0.95.
|
||||
print align.
|
||||
|
||||
if dv > 0 {
|
||||
set dv to dv * -1.
|
||||
}
|
||||
|
||||
local tr to ADDONS:TR.
|
||||
if not tr:AVAILABLE {
|
||||
print "Trajectoris is not available".
|
||||
return.
|
||||
}
|
||||
|
||||
tr:settarget(target).
|
||||
|
||||
|
||||
local deorbit to NODE(time:seconds + 200, 0, 0, dv).
|
||||
|
||||
until not hasNode{
|
||||
remove nextNode.
|
||||
wait 0.001.
|
||||
}
|
||||
|
||||
add deorbit.
|
||||
wait until tr:hasimpact.
|
||||
|
||||
local ipos to tr:impactpos.
|
||||
local lock offset to (ipos:ALTITUDEPOSITION(0) - target:ALTITUDEPOSITION(0)).
|
||||
local lock xDist to offset:x.
|
||||
local lock zDist to ipos:lat - target:lat.
|
||||
local dt is 60.
|
||||
when xDist < 500000 then{
|
||||
set dt to 30.
|
||||
}
|
||||
when xDist < 100000 then{
|
||||
set dt to 5.
|
||||
}
|
||||
when xDist < 10000 then{
|
||||
set dt to 1.
|
||||
}
|
||||
|
||||
when xDist < 5000 then{
|
||||
set dt to 0.5.
|
||||
}
|
||||
until xDist < offsetX + tol {
|
||||
remove nextNode.
|
||||
wait 0.001.
|
||||
set deorbit:eta to deorbit:eta + dt.
|
||||
add deorbit.
|
||||
wait until tr:hasimpact.
|
||||
set ipos to tr:impactpos.
|
||||
wait 0.001.
|
||||
}
|
||||
until abs(zDist) < offsetZ + tol{
|
||||
remove nextNode.
|
||||
wait 0.001.
|
||||
if zDist > 0 {
|
||||
set deorbit:normal to deorbit:normal - 0.1.
|
||||
} else{
|
||||
set deorbit:normal to deorbit:normal + 0.1.
|
||||
}
|
||||
add deorbit.
|
||||
wait until tr:hasimpact.
|
||||
set ipos to tr:impactpos.
|
||||
}
|
||||
|
||||
unlock steering.
|
||||
}
|
||||
|
||||
declare function CalculateCircularizationDV{
|
||||
local mu is body:mu.
|
||||
|
||||
local apR is apoapsis + body:radius.
|
||||
local circVel is sqrt(mu / apR).
|
||||
local apVel is sqrt(mu * ((2 / apR) - (1 / orbit:semimajoraxis))).
|
||||
return circVel - apVel.
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
declare function AutoStage{
|
||||
if not EnginesInStageActive(ship:stagenum) {
|
||||
stage.
|
||||
wait 0.1.
|
||||
}
|
||||
}
|
||||
|
||||
local function EnginesInStageActive{
|
||||
parameter targetStage.
|
||||
|
||||
list engines in allEngines.
|
||||
for eng in allEngines{
|
||||
if eng:stage = targetStage {
|
||||
if eng:IGNITION and eng:flameout {
|
||||
return false.
|
||||
}
|
||||
}
|
||||
}
|
||||
return true.
|
||||
}
|
||||
|
||||
local function IsFairingStage{
|
||||
parameter s.
|
||||
|
||||
}
|
||||
|
||||
local function StateHasEngines{
|
||||
parameter s.
|
||||
|
||||
}
|
||||
+101
-1
@@ -1,4 +1,4 @@
|
||||
run "library/lib_math".
|
||||
import("library/lib_math").
|
||||
|
||||
declare function WaitForEngineStart{
|
||||
wait until AnyEngineActive().
|
||||
@@ -41,6 +41,24 @@ declare function GetIsp{
|
||||
return sum / weights.
|
||||
}
|
||||
|
||||
declare function GetIspForStage{
|
||||
parameter engineState.
|
||||
parameter pressure is 0.
|
||||
LIST ENGINES IN allEngines.
|
||||
local totalThrust is GetThrustOfStage(engineState).
|
||||
local sum is 0.
|
||||
local weights is 0.
|
||||
for eng in allEngines{
|
||||
if eng:stage = engineState {
|
||||
local w is eng:POSSIBLETHRUST / totalThrust.
|
||||
local ispW is eng:ispat(pressure) * w.
|
||||
set sum to sum + ispW.
|
||||
set weights to weights + w.
|
||||
}
|
||||
}
|
||||
return sum / weights.
|
||||
}
|
||||
|
||||
declare function GetMaxMassFlow{
|
||||
LIST ENGINES IN allEngines.
|
||||
local sum is 0.
|
||||
@@ -129,4 +147,86 @@ declare function CalculateTimeToImpact{
|
||||
local hRel is curAltitude - tgtAltitude.
|
||||
local disc is ((vs^2) + (2 * g * hRel)).
|
||||
return (vs + sqrt(disc)) / g.
|
||||
}
|
||||
|
||||
function CalculateMultiStageBurnDuration{
|
||||
parameter dv.
|
||||
if ship:deltav:current >= dv {
|
||||
print "one stage" at (0, 5).
|
||||
return GetBurnTime(dv, ship:maxthrust, ship:mass).
|
||||
}else{
|
||||
print "multi stage" at (0, 5).
|
||||
local burnTime is 0.
|
||||
local remDv is dv.
|
||||
from {local s is ship:stagenum. } until s = 0 step { set s to s-1.} do {
|
||||
if remDv <= 0 {
|
||||
return burnTime.
|
||||
}
|
||||
local cdv is ship:stagedeltav(s):current.
|
||||
local cmass is GetMassOfStage(s).
|
||||
local cthrust is GetThrustOfStage(s).
|
||||
local cisp is GetIspForStage(s).
|
||||
if cdv >= remDv {
|
||||
set burnTime to burnTime + GetBurnTime(remDv, cmass, cthrust, cisp).
|
||||
}else{
|
||||
set burnTime to burnTime + GetBurnTime(cdv, cmass, cthrust, cisp).
|
||||
}
|
||||
set remDv to remDv - cdv.
|
||||
}
|
||||
return burnTime.
|
||||
}
|
||||
}
|
||||
|
||||
// Burn time from rocket equation
|
||||
function GetBurnTime {
|
||||
parameter deltaV.
|
||||
parameter stagethrust is 0.
|
||||
parameter stagemass is 0.
|
||||
parameter isp is 0.
|
||||
|
||||
if deltaV:typename() = "Vector" {
|
||||
set deltaV to deltaV:mag.
|
||||
}
|
||||
if isp = 0 {
|
||||
set isp to GetIsp().
|
||||
}
|
||||
if stagethrust = 0 {
|
||||
set stagethrust to ship:thrust.
|
||||
}
|
||||
if stagemass = 0 {
|
||||
set stagemass to ship:mass.
|
||||
}
|
||||
|
||||
local burnTime is -1.
|
||||
if stagethrust <> 0 {
|
||||
set burnTime to stagemass * (1 - CONSTANT:E ^ (-deltaV / isp)) / (stagethrust / isp).
|
||||
}
|
||||
return burnTime.
|
||||
}
|
||||
|
||||
function GetThrustOfStage {
|
||||
parameter st.
|
||||
|
||||
local totalThrust is 0.
|
||||
LIST ENGINES IN allEngines.
|
||||
for eng in allEngines{
|
||||
if eng:stage = st {
|
||||
set totalThrust to totalThrust + eng:POSSIBLETHRUST.
|
||||
}
|
||||
}
|
||||
return totalThrust.
|
||||
}
|
||||
|
||||
function GetMassOfStage {
|
||||
parameter st.
|
||||
|
||||
|
||||
local total is 0.
|
||||
LIST PARTS IN allP.
|
||||
for p in allP {
|
||||
if p:stage <= st {
|
||||
set total to total + p:mass.
|
||||
}
|
||||
}
|
||||
return total.
|
||||
}
|
||||
@@ -36,7 +36,6 @@ declare function Landing{
|
||||
|
||||
print "Starting Landing".
|
||||
gear on.
|
||||
set pad to location_constants:kerbin:launchpad:position.
|
||||
lock dist to pad.
|
||||
lock steering to srfRetrograde.
|
||||
rcs on.
|
||||
|
||||
Reference in New Issue
Block a user