mavmission.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. '''
  3. extract mavlink mission from log
  4. '''
  5. from __future__ import print_function
  6. from argparse import ArgumentParser
  7. parser = ArgumentParser(description=__doc__)
  8. parser.add_argument("--output", default='mission.txt', help="output file")
  9. parser.add_argument("logs", metavar="LOG", nargs="+")
  10. args = parser.parse_args()
  11. from pymavlink import mavutil, mavwp
  12. parms = {}
  13. def mavmission(logfile):
  14. '''extract mavlink mission'''
  15. mlog = mavutil.mavlink_connection(filename)
  16. wp = mavwp.MAVWPLoader()
  17. while True:
  18. m = mlog.recv_match(type=['MISSION_ITEM','CMD','WAYPOINT'])
  19. if m is None:
  20. break
  21. if m.get_type() == 'CMD':
  22. m = mavutil.mavlink.MAVLink_mission_item_message(0,
  23. 0,
  24. m.CNum,
  25. mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
  26. m.CId,
  27. 0, 1,
  28. m.Prm1, m.Prm2, m.Prm3, m.Prm4,
  29. m.Lat, m.Lng, m.Alt)
  30. if m.current >= 2:
  31. continue
  32. while m.seq > wp.count():
  33. print("Adding dummy WP %u" % wp.count())
  34. wp.set(m, wp.count())
  35. wp.set(m, m.seq)
  36. wp.save(args.output)
  37. print("Saved %u waypoints to %s" % (wp.count(), args.output))
  38. total = 0.0
  39. for filename in args.logs:
  40. mavmission(filename)