We built a MAVLink interface class for autonomous drone control and precision landing, wrapping PyMAVLink to handle communication over hardware serial (/dev/ttyAMA0 at 921600 baud).To prevent telemetry processing from slowing down our main vision loop, we moved incoming packet handling to a dedicated background daemon thread. We requested specific telemetry streams from the flight controller (LOCAL_POSITION_NED and DISTANCE_SENSOR at 10 Hz, HEARTBEAT at 2 Hz) using MAV_CMD_SET_MESSAGE_INTERVAL. To keep multi-threaded access clean, all reads and writes to state variables like armed, current_mode, local_position, and rangefinder_alt_m are protected with a threading lock.For vehicle execution, we implemented helper methods for mode switching, arming, and autonomous takeoff. The takeoff command switches to GUIDED mode, arms the vehicle, issues MAV_CMD_NAV_TAKEOFF, and blocks until the drone reaches 95% of the target altitude by monitoring local NED Z-coordinates.For the precision landing pipeline, we integrated VisionTracker with MAVLink’s landing_target_send using MAV_FRAME_BODY_NED. The main loop continuously feeds relative visual offset angles (angle_x, angle_y) to the flight controller at ~20 Hz. Before committing to a final landing, get_position_hold_feedback calculates 2D horizontal speed using the velocity vectors (v = \sqrt{v_x^2 + v_y^2}). Once horizontal speed drops below 0.15 m/s and local altitude drops under 1.0 meter, the controller automatically commands LAND mode for touchdown, finishing with thread cleanup on exit.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.