Home        Store        Learn        Blog

Using Pymavlink for a SITL flight with Gazebo and QGC (via PX4 autopilot)

Hey everyone.

I’m trying to run a basic gazebo simulation with Pymavlink and px4 autopilot. The intention is to make the drone send a heartbeat message, arm and take off. However right after arming, it just stays in one place for several seconds rather than take off at a particular defined altitude. The code looks fairly straightforward but I am new to the software side of Drone development so any help would be great.

from pymavlink import mavutil
import time
master = mavutil.mavlink_connection('udpin:localhost:14550')  
master.mav.command_long_send(master.target_system, master.target_component, mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 21196, 0, 0, 0, 0, 0)
master.mav.command_long_send(master.target_system, master.target_component, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 10)

Thanks in Advance

Hi @VighneshNKP, welcome to the forum :slight_smile:

This forum is focused on marine robotics - I expect you’re after the general ArduPilot forum, which is particularly relevant once you start getting into drone/aerial-specific functionality like automatically taking off to a particular altitude (ROVs/AUVs tend to chill at the water surface until you command them to go elsewhere, and we don’t tend to use the TAKEOFF command).

Note that master.wait_heartbeat() waits for a heartbeat from the vehicle. To send a HEARTBEAT message requires master.mav.heartbeat_send(...) :slight_smile: