Advertisement
Guest User

kRPC code

a guest
May 8th, 2014
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. import krpc
  2. import time
  3. import math
  4.  
  5. def main():
  6.     # Connect to the server with the default settings
  7.     # (IP address 127.0.0.1 and port 50000)
  8.     print 'Connecting to server...'
  9.     ksp = krpc.connect(name='Example script')
  10.     print 'Connected to server, version', ksp.krpc.get_status().version
  11.  
  12.     vessel = ksp.space_center.active_vessel
  13.     orbit = vessel.orbit
  14.     control = vessel.control
  15.     auto_pilot = vessel.auto_pilot
  16.     flight = vessel.flight(ksp.space_center.ReferenceFrame.surface)
  17.     resources = vessel.resources
  18.     surface = ksp.space_center.ReferenceFrame.surface
  19.     orbital = ksp.space_center.ReferenceFrame.orbital
  20.  
  21. ##    mass_lf = resources.
  22.  
  23.     # Set the throttle to 100% and enable SAS
  24.  
  25.  
  26.     # Countdown...
  27.  
  28.  
  29.     t1 = time.clock()
  30.     control.activate_next_stage()
  31.     # Activate the first stage
  32.     print 'Launch!'
  33.     auto_pilot.set_direction(flight.up_direction)
  34.     control.throttle = 1
  35.     time.sleep(6)
  36.     auto_pilot.set_rotation(45, 0)
  37.     time.sleep(4)
  38.     control.throttle = 0
  39.     count = 0
  40.     print(flight.retrograde, type(flight.retrograde))
  41.     auto_pilot.set_direction(flight.retrograde, 0, ksp.space_center.ReferenceFrame.surface)
  42.     control.throttle = 1
  43.     time.sleep(2)
  44.     vspeed_curr = flight.vertical_speed
  45.     while True:
  46.         if count < 50:
  47.             count += 1
  48.         if count == 50:
  49.             auto_pilot.set_direction(flight.up_direction, 0, referenceFrame = ksp.space_center.ReferenceFrame.surface)
  50.         vspeed_prev = vspeed_curr
  51.         vspeed_curr = flight.vertical_speed
  52.         delta_vspeed = vspeed_prev - vspeed_prev
  53.         if vspeed_curr > 0:
  54.             control.throttle = 0
  55.         if flight.true_altitude < 250:
  56.             if vspeed_curr < -10 or delta_vspeed < 0 and control.throttle < 1:
  57.                 control.throttle += .2
  58.             if vspeed_curr > -5 or delta_vspeed > 0 and control.throttle > 0:
  59.                 control.throttle -= .2
  60.         if flight.true_altitude < 5:
  61.             control.throttle = 0
  62.             break
  63.  
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement