-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasix.ks
More file actions
140 lines (113 loc) · 2.72 KB
/
basix.ks
File metadata and controls
140 lines (113 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
@LAZYGLOBAL OFF.
runOncePath("math/math").
runOncePath("math/vel_vec").
function waitRCS {
RCS on.
print "Turn off RCS to proceed.".
wait until RCS = false.
}
function countdown {
parameter counter, message.
until counter <= 0 {
print counter.
set counter to counter - 1.
wait 1.
}
print message.
}
function doSafeStage {
wait until stage:ready.
stage.
print "Staged.".
}
function autoStage {
local needstage is false.
if stage:ready {
if maxthrust = 0 {
set needstage to true.
} else {
local engineList is list().
list engines in enginelist.
for engine in enginelist {
if engine:ignition and engine:flameout {
set needstage to true.
break.
}
}
}
if needstage {
doSafeStage.
}
}
return needstage.
}
function stopEngine {
parameter message.
lock throttle to 0.
lock steering to prograde.
print "Done: " + message.
}
function addManeuverToFlightPlan {
parameter mnv.
add mnv.
}
function removeManeuverFromFlightPlan {
parameter mnv.
remove mnv.
}
function getManeuverPrecisionMetres {
return 10.
}
function getManeuverPrecisionDeltaV {
return 0.001.
}
function executeManeuver {
parameter mnv.
parameter checkObt_func is { parameter o. return false. }.
parameter autoWarp is true.
parameter throttelCoeff is 1.5.
if (not hasNode) or (nextNode <> mnv) {
addManeuverToFlightPlan(mnv).
}
local minMag is getManeuverPrecisionDeltaV().
if mnv:burnvector:mag < minMag {
removeManeuverFromFlightPlan(mnv).
return.
}
autoStage().
local burnTime is getEstimatedBurnTime(mnv:deltaV:mag).
print "Next maneuver:".
print " in: " + mnv:eta.
print " prograde: " + mnv:prograde.
print " radial: " + mnv:radialout.
print " normal: " + mnv:normal.
print " apoapsis: " + mnv:orbit:apoapsis.
print " periapsis: " + mnv:orbit:periapsis.
print " burntime: " + burnTime.
local startTime is time:seconds + mnv:eta - burnTime / 2.
if autoWarp and BRAKES = false {
warpTo(startTime - 60).
}
else if (startTime - time:seconds) > 180 {
print "Warp to next maneuver to continue.".
}
wait until time:seconds >= startTime - 57.
SAS off.
lock steering to mnv:burnvector.
wait until time:seconds >= startTime - 30.
if vang(ship:facing:forevector, mnv:burnvector) > 30 {
RCS on.
wait until time:seconds >= startTime - 3.
RCS off.
}
lock acc to ship:availablethrust / ship:mass.
wait until time:seconds >= startTime.
lock throttle to choose 1 if acc <= 0 else min(1, throttelCoeff * mnv:deltaV:mag / acc).
local initialVector is mnv:burnvector.
until mnv:burnvector:mag < minMag or vang(initialVector, mnv:burnvector) > 90 or checkObt_func:call(ship:obt) {
autoStage().
wait 0.
}
stopEngine("maneuver").
removeManeuverFromFlightPlan(mnv).
}