#!/usr/bin/env python import util, time, os, sys, math import socket, struct import select, errno from pymavlink import fgFDM def sim_send(m, a): '''send flight information to mavproxy and flightgear''' global fdm from math import degrees earth_rates = util.BodyRatesToEarthRates(a.dcm, a.gyro) (roll, pitch, yaw) = a.dcm.to_euler() fdm.set('latitude', a.latitude, units='degrees') fdm.set('longitude', a.longitude, units='degrees') fdm.set('altitude', a.altitude, units='meters') fdm.set('phi', roll, units='radians') fdm.set('theta', pitch, units='radians') fdm.set('psi', yaw, units='radians') fdm.set('phidot', earth_rates.x, units='rps') fdm.set('thetadot', earth_rates.y, units='rps') fdm.set('psidot', earth_rates.z, units='rps') fdm.set('vcas', math.sqrt(a.velocity.x*a.velocity.x + a.velocity.y*a.velocity.y), units='mps') fdm.set('v_north', a.velocity.x, units='mps') fdm.set('v_east', a.velocity.y, units='mps') # FG FDM protocol only supports 4 motors for display :( fdm.set('num_engines', 4) for i in range(4): fdm.set('rpm', 1000*m[i], idx=i) try: fg_out.send(fdm.pack()) except socket.error as e: if not e.errno in [ errno.ECONNREFUSED ]: raise timestamp = int((a.time_now - a.time_base) * 1e6) buf = struct.pack('