Change mode from companion computer

Hi everyone,

i was looking at the offboard_control example for px4-ROS2. In order to switch to Offboard mode the following instruction is used:

this->publish_vehicle_command(VehicleCommand::VEHICLE_CMD_DO_SET_MODE, 1, 6);

Now i’m struggling on how i can switch back to some mode, for example to HOLD_MODE in order to let the vehicle hovering after finishing the operation in offboard. In the VehicleCommand.msg i’ve read that the numeration follows the ENUM MAV_MODE but i don’t where to find this information.

Any help is appreciated,

Make sure you are sending the right spelling for each mode, see the below link for the standard naming

for example if you are using the mavros services to switch to mission mode

rosservice call /robot0/mavros/set_mode "base_mode: 0
custom_mode: 'AUTO.MISSION'"

I have developed a ROS2 node using MAVSDK to expose the basics of PX4 to do velocity based control from ROS2. Have a look at my code:

This node publishes a simple service to switch offboard mode. Depending on a parameter 1 or 0 the mode is either enabled or disabled. Look at linse 498-526.

I have never used PX4 ROS2 but will check it out.


Hi, Sorry for my second reply.

I now see what you mean. You are using Fast RTPS communication with PX4. Here is an example ROS1 node for that. Amongst other things, it does publish a service that you can call to switch to off board mode. Maybe this can help you.