Failed to run example/takeoff_and_land

I am trying to integrate MAVSDK C++ with my self-developed flight control system (using MAVLink2). I want to handle all the messages and commands within my control system, including those that require a response.

Here’s my setup and process:

  • I’m using Ubuntu 22.04 and have downloaded MAVSDK v2.12.
  • The flight controller is connected to my laptop through TELEM2 (using a USB-to-Serial cable) to communicate with MAVSDK, while a Type-C cable connects the controller to QGC, which is running on the same laptop. I expect this setup allows me to monitor the status of my simulated drone controlled by MAVSDK.
  • The simulated drone runs on my flight controller and replicates real-world conditions, including GPS data, so it can be considered a real drone for practical purposes.

To bypass the issue of telemetry.health_is_ok() (as I haven’t yet found a solution to ensure all checks pass), I blocked it. Then, I used the command:
build/takeoff_and_land serial:///dev/ttyUSB0:115200
to verify if MAVSDK could send commands from arm to land and control my simulated drone.

In my control system, I printed all the messages (e.g., PING, HEARTBEAT, COMMAND_LONG) and commands (e.g., MAV_CMD_REQUEST_MESSAGE, HOME_POSITION, MAV_CMD_SET_MESSAGE_INTERVAL, MAV_CMD_REQUEST_AUTOPILOT_CAPABILITIES) sent by MAVSDK in the QGC console and ensured they were handled correctly.

The current issue is that, without any changes to the code, the outcome is inconsistent:

  • Sometimes the procedure completes successfully from arm to land,and I can see the procedure reflected in QGC correctly.
  • Sometimes the example script fails during the landing phase.
  • Other times, the script fails earlier in the process,giving the errors below:
steven@steven-ThinkBook-16-G6-IMH:~/FMT-Firmware/MAVSDK/examples/takeoff_and_land$ build/takeoff_and_land serial:///dev/ttyUSB0:115200
[01:43:18|Info ] MAVSDK version: v2.12.2-74-g3b779fbc (mavsdk_impl.cpp:28)
[01:43:18|Debug] New system ID: 1 Comp ID: 1 (mavsdk_impl.cpp:698)
[01:43:18|Debug] Component Autopilot (1) added. (system_impl.cpp:367)
[01:43:18|Warn ] Received ack for not-existing command: 511! Ignoring... (mavlink_command_sender.cpp:290)
[01:43:18|Warn ] Vehicle type changed (new type: 2, old type: 0) (system_impl.cpp:218)
[01:43:18|Debug] Discovered 1 component(s) (system_impl.cpp:510)
[01:43:18|Warn ] sending again after 0.00376601 s, retries to do: 3  (520). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.00374807 s, retries to do: 3  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.00375385 s, retries to do: 3  (512). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] Request was for msg ID: 242 (mavlink_command_sender.cpp:328)
[01:43:18|Warn ] sending again after 0.0140701 s, retries to do: 2  (520). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0139921 s, retries to do: 2  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0139968 s, retries to do: 2  (512). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] Request was for msg ID: 242 (mavlink_command_sender.cpp:328)
[01:43:18|Warn ] sending again after 0.0243097 s, retries to do: 1  (520). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0242412 s, retries to do: 1  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0242452 s, retries to do: 1  (512). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] Request was for msg ID: 242 (mavlink_command_sender.cpp:328)
[01:43:18|Error] Retrying failed for command: 520) (mavlink_command_sender.cpp:366)
[01:43:18|Error] Retrying failed for command: 511) (mavlink_command_sender.cpp:366)
[01:43:18|Error] Retrying failed for REQUEST_MESSAGE command for message: 242, to (1/1) (mavlink_command_sender.cpp:361)
[01:43:18|Warn ] sending again after 0.00431176 s, retries to do: 3  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0144665 s, retries to do: 2  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Warn ] sending again after 0.0246652 s, retries to do: 1  (511). (mavlink_command_sender.cpp:322)
[01:43:18|Error] Retrying failed for command: 511) (mavlink_command_sender.cpp:366)
Setting rate failed: Timeout

Has anyone else experienced something similar? I would be grateful for any advice or suggestions.