def load_mission_from_file(mavproxy, mav, filename): '''load a mission from a file''' global num_wp wploader = mavwp.MAVWPLoader() wploader.load(filename) num_wp = wploader.count() print("loaded mission with %u waypoints" % num_wp) return True
def main(): mission_path = None if len(sys.argv) > 1: mission_path = sys.argv[1] frame = '+' # If we were given a mission, use its first waypoint as home. if mission_path: wploader = mavwp.MAVWPLoader() wploader.load(mission_path) wp = wploader.wp(0) home = mavutil.location(wp.x, wp.y, wp.z, 0) run_mission(mission_path, frame, home)
def mavmission(logfile): '''extract mavlink mission''' mlog = mavutil.mavlink_connection(filename) wp = mavwp.MAVWPLoader() while True: if mlog.mavlink10(): m = mlog.recv_match(type='MISSION_ITEM') else: m = mlog.recv_match(type='WAYPOINT') if m is None: break wp.set(m, m.seq) wp.save(opts.output) print("Saved %u waypoints to %s" % (wp.count(), opts.output))
def wp_to_gpx(infilename, outfilename): '''convert a wp file to a GPX file''' wp = mavwp.MAVWPLoader() wp.load(infilename) outf = open(outfilename, mode='w') def process_wp(w, i): t = time.localtime(i) outf.write('''<wpt lat="%s" lon="%s"> <ele>%s</ele> <cmt>WP %u</cmt> </wpt> ''' % (w.x, w.y, w.z, i)) def add_header(): outf.write('''<?xml version="1.0" encoding="UTF-8"?> <gpx version="1.0" creator="pymavlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> ''') def add_footer(): outf.write(''' </gpx> ''') add_header() count = 0 for i in range(wp.count()): w = wp.wp(i) if w.frame == 3: w.z += wp.wp(0).z if w.command == 16: process_wp(w, i) count += 1 add_footer() print("Created %s with %u points" % (outfilename, count))
def mavflightview(filename): print("Loading %s ..." % filename) mlog = mavutil.mavlink_connection(filename) wp = mavwp.MAVWPLoader() if opts.mission is not None: wp.load(opts.mission) path = [] while True: m = mlog.recv_match(type=['MISSION_ITEM', 'GLOBAL_POSITION_INT']) if m is None: break if m.get_type() == 'GLOBAL_POSITION_INT' and mlog.check_condition( opts.condition): if opts.mode is not None and mlog.flightmode.lower( ) != opts.mode.lower(): continue lat = m.lat * 1.0e-7 lng = m.lon * 1.0e-7 if lat != 0 or lng != 0: if mlog.flightmode in colourmap: point = (lat, lng, colourmap[mlog.flightmode]) else: point = (lat, lng) path.append(point) if m.get_type() == 'MISSION_ITEM': wp.set(m, m.seq) if len(path) == 0: print("No points to plot") return bounds = mp_util.polygon_bounds(path) (lat, lon) = (bounds[0] + bounds[2], bounds[1]) (lat, lon) = mp_util.gps_newpos(lat, lon, -45, 50) ground_width = mp_util.gps_distance(lat, lon, lat - bounds[2], lon + bounds[3]) while (mp_util.gps_distance(lat, lon, bounds[0], bounds[1]) >= ground_width - 20 or mp_util.gps_distance( lat, lon, lat, bounds[1] + bounds[3]) >= ground_width - 20): ground_width += 10 path_obj = mp_slipmap.SlipPolygon('FlightPath', path, layer='FlightPath', linewidth=2, colour=(255, 0, 180)) mission = wp.polygon() if len(mission) > 1: mission_obj = mp_slipmap.SlipPolygon('Mission', wp.polygon(), layer='Mission', linewidth=2, colour=(255, 255, 255)) else: mission_obj = None if opts.imagefile: create_imagefile(opts.imagefile, (lat, lon), ground_width, path_obj, mission_obj) else: map = mp_slipmap.MPSlipMap(title=filename, service=opts.service, elevation=True, width=600, height=600, ground_width=ground_width, lat=lat, lon=lon) map.add_object(path_obj) if mission_obj is not None: map.add_object(mission_obj)
def mission_count(filename): '''load a mission from a file and return number of waypoints''' wploader = mavwp.MAVWPLoader() wploader.load(filename) num_wp = wploader.count() return num_wp