I can not understand VEHICLE_CMD_DO_SET_MODE

Hello, I am trying to understand the basic offboard example in px4_ros_com. I have manage to run it, but I can not understad why in offboard_control.py in engage_offboard_mode at 67 line, the command to switch in offboard mode is set as

            VehicleCommand.VEHICLE_CMD_DO_SET_MODE, param1=1.0, param2=6.0)
        self.get_logger().info("Switching to offboard mode")

I have found that inside the px4_custom_mode.h in the firmware offboard mode is defined as the following at line 137

	case vehicle_status_s::NAVIGATION_STATE_OFFBOARD:
		custom_mode.main_mode = PX4_CUSTOM_MAIN_MODE_OFFBOARD;

So why param1 is 1.0 instead of 0.0 if a custom_mode.sub_mode is not defined?

1 Like

Hi @Cristian-wp , param1 is used to set the base_mode variable, to sub_mode, see the actual implementation of VEHICLE_CMD_DO_SET_MODE:

You want base_mode=VEHICLE_MODE_FLAG_CUSTOM_MODE_ENABLED (1) in order to enter OFFBOARD:

Thank you @Benja it is more clear now.