ArduPilot says it switched to GUIDED: check the mode on screen
ArduPilot can accept a GUIDED command with an ACK, but that doesn't prove the mode changed. See what the ACK shows and how to verify the mode from HEARTBEAT here.
You send a command to switch to GUIDED mode with pymavlink, and the autopilot says “accepted” with an ACK, but in your code or ground station the mode still looks the same as before. You check your code line by line, and there seems to be no error. The problem isn't in the code; it's in what the ACK actually says.
Below, using the ArduCopter source code, you'll find the check that runs behind the ACK, when the ACK proves nothing, and how to tell whether the mode actually changed.
What the ACK actually accepts
Both the mode change command and the legacy mode message end up in the same function on the autopilot. This function actually tries to change the mode, and the ACK carries the result of that attempt: “accepted” if the attempt succeeded, “failed” if it didn't.
So the ACK carries the result of a real attempt, not just a check of the message format. But in one case the function returns without trying anything.
The same GUIDED request returns along four paths
Read the four rows in the figure from top to bottom; the autopilot checks the conditions in this order. It's not enough that the ACK arrives; look at which row the autopilot went through to produce it.
If you're already in that mode, the command proves nothing
The most critical detail is the first row in the figure. If the requested mode is the same as the vehicle's current mode, the function returns “success” straight away without running any checks.
If your code asks for GUIDED again while already in GUIDED, the ACK always comes back “accepted”. This says nothing about your GPS, your EKF or your position state.
Example: You switched the drone to GUIDED by hand from Mission Planner, then started the Python code. The code requests GUIDED, looks at the ACK and says "ready". But since the vehicle was already in that mode, this ACK came without running any checks, even if your GPS fix had degraded in the meantime. If the same code bases its decision on the mode in HEARTBEAT, you at least know what you're relying on.
The most common mistake: sending the command over and over in a loop because the mode didn't change. If you're already in that mode, every repeat looks “successful” and hides the real problem.
Base the decision on the mode the autopilot broadcasts, not on the ACK
The only reliable check is reading the mode field in the HEARTBEAT stream. Send the command and log the ACK, but don't base decisions on it. Confirm over several HEARTBEAT packets that the mode actually changed.
mode_id = master.mode_mapping()['GUIDED']
master.mav.command_long_send(
master.target_system, master.target_component,
mavutil.mavlink.MAV_CMD_DO_SET_MODE, 0,
mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, mode_id, 0, 0, 0, 0, 0)
ack = master.recv_match(type='COMMAND_ACK', blocking=True, timeout=5)
# Trust HEARTBEAT, not the ACK
for _ in range(20):
hb = master.recv_match(type='HEARTBEAT', blocking=True, timeout=1)
if hb and mavutil.mode_string_v10(hb) == 'GUIDED':
print('mode really changed')
breakAlso check in the field
In a case shared on the forum, when GUIDED is requested from LOITER, on some setups the drone switches to RTL because of a GCS failsafe. This is a separate behavior that depends on the hardware and telemetry setup; don't confuse it with the mode command itself.
Error Messages and Their Meanings
Mode change to GUIDED failed: requires position
GUIDED is one of the modes that require position control through requires_position(). If the autopilot can't get a valid absolute or relative position from the EKF, it rejects this mode while armed.
PreArm: GPS 1: Bad fix
This line isn't related to the mode change; it comes from a separate prearm check loop. When you request GUIDED while the GPS has no fix, you can see the two side by side in the message stream:
COMMAND_ACK {command : 176, result : 0, ...}
STATUSTEXT: PreArm: GPS 1: Bad fixThe ACK was accepted, yet the PreArm line keeps coming. Treating the two as the same error leads to the wrong diagnosis.
Mode change to GUIDED failed: GCS entry disabled (FLTMODE_GCSBLOCK)
The FLTMODE_GCSBLOCK parameter uses a bitmask to block entry into certain modes from the ground station. If you see this message, the problem isn't GPS or EKF; it's the value of this parameter.
Which course includes this topic
The course where we build mode changes, the ACK/HEARTBEAT distinction, and GUIDED/AUTO commands with pymavlink from start to finish: Drone Control with Python from Scratch.
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