Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import krpc
- import time
- import math
- def main():
- # Connect to the server with the default settings
- # (IP address 127.0.0.1 and port 50000)
- print 'Connecting to server...'
- ksp = krpc.connect(name='Example script')
- print 'Connected to server, version', ksp.krpc.get_status().version
- vessel = ksp.space_center.active_vessel
- orbit = vessel.orbit
- control = vessel.control
- auto_pilot = vessel.auto_pilot
- flight = vessel.flight(ksp.space_center.ReferenceFrame.surface)
- resources = vessel.resources
- surface = ksp.space_center.ReferenceFrame.surface
- orbital = ksp.space_center.ReferenceFrame.orbital
- ## mass_lf = resources.
- # Set the throttle to 100% and enable SAS
- # Countdown...
- t1 = time.clock()
- control.activate_next_stage()
- # Activate the first stage
- print 'Launch!'
- auto_pilot.set_direction(flight.up_direction)
- control.throttle = 1
- time.sleep(6)
- auto_pilot.set_rotation(45, 0)
- time.sleep(4)
- control.throttle = 0
- count = 0
- print(flight.retrograde, type(flight.retrograde))
- auto_pilot.set_direction(flight.retrograde, 0, ksp.space_center.ReferenceFrame.surface)
- control.throttle = 1
- time.sleep(2)
- vspeed_curr = flight.vertical_speed
- while True:
- if count < 50:
- count += 1
- if count == 50:
- auto_pilot.set_direction(flight.up_direction, 0, referenceFrame = ksp.space_center.ReferenceFrame.surface)
- vspeed_prev = vspeed_curr
- vspeed_curr = flight.vertical_speed
- delta_vspeed = vspeed_prev - vspeed_prev
- if vspeed_curr > 0:
- control.throttle = 0
- if flight.true_altitude < 250:
- if vspeed_curr < -10 or delta_vspeed < 0 and control.throttle < 1:
- control.throttle += .2
- if vspeed_curr > -5 or delta_vspeed > 0 and control.throttle > 0:
- control.throttle -= .2
- if flight.true_altitude < 5:
- control.throttle = 0
- break
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement