When I use pymavlink to send the MAV_CMD_NAV_WAYPOINT command to ArduPlane in SITL, Plane cannot receive this command(Although this command is clearly stated in the documentation to be used by Plane).
The result returned: Got COMMAND_ACK: NAV_WAYPOINT: UNSUPPORTED
And I tried other navigation commands: MAV_CMD_NAV_LOITER_TIME, MAV_CMD_NAV_LOITER_TURNS but they were unable to control Plane. What step did I miss?
My code is as follows:
import time
import sys
from pymavlink import mavutil, mavwp
def change_mode(modename, the_connection):
# Choose a mode and check whether the mode is available
mode = modename
if mode not in the_connection.mode_mapping():
print('Unknown mode : {}'.format(mode))
print('Try:', list(the_connection.mode_mapping().keys()))
exit(1)
# Get mode ID and set new mode
mode_id = the_connection.mode_mapping()[mode]
the_connection.mav.set_mode_send(
the_connection.target_system,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
mode_id)
def planeflyto(go_lat, go_lon, ref_alt, master):
master.mav.command_long_send(
master.target_system, # target_system
master.target_component, # target_component
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
0,
0, 5, 0, 0, go_lat, go_lon, ref_alt
)
msg = master.recv_match(type='COMMAND_ACK', blocking=True)
print(msg)
def main():
master = mavutil.mavlink_connection('udp:127.0.0.1:14550')
master.wait_heartbeat()
print("=============Takeoff started===============")
change_mode('GUIDED', master)
master.mav.command_long_send(master.target_system, master.target_component,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)
msg = master.recv_match(type='COMMAND_ACK', blocking=True)
print(msg)
change_mode('TAKEOFF', master)
time.sleep(15)
change_mode('GUIDED', master)
wp1 = [-353655751, 1491689962, 50]
print("fly to WP1")
planeflyto(wp1[0], wp1[1], wp1[2], master)