Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/autotest/pysim/fg_display.py
Views: 1799
#!/usr/bin/env python12import errno3import socket4import sys5import time67from pymavlink import fgFDM8910class udp_socket(object):11"""A UDP socket."""12def __init__(self, device, blocking=True, is_input=True):13a = device.split(':')14if len(a) != 2:15print("UDP ports must be specified as host:port")16sys.exit(1)17self.port = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)18if is_input:19self.port.bind((a[0], int(a[1])))20self.destination_addr = None21else:22self.destination_addr = (a[0], int(a[1]))23if not blocking:24self.port.setblocking(0)25self.last_address = None2627def recv(self, n=1000):28try:29data, self.last_address = self.port.recvfrom(n)30except socket.error as e:31if e.errno in [errno.EAGAIN, errno.EWOULDBLOCK]:32return ""33raise34return data3536def write(self, buf):37try:38if self.destination_addr:39self.port.sendto(buf, self.destination_addr)40else:41self.port.sendto(buf, self.last_addr)42except socket.error:43pass444546udp = udp_socket("127.0.0.1:5123")47fgout = udp_socket("127.0.0.1:5124", is_input=False)4849tlast = time.time()50count = 05152fg = fgFDM.fgFDM()5354while True:55udp_buffer = udp.recv(1000)56fg.parse(udp_buffer)57fgout.write(fg.pack())58count += 159if time.time() - tlast > 1.0:60print("%u FPS len=%u" % (count, len(udp_buffer)))61count = 062tlast = time.time()63print(fg.get('latitude', units='degrees'),64fg.get('longitude', units='degrees'),65fg.get('altitude', units='meters'),66fg.get('vcas', units='mps'))676869