mavtester.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. '''
  3. test mavlink messages
  4. '''
  5. from __future__ import print_function
  6. from pymavlink import mavtest, mavutil
  7. from argparse import ArgumentParser
  8. parser = ArgumentParser(description=__doc__)
  9. parser.add_argument("--baudrate", type=int,
  10. help="master port baud rate", default=115200)
  11. parser.add_argument("--device", required=True, help="serial device")
  12. parser.add_argument("--source-system", dest='SOURCE_SYSTEM', type=int,
  13. default=255, help='MAVLink source system for this GCS')
  14. args = parser.parse_args()
  15. def wait_heartbeat(m):
  16. '''wait for a heartbeat so we know the target system IDs'''
  17. print("Waiting for APM heartbeat")
  18. msg = m.recv_match(type='HEARTBEAT', blocking=True)
  19. print("Heartbeat from APM (system %u component %u)" % (m.target_system, m.target_system))
  20. # create a mavlink serial instance
  21. master = mavutil.mavlink_connection(args.device, baud=args.baudrate, source_system=args.SOURCE_SYSTEM)
  22. # wait for the heartbeat msg to find the system ID
  23. wait_heartbeat(master)
  24. print("Sending all message types")
  25. mavtest.generate_outputs(master.mav)