Transmitter lost in SITL, but no failsafe while Python is running
If the failsafe doesn't trigger when the transmitter is cut in SITL and the drone hangs in LOITER, the cause may be the RC override packets Python sends. Set up the test like this.
You turn off the receiver in simulation to rehearse transmitter loss, but the drone doesn't return home. No failsafe warning appears in Mission Planner, and the drone hangs where it is. If a Python script is running at the same time, that script is most likely the cause.
Testing transmitter loss on a real drone can be an expensive mistake. That's why you rehearse it in ArduPilot's simulator, SITL. Set up the rehearsal correctly and the failsafe arrives within a second. Set it up wrong and it never arrives, while you think your settings are right.
What should happen when you cut the transmitter
The autopilot runs a timer whenever no new signal comes from the receiver. When the timer passes RC_FS_TIMEOUT (default 1 second), it shows Radio Failsafe and, depending on FS_THR_ENABLE, switches the drone to RTL or LAND. FS_THR_ENABLE defaults to 1, which means RTL.
In SITL, the way to silence the receiver is the SIM_RC_FAIL parameter. Set it to 1 and the receiver produces no signal at all. Set it to 2 and all channels go to center while throttle drops to 950 µs. Since this value is below FS_THR_VALUE (975), the failsafe still triggers.
How Python code hides the failsafe
The autopilot also counts an RC override packet from MAVLink as a live transmitter signal. Each packet resets the timer, even if the receiver has gone completely silent. If your code sends throttle via override several times a second, the timer never reaches one second.
The receiver goes silent at the same moment, but the failsafe comes only without override
Look at the bottom strip in the figure: the receiver is silent for 20 seconds, but as long as override packets keep coming, the drone waits in LOITER at 15 meters. The red RTL block starts 0.5 seconds after the packets stop. In the top strip there's no override, and the failsafe arrives at exactly 1.0 seconds.
What this looks like in the field: your code overrides throttle at 1500 to hold the drone in LOITER after takeoff, and meanwhile you rehearse transmitter loss. As long as the code runs, the autopilot never realizes the transmitter is gone.
Writing 0 into the override packet doesn't solve it either. The MAVLink spec defines 0 as "release the channel back to the receiver", but a packet with 0 also resets the timer. When the receiver goes silent, the autopilot keeps flying with the last value it saw from it. RC3 stays stuck at 1500 on screen.
Give throttle from the virtual receiver, not override
SITL's own receiver input is UDP port 5501. If you send channel values there, SIM_RC_FAIL really silences the receiver and the failsafe arrives as expected. The code below sets throttle to 1300 and checks that the autopilot reads this value from the receiver.
# Give the throttle from SITL's virtual receiver instead of RC override
import socket, struct, time
from pymavlink import mavutil
ALICI = ("127.0.0.1", 5501) # SITL's virtual receiver input
kanal = [1500, 1500, 1300, 1500, 1800, 1000, 1000, 1800]
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_RC_CHANNELS, 5, 1)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
son = None
bitis = time.time() + 3
while time.time() < bitis:
s.sendto(struct.pack("<8H", *kanal), ALICI) # 8 channels x 2 bytes, 50 Hz
son = m.recv_match(type="RC_CHANNELS", blocking=False) or son
time.sleep(0.02)
print("RC3 =", son.chan3_raw)When you run the code, you'll see this in the terminal:
RC3 = 1300The code connects to SITL over tcp:127.0.0.1:5760. If you started SITL with sim_vehicle.py, that port belongs to MAVProxy. Point the connection at its udp:127.0.0.1:14550 output instead. MAVProxy's rc 3 1500 command also writes to the same port 5501, so throttle you give with that command doesn't break the test either.
When you give throttle from the receiver and set SIM_RC_FAIL to 1, Radio Failsafe appears in the Messages tab 1.0 seconds later and the mode changes to RTL.
The same rule applies to a real drone
The code that runs the timer is in ArduCopter's radio.cpp file. SITL and the Pixhawk run the same code. If your companion computer keeps sending override, the autopilot may not notice even when the receiver drops out in the field.
Send override only when you need to give throttle or stick input, and close the loop when you're done. To move the drone autonomously, use position or velocity commands in GUIDED mode. These commands don't touch the transmitter timer.
Error Messages
Radio Failsafe
The autopilot received no transmitter signal for one second, or throttle dropped below FS_THR_VALUE. If FS_THR_ENABLE is 1, the drone switches to RTL. In a rehearsal, this is the line you want to see. If you don't see it, first stop the code that sends override.
Radio Failsafe Cleared
The signal is back. If your override interval is longer than one second, this line and Radio Failsafe come and go back to back. Send packets more often, or not at all.
PreArm: Radio failsafe on
The failsafe from the previous rehearsal is still active. Set SIM_RC_FAIL to 0, let the receiver signal come in, then arm.
PreArm: Throttle below failsafe
The throttle channel is below FS_THR_VALUE. If SIM_RC_FAIL was left at 2, throttle stays at 950 µs. Set the parameter back to 0.
Learn simulation from start to finish
To set up failsafe, geofence and wind rehearsals step by step in SITL, take a look at the AI and Drone Simulation course. Flying a camera drone in Gazebo, swarm simulation and steering the drone toward an object the camera finds are in the same course.
Virtual Machine Image for AI and Drone Simulation: a ready-made virtual machine with ArduPilot SITL, ROS Noetic and Gazebo 11 installed. You can start rehearsing without wrestling with setup.
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