def main(): fg = FlightGear('localhost', 5500) # Wait five seconds for simulator to settle down while 1: if fg['/sim/time/elapsed-sec'] > 5: break time.sleep(1.0) print(fg['/sim/time/elapsed-sec']) heading = fg['/orientation/heading-deg'] # Switch to external view for for 'walk around'. fg.view_next() fg['/sim/current-view/goal-heading-offset-deg'] = 180.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 180.0) fg['/sim/current-view/goal-heading-offset-deg'] = 90.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 90.0) fg['/sim/current-view/goal-heading-offset-deg'] = 0.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 0.0) time.sleep(2.0) # Switch back to cockpit view fg.view_prev() time.sleep(2.0) # Flaps to take off position fg['/controls/flaps'] = 0.34 #fg.wait_for_prop_eq('/surface-positions/flap-pos-norm', 0.34) print(fg['/sim/position/altitude-agl-ft']) print('Initializing aircraft at desired Lat, Lon and Alt') fg['/sim/aircraft'] = 'Cessna 172P' fg['/position/longitude-deg'] = '-70.9993' fg['/position/latitude-deg'] = '42.3769' fg['/position/altitude-ft '] = '2200' fg['/devices/status/keyboard/event/key '] = '112' fg['/devices/status/keyboard/event/pressed '] = 'true' time.sleep(2.0) print('Aircraft Simulation initialized') print(fg['/sim/position/altitude-ft']) fg.quit()
def main(): fg = FlightGear('localhost', 5400) # Wait five seconds for simulator to settle down while True: if fg['/sim/time/elapsed-sec'] > 5.0: break time.sleep(5.0) print(fg['/sim/time/elapsed-sec']) # Switch to external view for for 'walk around'. # fg.view_next() while True: try: roll = fg['/orientation/roll-deg'] pitch = fg['/orientation/pitch-deg'] roll = roll + 90 pitch = pitch + 90 # Reserve start 0xFF for start byte r_num = int(roll + 1 if roll == 0xFF else roll) p_num = int(pitch + 1 if pitch == 0xFF else pitch) p_num = 180 - p_num # Invert Pitch r_lsb = chr(int(r_num & 0xFF)) r_msb = chr(int(r_num >> 8)) p_lsb = chr(int(p_num & 0xFF)) p_msb = chr(int(p_num >> 8)) ser.write(chr(0xFF)) ser.write(r_lsb) ser.write(r_msb) ser.write(p_lsb) ser.write(p_msb) print(ord(r_lsb), ord(r_msb), ord(p_lsb), ord(p_msb)) print(ser.readline()) except Exception as e: print(str(e)) fg.quit() ser.close()
def main(): fg = FlightGear('localhost', 5500) # Wait five seconds for simulator to settle down while 1: if fg['/sim/time/elapsed-sec'] > 5: break time.sleep(1.0) print(fg['/sim/time/elapsed-sec']) # parking brake on fg['/controls/parking-brake'] = 1 # heading = fg['/orientation/heading-deg'] # Switch to external view for for 'walk around'. fg.view_next() fg['/sim/current-view/goal-heading-offset-deg'] = 180.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 180.0) fg['/sim/current-view/goal-heading-offset-deg'] = 90.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 90.0) fg['/sim/current-view/goal-heading-offset-deg'] = 0.0 #fg.wait_for_prop_eq('/sim/current-view/heading-offset-deg', 0.0) time.sleep(2.0) # Switch back to cockpit view fg.view_prev() time.sleep(2.0) # Flaps to take off position fg['/controls/flaps'] = 0.34 #fg.wait_for_prop_eq('/surface-positions/flap-pos-norm', 0.34) fg.quit()