I’m writing some Python code to communicate with my Pixhawk2, running ArduRover, and am running into a problem. Here’s my simple script, where I use pymavlink to listen for the APM hearbeat:
#!/usr/bin/env python from pymavlink import mavutil mavutil.set_dialect("ardupilotmega") master = mavutil.mavlink_connection("/dev/ttyTHS2", baud=921600) print "Waiting for heartbeat.." hb = master.wait_heartbeat() print "..got it" master.close()
This code works (as far as I can tell). It detects the heartbeat, and exits cleanly. However, if I use it, I cannot thereafter run mavros. If I do, it (the mavros process) exits with the following error:
[ INFO] [1522178284.642819047]: serial0: device: /dev/ttyTHS2 @ 921600 bps [ WARN] [1522178284.658598556]: FCU protocol: v2.0 [ INFO] [1522178284.658695100]: GCS URL: udp://@10.42.0.150 [ERROR] [1522178284.658787388]: serial0: receive: End of file [ INFO] [1522178284.659888124]: udp1: Bind address: 0.0.0.0:14555 [ INFO] [1522178284.660145915]: udp1: Remote address: 10.42.0.150:14550 terminate called after throwing an instance of 'std::system_error' what(): Resource deadlock avoided
This appears to me like the OS thinks the serial connection is still ‘owned’ by some object created in my Python script but the script has exited and all resources should be released. What’s going on here? How do I fix this?