-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11f432d
commit bcafb48
Showing
1 changed file
with
16 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
#!/usr/bin/python3 | ||
""" | ||
Simple GUI example TODO: Docs | ||
Simple GUI example that prints the latitude and longitude of the aircraft | ||
""" | ||
import time | ||
import math | ||
from flightgear_python.fg_if import GuiConnection | ||
|
||
def gui_callback(gui_data, event_pipe): | ||
print(gui_data) | ||
return gui_data | ||
lat_deg = math.degrees(gui_data['lat_rad']) | ||
lon_deg = math.degrees(gui_data['lon_rad']) | ||
child_data = (lat_deg, lon_deg) | ||
event_pipe.child_send(child_data) | ||
|
||
""" | ||
Start FlightGear with `--native-gui=socket,out,30,localhost,5504,udp --native-gui=socket,in,30,localhost,5505,udp` | ||
""" | ||
if __name__ == '__main__': # NOTE: This is REQUIRED on Windows! | ||
gui_conn = GuiConnection(gui_version=8) | ||
ctrls_event_pipe = gui_conn.connect_rx('localhost', 5504, gui_callback) | ||
gui_conn.connect_tx('localhost', 5505) | ||
gui_conn.start() # Start the GUI RX/TX loop | ||
gui_event_pipe = gui_conn.connect_rx('localhost', 5504, gui_callback) | ||
# Note: I couldn't get FlightGear to do anything with the returned data on this interface | ||
# I think it's just ignoring everything. Technically you can send data back though. | ||
# gui_conn.connect_tx('localhost', 5505) | ||
gui_conn.start() # Start the GUI RX loop | ||
|
||
time.sleep(2) | ||
while True: | ||
# could also do `gui_conn.event_pipe.parent_send` so you just need to pass around `gui_conn` | ||
# ctrls_event_pipe.parent_send((gear_down_parent,)) # send tuple | ||
# gear_down_parent = not gear_down_parent # Flip gear state | ||
time.sleep(10) | ||
# could also do `gui_conn.event_pipe.parent_recv` so you just need to pass around `gui_conn` | ||
pipe_data = gui_event_pipe.parent_recv() # receive tuple | ||
lat_deg, lon_deg = pipe_data | ||
print(f'Lat: {lat_deg:.6f} Lon: {lon_deg:.6f}') | ||
time.sleep(0.01) |