In [1]:
%run -i 'KRPC.ipynb'

In [2]:
conn = krpc.connect(name='laptop', address='192.168.1.9')

ksc = conn.space_center
vessel = ksc.active_vessel
obt = vessel.orbit
ap = vessel.auto_pilot
con = vessel.control

vrf = vessel.reference_frame
srfrf = vessel.surface_reference_frame
vobtrf = vessel.orbital_reference_frame
obtrf = obt.body.reference_frame
obtorf = obt.body.orbital_reference_frame
obtnrrf = obt.body.non_rotating_reference_frame

flight = lambda rf: vessel.flight(rf)

In [30]:
t = ksc.ut
o = KeplerOrbit(obt)

f = flight(obtorf)
print(obt.time_to_apoapsis, obt.time_to_periapsis)
print(f.longitude)
print(o.Ω * 180/π)
print(o.ν * 180/π)


93.74291767160798 1161.2628530771888
71.2948074774119
239.561698078797
13.3712006268

In [ ]:
speed = conn.add_stream(getattr, flight(srfrf), 'speed')
altitude = conn.add_stream(getattr, flight(obtrf), 'mean_altitude')
apoapsis = conn.add_stream(getattr, obt, 'apoapsis_altitude')

In [5]:
con.throttle = 0.6

ap.set_rotation(90, 90, roll=90)

time.sleep(1)

con.activate_next_stage()

while flight(obtrf).speed < 100.:
    time.sleep(0.1)
    
ap.set_rotation(80, 90, roll=90)

while flight(obtrf).mean_altitude < 5000.:
    time.sleep(0.1)

ap.disengage()
ap.sas = True
ap.sas_mode = ksc.SASMode.prograde

while obt.apoapsis_altitude < 80000:
    time.sleep(0.1)
    
ap.sas_mode = ksc.SASMode.stability_assist
ap.sas = False

while abs(obt.eccentricity) > 0.1:
    obt.apoapsis
    ap.set_direction(, 90, roll=90)
    

    
ap.disengage()
con.throttle = 0.

In [11]:
ksc.SASMode.prograde


Out[11]:
<SASMode.prograde: 2>

In [62]:
speed.remove()
altitude.remove()
apoapsis.remove()

In [4]:
def prelaunch(conn):
    ksc = conn.space_center
    vessel = ksc.active_vessel
    obtbody_rf = vessel.orbit.body.reference_frame
    
    flight = vessel.flight
    ap = vessel.auto_pilot
    cont = vessel.control
    
    vessel
    


ut = conn.add_stream(getattr, ksc, 'ut')
mean_altitude = conn.add_stream(getattr, flight(), 'mean_altitude')
#position = conn.add_stream(vessel.position, obtbody_rf)

timestamp = []
altitude = []

t0 = ut()
alt = mean_altitude()
while alt < 80000:
    t1 = ut()
    alt = mean_altitude()
    if abs(t1 - t0) > 0.001:
        timestamp.append(t1)
        altitude.append(alt)
        t0 = t1
        time.sleep(1./25.)

In [7]:
print(ut())


36067852.33412806

In [5]:
pyplot.plot(timestamp,altitude)


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-0d6233e46f36> in <module>()
----> 1 pyplot.plot(timestamp,altitude)

/usr/lib64/python3.4/site-packages/matplotlib/pyplot.py in plot(*args, **kwargs)
   2985         ax.hold(hold)
   2986     try:
-> 2987         ret = ax.plot(*args, **kwargs)
   2988         draw_if_interactive()
   2989     finally:

/usr/lib64/python3.4/site-packages/matplotlib/axes.py in plot(self, *args, **kwargs)
   4138 
   4139         for line in self._get_lines(*args, **kwargs):
-> 4140             self.add_line(line)
   4141             lines.append(line)
   4142 

/usr/lib64/python3.4/site-packages/matplotlib/axes.py in add_line(self, line)
   1497             line.set_clip_path(self.patch)
   1498 
-> 1499         self._update_line_limits(line)
   1500         if not line.get_label():
   1501             line.set_label('_line%d' % len(self.lines))

/usr/lib64/python3.4/site-packages/matplotlib/axes.py in _update_line_limits(self, line)
   1508         Figures out the data limit of the given line, updating self.dataLim.
   1509         """
-> 1510         path = line.get_path()
   1511         if path.vertices.size == 0:
   1512             return

/usr/lib64/python3.4/site-packages/matplotlib/lines.py in get_path(self)
    742         """
    743         if self._invalidy or self._invalidx:
--> 744             self.recache()
    745         return self._path
    746 

/usr/lib64/python3.4/site-packages/matplotlib/lines.py in recache(self, always)
    419                 x = ma.asarray(xconv, np.float_)
    420             else:
--> 421                 x = np.asarray(xconv, np.float_)
    422             x = x.ravel()
    423         else:

/home/goetz/.local/lib/python3.4/site-packages/numpy/core/numeric.py in asarray(a, dtype, order)
    460 
    461     """
--> 462     return array(a, dtype, copy=False, order=order)
    463 
    464 def asanyarray(a, dtype=None, order=None):

TypeError: float() argument must be a string or a number, not 'Stream'

In [42]:
print(vessel.name)
print(vessel.met)
print(vessel.mass)
print(vessel.position(vessel.orbit.body.reference_frame))


Kerbal X
0.0
129220.0
(159785.88961593373, -1018.0912642640197, -578429.1905414417)

In [81]:
def latlon(vessel):
    x,y,z = vessel.position(vessel.orbit.body.reference_frame)
    r = np.sqrt(x*x + y*y + z*z)
    lat = 90. - np.arccos(y / r) * 180. / np.pi
    lon = np.arctan2(z, x) * 180. / np.pi
    return lat,lon


(-0.097205327823132848, -74.557662208705707)

In [82]:
data = []


(-0.0972053225905114, -74.557662190809467)

In [91]:
image = pyplot.imread('/home/goetz/kerbin.jpg')
fig, ax = pyplot.subplots(figsize=(15,7))
im = ax.imshow(image)
ax.set_autoscale_on(False)

xmin,xmax = ax.get_xlim()
ymin,ymax = ax.get_ylim()

lat,lon = latlon(vessel)
xmap = ((lon + 180.) / 360.) * (xmax - xmin) + xmin
ymap = ((lat + 90.) / 180.) * (ymax - ymin) + ymin

pt = ax.plot(xmap,ymap, marker='o', color='cyan')