Drone disarms by itself (Python had armed it)
If the drone DISARMs on its own after you ARM it with Python, the DISARM_DELAY timer has run out. This article covers how the timer works and how to order your code.
You run the Python code, see the ARM line on screen, then nothing happens. The motors spin at idle for a few seconds and stop on their own.
When you send the takeoff command, the vehicle stays on the ground. At first glance it looks like a bug in your code, and when you run the same code a second time you get stuck at the same spot. Your code did ARM correctly; something else is undoing it.
There's a timer running inside the autopilot
While the vehicle waits armed, ArduPilot runs a timer. If the timer runs out while the vehicle is on the ground and the throttle is low, the autopilot DISARMs the motors itself.
The default duration is 10 seconds. The red line in the figure shows what happens to code that sits waiting for GPS after ARM: the timer reaches the limit and DISARM follows. On the blue line the takeoff command goes out right away, so the timer resets.
How the autopilot's timer fills up after ARM
When the timer resets
The decision runs from the top on every loop. If any of the following is true, the timer resets and no DISARM comes.
- If the motors are already DISARMED, or the duration parameter is set to zero
- If takeoff is requested, meaning the motors' target state is above idle
- If the throttle isn't low, or the vehicle isn't considered to be on the ground
- If the flight mode is THROW
If the interlock is off or the emergency stop is active, the duration is halved.
When flying with Python code, none of these happens after ARM. If you ARM and then sit waiting for GPS or computing a route, the vehicle stays on the ground with the throttle at zero, and the timer runs all the way out.
With the default setting, 10 seconds after ARM the Disarming motors line shows up in telemetry. The takeoff command you send after that doesn't lift the vehicle off the ground.
What you need to do
The fix is to correct the order: all preparation finishes before ARM. No waiting goes between ARM and the takeoff command.
import time
from pymavlink import mavutil
arac = mavutil.mavlink_connection("tcp:127.0.0.1:5760", source_system=255)
arac.wait_heartbeat(timeout=30)
arac.mav.request_data_stream_send(arac.target_system, arac.target_component,
mavutil.mavlink.MAV_DATA_STREAM_ALL, 10, 1)
# Preparation finishes BEFORE ARM. If you wait for GPS after ARM, the timer keeps running.
bitis = time.time() + 120
while time.time() < bitis:
g = arac.recv_match(type="GPS_RAW_INT", blocking=True, timeout=3)
if g and g.fix_type >= 3 and g.satellites_visible >= 6:
break
else:
raise SystemExit("GPS not ready")
arac.set_mode_apm("GUIDED")
time.sleep(2)
for deneme in range(5):
arac.mav.command_long_send(arac.target_system, arac.target_component,
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM,
0, 1, 0, 0, 0, 0, 0, 0)
son = time.time() + 8
while time.time() < son:
hb = arac.recv_match(type="HEARTBEAT", blocking=True, timeout=2)
if hb and (hb.base_mode & mavutil.mavlink.MAV_MODE_FLAG_SAFETY_ARMED):
break
else:
continue
break
else:
raise SystemExit("ARM failed")
# Nothing goes between ARM and the takeoff command.
arac.mav.command_long_send(arac.target_system, arac.target_component,
mavutil.mavlink.MAV_CMD_NAV_TAKEOFF,
0, 0, 0, 0, 0, 0, 0, 8.0)
# COMMAND_ACK doesn't confirm the result; watch the altitude.
bitis = time.time() + 60
while time.time() < bitis:
m = arac.recv_match(type=["GLOBAL_POSITION_INT", "HEARTBEAT"],
blocking=True, timeout=3)
if m is None:
continue
if m.get_type() == "HEARTBEAT":
if not (m.base_mode & mavutil.mavlink.MAV_MODE_FLAG_SAFETY_ARMED):
raise SystemExit("DISARMED, takeoff did not happen")
elif m.relative_alt / 1000.0 >= 7.6:
print("altitude: %.2f m" % (m.relative_alt / 1000.0))
breakThe timer's duration is stored in the DISARM_DELAY parameter, in seconds. Its default value in the source code is 10. Your board may have a different value; read it instead of assuming.
If a long preparation is unavoidable, you can increase DISARM_DELAY. That comes at a cost: a vehicle forgotten on the ground stays armed longer. Before increasing the duration, try moving the preparation earlier.
Example: Your code first ARMs, then waits for you to enter the coordinates of the payload drop point from the ground station. Until you type the coordinates, the vehicle sits on the ground at zero throttle; when the 10 seconds are up, Disarming motors appears in telemetry and the takeoff command that follows is wasted. If you move the coordinate entry before ARM, the takeoff command goes out right after ARM and the timer never runs out.
Error Messages and Their Meanings
Disarming motors
The line the autopilot prints when it DISARMs. On its own it doesn't mean a fault. If it came after ARM without you asking for it, it shows the timer ran out.
PreArm: Motor Interlock Enabled
This is a different case. The vehicle hasn't armed yet; the autopilot doesn't allow ARM while the interlock channel is in the on position. It has nothing to do with the timer.
PreArm: Safety Switch
The safety button on the board hasn't been pressed. Again, this is a pre-ARM block. If you see this message, the vehicle never armed in the first place.
What changes in the field
The timer itself lives in the firmware. If your transmitter is connected, the throttle stick position can reset the timer and the fault may never show up. Autonomous setups without a transmitter have no such rescue.
Where to go from here
The exact order of the decision chain in the firmware, the log signatures, and behavior that changes with the frame type are covered 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