-
Notifications
You must be signed in to change notification settings - Fork 0
/
maneuver.ks
93 lines (78 loc) · 2.31 KB
/
maneuver.ks
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
declare parameter stageLimit.
run utility.
lock throttle to 0.
sas off.
// grab our next node
local mNode to nextnode.
// figure out some information about it
set burnDV to mNode:deltav.
set burnDVMag to mNode:deltav:mag.
set burnAcceleration to ship:maxthrust / ship:mass.
set burnTime to burnDVMag / burnAcceleration.
print "Aligning with maneuver prograde.".
//sas on.
lock steering to mNode:deltav.
wait until vang(ship:facing:forevector, mNode:deltav) < 1.
print "Ship aligned.".
// warp to 30s before the burn time
print "Maneuver burn scheduled for " + round(mNode:eta - (burnTime / 2), 1) + " s from now.".
if(mNode:eta > 10) {
print "Warping to 10s before start of burn.".
warpto(time:seconds + mNode:eta - (burnTime / 2) - 10).
print "Warp complete.".
}
// wait for it...
print "Waiting to begin burn...".
wait until (vang(ship:facing:forevector, mNode:deltav) < 1) or (mNode:eta <= (burnTime / 2)).
warpto(time:seconds + mNode:eta - (burnTime / 2)).
until mNode:eta <= (burnTime / 2) {
clearscreen.
print round(mNode:eta - (burnTime / 2), 1) + " s until burn...".
wait 0.1.
}
//wait until mNode:eta <= (burnTime / 2).
print "Burn is go!".
lock throttle to 1.
// wait until we get to 2s left
until burnTime <= 2 {
// autostage if necessary
AutoStage(stageLimit, 10).
// constantly update the acceleration and time left
set burnAcceleration to ship:maxthrust / ship:mass.
if burnAcceleration > 0.001 {
set burnTime to mNode:deltav:mag / burnAcceleration.
}
wait 0.1.
}
print "Burn almost complete, throttling back".
until false {
// autostage if necessary
AutoStage(stageLimit, 10).
// cut the throttle completely if the node prograde flips around and we've somehow passed it!
if(vdot(burnDV, mNode:deltav) < 0) {
lock throttle to 0.
break.
}
// throttle back linearly
set burnAcceleration to ship:maxthrust / ship:mass.
if(burnAcceleration > 0.001) {
lock throttle to min(mNode:deltav:mag / burnAcceleration, 1).
}
else {
lock throttle to 1.
}
// if we're close, hold tight
if(mNode:deltav:mag <= 0.1) {
print "Finalizing burn.".
wait until vdot(burnDV, mNode:deltav) < 0.5.
break.
}
wait 0.01.
}
set ship:control:pilotmainthrottle to 0.
lock throttle to 0.
unlock steering.
unlock throttle.
print "Maneuver burn complete!".
remove mNode.
sas on.