Hello,
We encountered a strange problem just yesterday when attempting an automated flight using MAVSDK and Python from an onboard Raspberry Pi 4.
The rotors started slowly spinning for a few seconds and then stopped again. My Python logs showed the following error:
2024-02-06 15:01:37,554 - mavsdk.system - DEBUG - e[34m[02:58:03|Info ] e[0mWaiting to discover system on serial:///dev/serial0:921600… (connection_initiator.h:20)
2024-02-06 15:01:37,558 - mavsdk.system - DEBUG - e[32m[02:58:03|Debug] e[0mNew: System ID: 1 Comp ID: 1 (mavsdk_impl.cpp:482)
2024-02-06 15:01:37,561 - mavsdk.system - DEBUG - e[32m[02:58:03|Debug] e[0mComponent Autopilot (1) added. (system_impl.cpp:377)
2024-02-06 15:01:37,564 - mavsdk.system - DEBUG - e[33m[02:58:03|Warn ] e[0mVehicle type changed (new type: 14, old type: 0) (system_impl.cpp:225)
2024-02-06 15:01:37,567 - mavsdk.system - DEBUG - e[32m[02:58:03|Debug] e[0mDiscovered 1 component(s) (system_impl.cpp:578)
2024-02-06 15:01:37,578 - mavsdk.system - DEBUG - e[34m[02:58:03|Info ] e[0mSystem discovered (connection_initiator.h:63)
2024-02-06 15:01:37,580 - mavsdk.system - DEBUG - e[34m[02:58:04|Info ] e[0mServer started (grpc_server.cpp:53)
2024-02-06 15:01:37,581 - mavsdk.system - DEBUG - e[34m[02:58:04|Info ] e[0mServer set to listen on 0.0.0.0:50051 (grpc_server.cpp:54)
2024-02-06 15:01:37,583 - mavsdk.system - DEBUG - e[32m[02:58:06|Debug] e[0mUsing Gimbal Version 2 as gimbal manager information for gimbal device 0 was discovered (gimbal_impl.cpp:68)
2024-02-06 15:01:37,584 - mavsdk.system - DEBUG - e[32m[03:01:33|Debug] e[0mMAVLink: info: Armed by external command (system_impl.cpp:250)
2024-02-06 15:01:37,585 - mavsdk.system - DEBUG - e[32m[03:01:34|Debug] e[0mMAVLink: info: [logger] /fs/microsd/log/2024-02-06/16_01_33.ulg (system_impl.cpp:250)
2024-02-06 15:01:37,593 - root - ERROR - Traceback (most recent call last):
File “/home/pi/mission/cpa/utils/mission_runner.py”, line 257, in run_mission
await self.drone.handleAction(action)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 210, in handleAction
await self.handleAction_TakeOff(action)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 250, in handleAction_TakeOff
await self.drone.action.takeoff()
File “/home/pi/venv_mission/lib/python3.7/site-packages/mavsdk/action.py”, line 368, in takeoff
raise ActionError(result, “takeoff()”)
mavsdk.action.ActionError: COMMAND_DENIED: ‘Command Denied’; origin: takeoff(); params: ()2024-02-06 15:01:37,594 - root - ERROR - Error executing action Action : Takeoff to 0.0, 0.0, 7.77058333123739
2024-02-06 15:01:37,595 - root - INFO - Action : Return to launch.
2024-02-06 15:01:37,616 - root - ERROR - Traceback (most recent call last):
File “/home/pi/mission/cpa/utils/mission_runner.py”, line 257, in run_mission
await self.drone.handleAction(action)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 210, in handleAction
await self.handleAction_TakeOff(action)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 250, in handleAction_TakeOff
await self.drone.action.takeoff()
File “/home/pi/venv_mission/lib/python3.7/site-packages/mavsdk/action.py”, line 368, in takeoff
raise ActionError(result, “takeoff()”)
mavsdk.action.ActionError: COMMAND_DENIED: ‘Command Denied’; origin: takeoff(); params: ()During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/pi/mission/cpa/utils/mission_runner.py”, line 314, in run_mission
await self.drone.handleAction(rtlAct)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 216, in handleAction
await self.handleAction_ReturnToLaunch(action)
File “/home/pi/mission/cpa/drones/px4_drone.py”, line 529, in handleAction_ReturnToLaunch
await self.drone.action.return_to_launch()
File “/home/pi/venv_mission/lib/python3.7/site-packages/mavsdk/action.py”, line 505, in return_to_launch
raise ActionError(result, “return_to_launch()”)
mavsdk.action.ActionError: COMMAND_DENIED: ‘Command Denied’; origin: return_to_launch(); params: ()
A summary of the Python code used for takeoff (untested):
import asyncio
from mavsdk import System
from mavsdk.gimbal import GimbalMode, ControlMode
from mavsdk.offboard import (PositionNedYaw, OffboardError,
VelocityBodyYawspeed)
from pymavlink import mavutil
drone = System()
await drone.connect(system_address='serial:///dev/serial0:921600')
await drone.gimbal.take_control(ControlMode.PRIMARY)
await drone.gimbal.set_mode(GimbalMode.YAW_FOLLOW)
await drone.gimbal.set_pitch_and_yaw(0, 0)
async for health in drone.telemetry.health():
if health.is_global_position_ok:
logger.info("Established GPS lock...")
break
if await self.drone.offboard.is_active():
# We might be flying without remote.
# Explicitly set offboard mode for parameter COM_RCL_EXCEPT to work.
await drone.offboard.set_velocity_body(VelocityBodyYawspeed(0.0, 0.0, 0.0, 0.0))
await drone.offboard.start()
await drone.action.arm()
await drone.action.set_takeoff_altitude(aTargetAltitude)
await drone.action.takeoff()
This problem only shows up sporadically. We made several more attempts and were able to reproduce it one more time. However, since the drone is supposed to operate autonomously, this ‘sporadically’ is a real issue.
The Flight controller logs also show no apparent problems (at least to me): Flight controller log 1, Flight controller log 2
The remote was on and connected to the copter, but I can confidently say that I didn’t touch any controls by accident.
Thanks and best regards