# I can not understand VEHICLE\_CMD\_DO\_SET\_MODE

**URL:** <https://discuss.px4.io/t/i-can-not-understand-vehicle-cmd-do-set-mode/35216>\
**Category:** PX4 Autopilot\
**Created:** [November 9, 2023, 2:40pm UTC](https://discuss.px4.io/t/i-can-not-understand-vehicle-cmd-do-set-mode/35216 "2023-11-09T14:40:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cristian-wp](https://discuss.px4.io/user_avatar/discuss.px4.io/cristian-wp/32/6403_2.png) [@Cristian-wp](https://discuss.px4.io/u/Cristian-wp)\
**Post date:** [November 9, 2023, 2:40pm UTC](https://discuss.px4.io/t/i-can-not-understand-vehicle-cmd-do-set-mode/35216/1 "2023-11-09T14:40:35Z")

</div>

Hello, I am trying to understand the basic offboard example in [px4\_ros\_com](https://github.com/PX4/px4_ros_com). I have manage to run it, but I can not understad why in [offboard\_control.py](https://github.com/PX4/px4_ros_com/blob/c4aa415509dbd5e24e48f1b0bb45fd1ce03a1cb9/src/examples/offboard_py/offboard_control.py) in engage\_offboard\_mode at [67](https://github.com/PX4/px4_ros_com/blob/c4aa415509dbd5e24e48f1b0bb45fd1ce03a1cb9/src/examples/offboard_py/offboard_control.py#L67) line, the command to switch in offboard mode is set as

```auto
   self.publish_vehicle_command(
            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](https://github.com/PX4/PX4-Autopilot/blob/1463f9dec85731dcbc366107c5789d8c3ddd55c9/src/modules/commander/px4_custom_mode.h) in the firmware offboard mode is defined as the following at line [137](https://github.com/PX4/PX4-Autopilot/blob/1463f9dec85731dcbc366107c5789d8c3ddd55c9/src/modules/commander/px4_custom_mode.h#L137C1-L139C9)

```auto
	case vehicle_status_s::NAVIGATION_STATE_OFFBOARD:
		custom_mode.main_mode = PX4_CUSTOM_MAIN_MODE_OFFBOARD;
		break;

```

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

---

<div class="post-metadata">

**Author:** ![Benja](https://discuss.px4.io/user_avatar/discuss.px4.io/benja/32/11872_2.png) [@Benja](https://discuss.px4.io/u/Benja)\
**Post date:** [November 11, 2023, 9:11pm UTC](https://discuss.px4.io/t/i-can-not-understand-vehicle-cmd-do-set-mode/35216/2 "2023-11-11T21:11:26Z")

</div>

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`:

> <https://github.com/PX4/PX4-Autopilot/blob/1592aedc1106589a31dc3643b38f0d78781c37b9/src/modules/commander/Commander.cpp#L759-L763>

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

> <https://github.com/PX4/PX4-Autopilot/blob/1592aedc1106589a31dc3643b38f0d78781c37b9/src/modules/commander/Commander.cpp#L767-L831>

---

<div class="post-metadata">

**Author:** ![Cristian-wp](https://discuss.px4.io/user_avatar/discuss.px4.io/cristian-wp/32/6403_2.png) [@Cristian-wp](https://discuss.px4.io/u/Cristian-wp)\
**Post date:** [November 13, 2023, 8:50am UTC](https://discuss.px4.io/t/i-can-not-understand-vehicle-cmd-do-set-mode/35216/3 "2023-11-13T08:50:18Z")

</div>

Thank you @Benja it is more clear now.
