# Change mode from companion computer

**URL:** <https://discuss.px4.io/t/change-mode-from-companion-computer/26324>\
**Category:** PX4 Autopilot\
**Created:** [February 24, 2022, 5:36pm UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324 "2022-02-24T17:36:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![FedeUnibo](https://discuss.px4.io/user_avatar/discuss.px4.io/fedeunibo/32/8216_2.png) [@FedeUnibo](https://discuss.px4.io/u/FedeUnibo)\
**Post date:** [February 24, 2022, 5:36pm UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324/1 "2022-02-24T17:36:12Z")

</div>

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:

```auto
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,  
Thanks.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Elsafy](https://discuss.px4.io/user_avatar/discuss.px4.io/ahmed_elsafy/32/4093_2.png) [@Ahmed\_Elsafy](https://discuss.px4.io/u/Ahmed_Elsafy)\
**Post date:** [February 25, 2022, 3:01am UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324/2 "2022-02-25T03:01:33Z")

</div>

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

[http://docs.ros.org/en/api/mavros\_msgs/html/msg/State.html](http://docs.ros.org/en/api/mavros_msgs/html/msg/State.html)

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

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

```

---

<div class="post-metadata">

**Author:** ![eslaghuis](https://discuss.px4.io/user_avatar/discuss.px4.io/eslaghuis/32/8807_2.png) [@eslaghuis](https://discuss.px4.io/u/eslaghuis)\
**Post date:** [February 26, 2022, 5:22am UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324/3 "2022-02-26T05:22:31Z")

</div>

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: [https://github.com/slaghuis/drone\_mavsdk](https://github.com/slaghuis/drone_mavsdk)

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.

Eric

---

<div class="post-metadata">

**Author:** ![eslaghuis](https://discuss.px4.io/user_avatar/discuss.px4.io/eslaghuis/32/8807_2.png) [@eslaghuis](https://discuss.px4.io/u/eslaghuis)\
**Post date:** [February 26, 2022, 7:44am UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324/4 "2022-02-26T07:44:14Z")

</div>

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.

> **[GitHub - slaghuis/drone\_rtps: A ROS2 node that interfaces to PX4 using Fast...](https://github.com/slaghuis/drone_rtps)**
>
> A ROS2 node that interfaces to PX4 using Fast RTPS and published enough to get the navigation stack running. - GitHub - slaghuis/drone\_rtps: A ROS2 node that interfaces to PX4 using Fast RTPS and p...

---

<div class="post-metadata">

**Author:** ![slim71](https://discuss.px4.io/user_avatar/discuss.px4.io/slim71/32/13489_2.png) [@slim71](https://discuss.px4.io/u/slim71)\
**Post date:** [May 5, 2024, 7:48am UTC](https://discuss.px4.io/t/change-mode-from-companion-computer/26324/5 "2024-05-05T07:48:49Z")

</div>

Have you ever found a way to do this?
