The following MAVLINK commands to connect, arm and takeoff work fine in the SITL:
from pymavlink import mavutil
vehicle = mavutil.mavlink_connection(‘udpin:localhost:14551’)
vehicle.wait_heartbeat()
print(“Heartbeat from system (system %u component %u)” % (vehicle.target_system, vehicle.target_component))vehicle.mav.command_long_send(vehicle.target_system, vehicle.target_component, mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)
msg = vehicle.recv_match(type=‘COMMAND_ACK’, blocking=True)
print(msg)vehicle.mav.command_long_send(vehicle.target_system, vehicle.target_component, mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, 10)
msg = vehicle.recv_match(type=‘COMMAND_ACK’, blocking=True)
print(msg)
Separately, once airborne, the following goto command also works fine:
vehicle.mav.send(mavutil.mavlink.MAVLink_set_position_target_global_int_message(10, vehicle.target_system, vehicle.target_component, mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT, int(0b110111111000), int(-35.3628407 * 10 ** 7), int(149.1646910 * 10 ** 7), 10, 0, 0, 0, 0, 0, 0, 0, 0))
while 1:
msg = vehicle.recv_match( type=‘LOCAL_POSITION_NED’, blocking=True)
print(msg)
But attempts to the combine the above statements fail, with the vehicle arming, shows ‘takeoff accepted’, then disarms w/o gaining altitude. Why is this failing?