-
Notifications
You must be signed in to change notification settings - Fork 0
/
rv.ks
150 lines (115 loc) · 3.68 KB
/
rv.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
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
141
142
143
144
145
146
147
148
149
150
// Rendevous with another craft
run once libguido.
run once liborbital.
myinit().
declare parameter dst is vessel("KSS").
set alt_ship to (ship:apoapsis+ship:periapsis)/2.
set alt_dst to (dst:apoapsis+dst:periapsis)/2.
if dst:distance > 10000 {
// Calculate time for Hohmann Transfer
set t_trans to t_hohmann(alt_ship, alt_dst).
// Calculate how much target will have moved
set a_trans to 180-360/dst:orbit:period*t_trans.
print "calculating hohmann transfer.".
print "duration: "+round(t_trans,0)+" sec".
print "phase an: "+round(a_trans,1)+" deg".
set a to 999.
lock steering to prograde.
until a-a_trans < 0.1 {
set a to mod(dst:longitude-ship:longitude+720,360).
set da to mod(a-a_trans+720,360).
set dt to da/( 360*(dst:orbit:period-ship:orbit:period) / (ship:orbit:period^2) )*0.9.
print1s("delta:"+round(da,4)+" dt: "+round(dt,1)+" s").
// Adjust speed
set_warp_for_t(dt-10).
wait max(dt-55,1).
}
wait_turn(ship:prograde).
lock steering to ship:prograde.
wait 1.
print "starting burn.".
until ship:apoapsis > alt_dst {
if alt_dst-ship:apoapsis < 1000 {
lock throttle to 0.01.
} else {
lock throttle to 0.1.
}
wait 0.1.
}
lock throttle to 0.
wait 0.1.
rwait(eta:apoapsis).
}
set done to false.
until done {
// Adjust speed if needed.
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
print "v_rel: "+v_rel:mag+" dist: "+dst:position:mag.
if v_rel:mag > 1 {
// Zero out relative speed.
print "reducing relative speed.".
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
wait_turn(v_rel:direction).
until v_rel:mag < 1 {
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
lock steering to v_rel:direction.
set_throttle(v_rel:mag,2).
wait 0.1.
}
lock throttle to 0.
wait 0.1.
}
// Move closer if needed
print "v_rel: "+round(v_rel:mag,1)+" dist: "+round(dst:position:mag).
if dst:position:mag > 100 {
print "accelerating toward target.".
wait_turn(dst:position:direction).
wait 1.
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
set speed to max(2,dst:position:mag/120).
print "approaching v: "+speed.
until v_rel:mag > speed {
set_throttle(10,2).
lock steering to dst:position:direction.
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
wait 0.1.
}
lock throttle to 0.
print "in transit, turning to break.".
set old_dist to 999999.
until dst:position:mag < 100 OR old_dist < dst:position:mag {
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
lock steering to v_rel:direction.
set dv to v_rel:mag.
set dt to dv/(ship:maxthrust/ship:mass).
set t_left to dst:position:mag/dv.
if t_left < 10 {
set_throttle(dv,10).
}
set old_dist to dst:position:mag.
wait 0.2.
}
}
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
if dst:position:mag < 100 AND v_rel:mag < 1 {
set done to True.
}
}
// Try to get speed down to as low as possible.
// Zero out relative speed.
print "arrived. attempting to zero speed.".
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
wait_turn(v_rel:direction).
wait 2.
set v_old to 99999.
until v_rel:mag > v_old {
set v_old to v_rel:mag.
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
lock steering to v_rel:direction.
lock throttle to 0.01.
wait 0.1.
set v_rel to dst:velocity:orbit - ship:velocity:orbit.
}
lock throttle to 0.
myexit().
print "done.".