I am trying to control my drone that is using a pixhawk 6c from a Jetson Orin Nano using pymavlink.
I am using this code:
from pymavlink import mavutil
import time
connection = mavutil.mavlink_connection('tcp:127.0.0.1:5762')
connection.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (connection.target_system, connection.target_component))
# Request data streams
connection.mav.request_data_stream_send(
connection.target_system,
connection.target_component,
mavutil.mavlink.MAV_DATA_STREAM_ALL, # Request all streams
10, # Frequency in Hz
1 # Enable streaming
)
trigger = input("Press Enter to interrupt the mission: ")
if trigger == 'y':
print("Mission interrupted")
# Set the Drone to GUIDED mode
mode_id = connection.mode_mapping()['GUIDED']
connection.mav.set_mode_send(
connection.target_system,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
mode_id
)
msg = connection.recv_match(type='COMMAND_ACK', blocking=True)
print('Received Mode ACK: %s' % msg)
delay = 5
while delay > 0:
print("waiting")
time.sleep(1)
delay -= 1
# Set the Drone to AUTO mode
mode_id = connection.mode_mapping()['AUTO']
connection.mav.set_mode_send(
connection.target_system,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
mode_id
)
msg = connection.recv_match(type='COMMAND_ACK', blocking=True)
print('Received Mode ACK: %s' % msg)
I tested it in SITL first and then on my actual drone and in both instances, I could see the mode being switched to GUIDED on my MissionPlanner screen but I never got the COMMAND_ACK.
I created a seperate code that had the mode changing code 5 times and I got the ACK in that file. There is nothing different in this code besides the fact that the drone is in the air when the mode is changed.
Why am I not receiving COMMAND_ACK?