-
Notifications
You must be signed in to change notification settings - Fork 0
/
execmanoeuver.py
52 lines (42 loc) · 1.33 KB
/
execmanoeuver.py
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
import krpc
from toolbox import *
from time import sleep
from math import exp,sqrt,cos,pi
conn = krpc.connect(name='Launch Program')
vessel = conn.space_center.active_vessel
control = vessel.control
ap = vessel.auto_pilot
ap.reference_frame = vessel.orbit.body.reference_frame
ap.set_pid_parameters(30,0,6)
ap.engage()
if len(control.nodes)<1:
raise NameError('NoNode')
rm = runmode()
mynode = control.nodes[0]
while rm:
if rm(0):
dv = mynode.delta_v
########################
#Only for 1-engine vessels
for eng in vessel.parts.engines:
if eng.active:
Isp=eng.specific_impulse
break
########################
mdot = vessel.max_thrust/9.82/Isp #mass flowrate
mfoverm0 = exp(-dv/Isp/9.82)
dt = vessel.mass*(1-mfoverm0)/mdot
rm+1
if rm(1):
ap.target_direction=mynode.burn_vector(vessel.orbit.body.reference_frame)
print "ETA: {0:0.2f}".format(mynode.time_to-dt/2)
if mynode.time_to<dt/2:
rm+1
if rm(2):
dvvec=mynode.remaining_burn_vector(vessel.orbit.body.reference_frame)
ap.target_direction=dvvec
tcommand = 0.07*mynode.remaining_delta_v
control.throttle = min(max(tcommand,0),1)
if tnorm(dvvec)<0.2:
rm.finish()
control.throttle = 0