UAV won't go to the first waypoint in AUTO mode
The mission looks uploaded from Mission Planner, but the UAV won't go to the first waypoint in AUTO mode. We explain why the upload silently ends up empty and how to fix it.
You uploaded the mission with Python code. The autopilot acknowledged it, and the code finished without errors.
Then you switch to AUTO and the vehicle goes nowhere. Or worse: it flies the mission from the previous flight.
Most of the time the cause is that the code trusts the wrong acknowledgment. Let's build the mission upload handshake step by step and see how to catch this trap.
Which command the incoming acknowledgment belongs to
In most sample code the flow goes like this: clear the old mission, tell the autopilot how many items are coming, then catch the first acknowledgment that arrives.
The command that clears the old mission has its own acknowledgment too. If you don't read it, your loop sees that acknowledgment before the autopilot has requested a single waypoint, reads "accepted", and exits saying "uploaded".
Look at the yellow strip in the figure: the first acknowledgment belongs to the clear command. The upload's acknowledgment only arrives after the autopilot has requested every item one by one. Those requests are the proof of the upload. An acknowledgment that arrives without any requests belongs to the previous command.
Two separate acknowledgments arrive during a mission upload
Try the code in SITL first
Before connecting the code to a board, you can try it on your computer with SITL. The commands below download ArduCopter SITL and start it at Şanlıurfa coordinates.
Leave it open in a separate terminal; the Python code will connect to it over TCP 5760.
mkdir -p ~/sitl && cd ~/sitl
curl -sL -o arducopter https://firmware.ardupilot.org/Copter/stable/SITL_x86_64_linux_gnu/arducopter
chmod +x arducopter
curl -sL -o copter.parm https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/autotest/default_params/copter.parm
pip install pymavlink
./arducopter -S -I0 --model + --speedup 5 --defaults copter.parm --sysid 1 --home 37.1591,38.7969,500,0The correct code
The code below gets three things right: it consumes the ACK of CLEAR_ALL, listens for both MISSION_REQUEST and MISSION_REQUEST_INT, and at the end checks the number of requested seqs.
import time
from pymavlink import mavutil
WPS = [(37.1600, 38.7969, 20.0), (37.1600, 38.7980, 20.0), (37.1591, 38.7980, 20.0)]
m = mavutil.mavlink_connection('tcp:127.0.0.1:5760')
m.wait_heartbeat()
m.mav.request_data_stream_send(m.target_system, m.target_component,
mavutil.mavlink.MAV_DATA_STREAM_ALL, 4, 1)
# Clear the old mission AND consume CLEAR_ALL's own ACK.
m.mav.mission_clear_all_send(m.target_system, m.target_component)
m.recv_match(type='MISSION_ACK', blocking=True, timeout=5)
def item(seq):
lat, lon, alt = (WPS[0][0], WPS[0][1], 0.0) if seq == 0 else WPS[seq - 1]
return m.mav.mission_item_int_encode(
m.target_system, m.target_component, seq,
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT,
mavutil.mavlink.MAV_CMD_NAV_WAYPOINT,
0, 1, 0, 3, 0, 0,
int(lat * 1e7), int(lon * 1e7), alt, 0)
# seq 0 is HOME: len(WPS) + 1 is sent.
m.mav.mission_count_send(m.target_system, m.target_component, len(WPS) + 1, 0)
ack, served = None, []
t0 = time.time()
while time.time() - t0 < 40:
msg = m.recv_match(type=['MISSION_REQUEST', 'MISSION_REQUEST_INT', 'MISSION_ACK'],
blocking=True, timeout=5)
if msg is None:
continue
if msg.get_type() == 'MISSION_ACK':
ack = msg
break
served.append(msg.seq)
m.mav.send(item(msg.seq))
print("Requested seq list :", served)
print("MISSION_ACK type :", ack.type if ack else None)
assert ack is not None and ack.type == 0, "No ACK or rejected"
assert len(served) == len(WPS) + 1, "Autopilot did not request every item -> mission incomplete!"
print("RESULT: mission uploaded and handshake confirmed.")What you see when it works correctly
When you run the code, you see this:
Requested seq list : [0, 1, 2, 3]
MISSION_ACK type : 0
RESULT: mission uploaded and handshake confirmed.Even though you send 3 waypoints, the requested seq list has 4 elements, because seq 0 is HOME and is included in the count. If you miss this, your last waypoint silently disappears.
What you see if you don't read the clear acknowledgment
Code that doesn't consume the acknowledgment of CLEAR_ALL and exits after catching the first MISSION_ACK produces output like this:
HEARTBEAT sys=1 comp=0
GPS OK fix=6 sat=10
ACK: MISSION_ACK {target_system : 255, target_component : 0, type : 0, mission_type : 0}
UPLOAD OK, served seq: []
Traceback (most recent call last):
File "mission_test.py", line 78, in <module>
print("READBACK count =", cnt.count)
AttributeError: 'NoneType' object has no attribute 'count'The served seq list is EMPTY. The autopilot didn't request a single item, yet there's a type=0 ACK on the screen. The code said "success", and there is no mission on the vehicle.
So MISSION_ACK alone is not proof of the upload. The proof is that the autopilot sent a MISSION_REQUEST for every seq.
Example: in a payload drop mission, you change the drop point at the last minute and upload the new route in the field. If the code sees the first acknowledgment and says "uploaded", the drone won't budge when you switch to AUTO, because there is no mission on the vehicle. Looking at the requested seq list the code prints catches this before you even switch to AUTO: if the list is empty, the new mission isn't on the vehicle.
Under competition conditions this code isn't enough
On the Fighting UAV field, this minimal code leaves some gaps open:
- No read-back: The autopilot giving an ACK doesn't mean the coordinates were written correctly. You need to read them back with MISSION_REQUEST_LIST and compare them in meters.
- No arrival confirmation in AUTO: Uploading a mission and flying it are separate things. You can't say "it went to the waypoint" without listening for MISSION_ITEM_REACHED.
- No telemetry loss scenario: On a real link, if a MISSION_REQUEST packet is dropped, the autopilot requests it again. Your code must be designed to resend it.
- Board-specific serial port differences: SERIALx_PROTOCOL and baud settings differ on Pixhawk TELEM2, Cube, and Matek boards. With the wrong setting, no MISSION_REQUEST arrives at all.
Error Messages
The first two lines come from the checks in the correct code; the third comes from the output of the code that falls into the trap. Which one you see tells you where the upload stopped.
AssertionError: Autopilot did not request every item -> mission incomplete!
The second check in the correct code fired: the acknowledgment arrived, but the number of requested seqs isn't the waypoint count + 1. The mission on the vehicle is incomplete or missing entirely. Look at the requested seq list.
AssertionError: ACK gelmedi ya da reddedildi
The first check in the correct code fired: no acknowledgment arrived within 40 seconds, or its type value isn't 0. Check the connection and the items sent.
AttributeError: 'NoneType' object has no attribute 'count'
In the output of the code that falls into the trap, this comes right after the empty seq list. The read-back request got no response, and the code tried to read the count field of an empty response. There is no mission on the vehicle.
For readers of this article
Mission upload, read-back, arrival confirmation in AUTO, and board-specific serial port settings are all covered step by step in the Drone Control with Python from Scratch course.
AI and Drone Simulation Virtual Machine: comes with ArduPilot SITL, ROS Noetic, and Gazebo 11 installed. You start simulating without any setup hassle.
Was this article helpful?
Learn this topic from start to finish
Season plan: all six courses for 9 months, ₺790 a month. ₺390 a month for high school and university students, ₺351 the first month with your member code. You can stop in any month you like. Start the Season plan · I'm a student