-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecnode.ks
More file actions
93 lines (76 loc) · 2.23 KB
/
execnode.ks
File metadata and controls
93 lines (76 loc) · 2.23 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
// Parameters
parameter slack is 30.
// Imports
run once koslib.
// Fixed parameters
set final_slack to 5.
set stage_wait to 3.
// Prepare the ship
clearscreen.
sas off.
set node to nextnode.
// figure out burn duration
set dob to burn_time(node:deltav:mag).
print "Estimated burn time: " + sec2timestr(dob).
// warp to burn time; give some slack for final steering adjustments
set hang to node:eta - dob / 2 - slack.
print "Warping ahead by " + sec2timestr(hang).
set twarpexit to time:seconds + hang.
if hang > 0 {
set warpmode to "RAILS".
warpto(twarpexit).
}
// estimate burn direction
set node_facing to lookdirup(node:deltav, facing:topvector).
// point ship at node
lock steering to lookdirup(node:deltav, facing:topvector).
wait until (vdot(facing:forevector, node_facing:forevector) >= 0.999 and ship:angularvel:mag < 0.01) or node:eta <= dob / 2.
// wait to fire
wait until time:seconds > twarpexit.
set warpmode to "PHYSICS".
set warp to 4.
wait until time:seconds > twarpexit + slack - final_slack.
set warp to 0.
set warpmode to "RAILS".
wait until time:seconds > twarpexit + slack.
set done to false.
set dv0 to node:deltav.
set dvmin to dv0:mag.
set th to 0.
lock throttle to th.
when availablethrust = 0 then {
stage.
set t0 to time:seconds.
wait until stage:ready.
if availablethrust = 0 {
on time:seconds {
if time:seconds > t0 + stage_wait {
stage.
return false.
}
return true.
}
}
}
until done {
if (node:deltav:mag < dvmin) {
set dvmin to node:deltav:mag.
}
// feather the throttle
set accel to availablethrust / mass.
if accel > 0 and mass > 0 {
set th to clip(dvmin / accel, 0, 1.0).
print "Requesting throttle of " + round(th, 1) at (0,15).
}
// three conditions for being done:
// 1) overshot (node delta vee is pointing opposite from initial)
// 2) burn DV increases (off target due to wobbles)
// 3) burn DV gets too small for main engines to cope with
set done to (vdot(dv0, node:deltav) < 0) or
(node:deltav:mag > dvmin + 0.1) or
(node:deltav:mag <= 0.2).
}
// Cleanup
lock throttle to 0.
unlock steering.
remove node.