-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeo_xfer.ks
More file actions
51 lines (40 loc) · 1.36 KB
/
keo_xfer.ks
File metadata and controls
51 lines (40 loc) · 1.36 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
run once koslib.
parameter target_lng.
clearscreen.
// Constants
set r to body:radius.
set d to 2 * r.
set mu to body:mu.
set T_body to body:rotationperiod.
set pi to constant:pi.
set alt_keo to 2863334.
set sma_keo to alt_keo + r.
set T_keo to 6 * 60 * 60.
// Get transfer orbit period
set sma_xfer to (obt:semimajoraxis + sma_keo) / 2.
set T_xfer to 2 * constant:pi * sqrt(sma_xfer^3 / mu).
print "Period of transfer orbit: " + sec2timestr(T_xfer).
// How much does the planet rotate between xfer and circ burns?
set offset_angle to 360 * mod((T_xfer / 2) / T_body, 1).
print "Offset angle: " + round(offset_angle, 2).
// What angle should we burn at?
set burn_lng to normang(target_lng - 180 + offset_angle).
print "Burn longitude: " + round(burn_lng, 2).
// When will we arrive at that angle?
function lng_diff {
parameter t.
return abs(angdiff(body:geopositionof(positionat(ship, t)):lng, burn_lng)).
}
if lng_diff(time:seconds) < lng_diff(time:seconds + 0.01) {
set guess to time:seconds + T_body / 2.
} else {
set guess to time:seconds.
}
set burn_t to btls(lng_diff@, guess, 10, 0.1, 4).
print "Burning in: " + round(burn_t, 1) + "s".
// How much should we burn?
set v_init to velocityat(ship, burn_t):orbit:mag.
set v_final to sqrt(v_init^2 + (mu * (1/obt:semimajoraxis - 1/sma_xfer))).
// Create node
set nd to node(burn_t, 0, 0, v_final - v_init).
add nd.