Pixhawk rejects the takeoff command: check ARM and the mode first
If the takeoff command you send with Python is rejected, the drone won't take off. Check the ACK result, ARM, GUIDED mode and target altitude; working code is here too.
You send a takeoff command from Python, the code finishes without errors, and the drone stays put. The motors don't spin, and there's no error on screen.
The autopilot receives the command, runs it through a checklist, and rejects it if one of the checks fails. It tells you it rejected it with a reply, and most code never reads that reply.
Why the drone silently ignores the takeoff command
When ArduPilot receives a takeoff command, it checks four things: whether the motors are armed, whether the drone is on the ground, whether the selected mode supports takeoff, and whether the target altitude is higher than the current altitude. The first check that fails rejects the command.
In the reply to a rejected command the result field is 4, and in the reply to an accepted command it is 0. If the code doesn't look at this number, "I sent the command" and "the drone took off" get mixed up.
In the figure below, look at the order of the four checks and at how all of them lead to the same red band.
A takeoff command passes through four checks in order
Read as text
- takeoff command then are the motors armed?
- are the motors armed? then (yes) is the drone on the ground?
- is the drone on the ground? then (yes) does the mode support takeoff?
- does the mode support takeoff? then (yes: GUIDED, LOITER, POSHOLD, ZIGZAG) is the target altitude above the current one?
- is the target altitude above the current one? then (yes) result 0 drone climbs
- are the motors armed? then (no) result 4 · command rejected drone stays put, first failing check stops it
- is the drone on the ground? then (no) result 4 · command rejected drone stays put, first failing check stops it
- does the mode support takeoff? then (no) result 4 · command rejected drone stays put, first failing check stops it
- is the target altitude above the current one? then (no) result 4 · command rejected drone stays put, first failing check stops it
Which mode the takeoff command works in
Send the takeoff command in GUIDED mode. In the source code, LOITER, POSHOLD and ZIGZAG modes also pass the command's mode check. In STABILIZE mode the command is rejected, and for AUTO mode no takeoff support is defined in the source code.
In ALT_HOLD, FLOWHOLD and SPORT modes, the command is accepted only if the flag saying horizontal position isn't required is given in the third parameter. The default send doesn't have this flag, so the command is rejected in these three modes too.
The order is the one in the ArduCopter source code. The checks are defined in the takeoff.cpp file, and which modes support takeoff is defined in the has_user_takeoff function in mode.h.
Why you must send takeoff right after ARM
For a drone that is armed on the ground with zero throttle, ArduCopter by default disarms the motors itself after 10 seconds. The time is held in the DISARM_DELAY parameter, whose default is defined as 10 in config.h.
Write your code to send takeoff right after waiting for the ARM result. If user input or a long computation gets in between, the drone disarms before takeoff arrives and the command is rejected. Compare the two strips in the figure.
The time window between ARM and takeoff
Example: On the TEKNOFEST runway, your teammate at the ground station presses ARM, then waits for the referee's takeoff signal. If the signal comes later than 10 seconds, the drone has long since disarmed, and the reply to the takeoff command you send afterward says 4. Put ARM and takeoff in the same flow, and start both after the referee's signal.
Look at the reply first, then fix the code
The code below waits for a GPS 3D fix, switches the mode to GUIDED, retries until the drone is armed, sends the takeoff command and reads the result of the reply. If the result isn't 0, it raises an error, so a rejected command doesn't stay silent.
from pymavlink import mavutil
import time
mv = mavutil.mavlink
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,
mv.MAV_DATA_STREAM_ALL, 10, 1)
GUIDED = 4 # ArduCopter GUIDED mode number
def gps_bekle():
while True:
g = m.recv_match(type='GPS_RAW_INT', blocking=True, timeout=5)
if g and g.fix_type >= 3 and g.satellites_visible >= 6:
return
def mod_degistir(mod):
m.mav.command_long_send(m.target_system, m.target_component,
mv.MAV_CMD_DO_SET_MODE, 0, 1, mod, 0, 0, 0, 0, 0)
bitis = time.time() + 5
while time.time() < bitis:
h = m.recv_match(type='HEARTBEAT', blocking=True, timeout=1)
if h and h.custom_mode == mod:
return True
return False
def arm_et():
for deneme in range(10):
m.mav.command_long_send(m.target_system, m.target_component,
mv.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)
bitis = time.time() + 1.5
while time.time() < bitis:
h = m.recv_match(type='HEARTBEAT', blocking=True, timeout=0.5)
if h and h.base_mode & mv.MAV_MODE_FLAG_SAFETY_ARMED:
return True
return False
def takeoff(yukseklik):
m.mav.command_long_send(m.target_system, m.target_component,
mv.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, yukseklik)
ack = None
bitis = time.time() + 5
while time.time() < bitis:
a = m.recv_match(type='COMMAND_ACK', blocking=True, timeout=1)
if a and a.command == mv.MAV_CMD_NAV_TAKEOFF:
ack = a
break
if ack is None:
raise RuntimeError('no ACK received for takeoff')
if ack.result != mv.MAV_RESULT_ACCEPTED:
raise RuntimeError('takeoff reddedildi, sonuc=%d' % ack.result)
gps_bekle()
if not mod_degistir(GUIDED):
raise RuntimeError('could not switch to GUIDED mode')
if not arm_et():
raise RuntimeError('could not ARM')
takeoff(10)
while True:
p = m.recv_match(type='GLOBAL_POSITION_INT', blocking=True, timeout=5)
if p and p.relative_alt / 1000.0 >= 9.5:
print('altitude: %.1f m' % (p.relative_alt / 1000.0))
breakIf the command is rejected, the program stops with the error "takeoff reddedildi, sonuc=4". You get this result if you send takeoff to a drone that isn't armed, or to a drone armed in STABILIZE mode.
If you send the 10-meter command to a drone armed in GUIDED mode, the reply is 0, and once the drone passes 9.5 meters the program prints the altitude and exits. The climb time depends on the drone's mass and thrust; measure it from the log on your own drone.
When reading the reply, check the command number.
The reply to the ARM command comes over the same link. If the ack.command value isn't 22, that reply doesn't belong to takeoff.
Also check the ARM permission on the board
On a real Pixhawk, ARM permission depends on the GPS 3D fix, the satellite count and the EKF state. If ARM doesn't come, takeoff never gets its turn. Read the PreArm lines in Mission Planner's message window.
Error Messages
You may run into these lines in the console or in Mission Planner's message window.
Got COMMAND_ACK: NAV_TAKEOFF: FAILED
This is the line seen in the MAVProxy console, reported on the forum by a user. The autopilot rejected the takeoff command. Check ARM, the mode and the target altitude in order.
PreArm: Need Position Estimate
This line appears if the autopilot hasn't found a position estimate yet when the ARM command arrives. Wait until the GPS 3D fix arrives and the EKF starts using GPS, then try ARM again.
Auto: Missing Takeoff Cmd
This line appears when switching to AUTO mode if the motors are armed, the drone is on the ground and the mission's first command isn't takeoff; the text appears in mode_auto.cpp. Take off in GUIDED first, then switch to AUTO, or start the mission with a takeoff command.
If you want to see the decision chain line by line
We cover the order in which the source code eliminates the takeoff command, and the forum cases, as a lesson in the Drone Control with Python from Scratch course.
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