Change Flight Mode using MAVSDK-Python

Hi. I’m designing a GUI to control my px4 using tkinter and mavsdk-python libraries
When i land my real px4 by my GUI, it doesn’t automatically change from LANDED MODE → HOLD MODE when it’s done. So if i want to takeoff again, the px4 denies to arm because it is LANDED MODE
I want to ask that how can i change flight mode using mavsdk-python like changing flight mode in QGC

As I know you can set only offboard mode by mavsdk - offboard.start().
If used MAVSDK C++, it have MavlinkPassthrough plugin, where you can send any command

mavsdk::MavlinkPassthrough::CommandLong commandLong;
commmandLong.command = MAV_CMD_DO_SET_MODE;
commandLong.param2 = Hold;
commandLong.target_compid = 0;
commandLong.target_sysid = 0;

In mavsdk-python I see that it have Action.hold() . May be it is what you looking for, don’t know I’m don’t use mavsdk-python.

Yes… I think it will be work:

async hold()
Send command to hold position (a.k.a. “Loiter”).
Sends a command to drone to change to Hold flight mode, causing the vehicle to stop and maintain its current GPS position and altitude.
Note: this command is specific to the PX4 Autopilot flight stack as it implies a change to a PX4-specific mode.”

Thank you so much!!!

1 Like