Sending MAVLINK Commands to Quadcopter

Hi, new to the community and running into some walls.

I have a x500 V2 quad from Holybro (Pixhawk 6X FC), using QGroundControl on a Macbook. Manual control works perfectly fine, and have had a blast planning and running missions from GCS. My current issue is sending commands from GCS (my laptop).

I’m using pymavlink and have had success LISTENING to some information, for example:

from pymavlink import mavutil

connection = mavutil.mavlink_connection('udp:localhost:14445')

connection.wait_heartbeat()

print("{system %u component %u}" % (connection.target_system, connection.target_component))

while 1:
    msg = connection.recv_match(type='ALTITUDE',blocking=True) #type='LOCAL_POSITION_NED'
    print(msg)

gives me the outputs:

{system 1 component 0} ALTITUDE {time_usec : 3247797525, altitude_monotonic : -0.6024488210678101, altitude_amsl : 31.877580642700195, altitude_local : 10.720012664794922, altitude_relative : -0.2820453643798828, altitude_terrain : nan, bottom_clearance : nan} ALTITUDE {time_usec : 3250194077, altitude_monotonic : -0.6288720369338989, altitude_amsl : 31.86186981201172, altitude_local : 10.704302787780762, altitude_relative : -0.29775524139404297, altitude_terrain : nan, bottom_clearance : nan} }

However, when I try to SEND any commands, such as arm, nothing happens:

connection.mav.command_long_send(connection.target_system, connection.target_component, mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)
arm_msg = connection.recv_match(type='COMMAND_ACK', blocking=True)
print(arm_msg)

program doesn’t move past wait_heartbeat():
{system 0 component 0}

the target_system value is also inconsistent, 0/1. Not sure how meaningful this is.

Any help would be greatly appreciated!

What are you actually trying to do? I can suggest to use MAVSDK as that’s generally tested with PX4, assuming you’re using PX4 and not ArduPilot.

The goal is to run a simple python script that, say, arms the drone, takes off to a given altitude, holds position for X time, and lands. Essentially, I’m trying to learn the basic building blocks of Mavlink commands that can be sent from GCS before buying a companion computer.

1 Like

I see. In that case I suggest to use MAVSDK, and play with offboard control, e.g. this example: