# Convert the stretch\_docking code to ROS2

**URL:** https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301
**Category:** Ask
**Created:** [March 28, 2025, 11:50pm UTC](https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301 "2025-03-28T23:50:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tammerhaddad](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/tammerhaddad/32/964_2.png) [@tammerhaddad](https://forum.hello-robot.com/u/tammerhaddad)
#### Post date: [March 28, 2025, 11:50pm UTC](https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301/1 "2025-03-28T23:50:46Z")

</div>

Hi, I’m trying to set up [the docking station](https://hello-robot.com/stretch-docking-station) for the stretch, and I’m using the [github code](https://github.com/hello-robot/stretch_docking), which hasn’t been perfected but i got it mostly working. However, I need to incorporate it into my ROS2 framework.

Does anybody know of a codebase that has already done this, and if not, some advice for doing so? It’s basically just a couple python files, and I’m already going to pull in an aruco tag ros2 program that I can link to replace the current python one, but I still need to do the rest.

---

<div class="post-metadata">

### Author: ![bshah](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/bshah/32/55_2.png) [@bshah](https://forum.hello-robot.com/u/bshah)
#### Post date: [March 29, 2025, 1:20am UTC](https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301/2 "2025-03-29T01:20:16Z")

</div>

Hi @tammerhaddad, welcome to the Stretch forum! To my knowledge, I don’t think anyone has ported that code to ROS2. I’d actually recommend keeping (at least initially) the camera driver / Aruco detection code, and starting your port with replacing the robot drivers. The code currently uses Stretch Body, the Python API to the robot, and you’d be looking to replace this with the ROS2 API to the robot. Fortunately, all of the driver specific code is kept in one file: [normalized\_velocity\_control.py](https://github.com/hello-robot/stretch_docking/blob/main/normalized_velocity_control.py). The docking code only sends mobile base and head pan commands:

> <https://github.com/hello-robot/stretch_docking/blob/8eaf9dd589ac75677b95a81c2d69f647bbcb5994/docking_demo.py#L657-L663>

So in normalized\_velocity\_control.py, you’re looking to replace every instance of `robot.base.set_velocity()` with a Twist message published to the `/cmd_vel` topic.

> <https://github.com/hello-robot/stretch_docking/blob/8eaf9dd589ac75677b95a81c2d69f647bbcb5994/normalized_velocity_control.py#L53>

Similarly, replace `robot.head` commands with calls to the ROS2 follow joint trajectory action.

> <https://github.com/hello-robot/stretch_docking/blob/8eaf9dd589ac75677b95a81c2d69f647bbcb5994/normalized_velocity_control.py#L351-L352>

Hope this helps!

---

<div class="post-metadata">

### Author: ![tammerhaddad](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/tammerhaddad/32/964_2.png) [@tammerhaddad](https://forum.hello-robot.com/u/tammerhaddad)
#### Post date: [March 31, 2025, 4:08pm UTC](https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301/3 "2025-03-31T16:08:16Z")

</div>

Thanks for the warm welcome!  
I figured the movement portion would be the most difficult/first step, especially since I was planning on porting it from stretch\_body.robot to hello\_helpers hello\_misc, because I am running the stretch\_nav2 navigation driver as part of my launch, and so I run into a conflict if I dont. But publishing to cmd\_vel seems much better, so I’ll do that

When you say “keeping … the camera driver/ aruco detection code”, do you mean just putting them in a ros2 node? or co running them as a python file while i work on the drivers?  
or literally ignoring them and testing the drivers independently?

Thanks for the help!

---

<div class="post-metadata">

### Author: ![bshah](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.hello-robot.com/bshah/32/55_2.png) [@bshah](https://forum.hello-robot.com/u/bshah)
#### Post date: [March 31, 2025, 8:39pm UTC](https://forum.hello-robot.com/t/convert-the-stretch-docking-code-to-ros2/1301/4 "2025-03-31T20:39:31Z")

</div>

Nice, that makes sense!

> When you say “keeping … the camera driver/ aruco detection code”, do you mean just putting them in a ros2 node? or co running them as a python file while i work on the drivers?  
> or literally ignoring them and testing the drivers independently?

I mean co-running them as a Python file. In the ROS world, Stretch has the [Realsense ROS drivers](https://github.com/hello-robot/stretch_ros2/blob/humble/stretch_core/launch/d435i_high_resolution.launch.py) for the D435if head camera, and a [detect\_aruco\_markers](https://github.com/hello-robot/stretch_ros2/blob/humble/stretch_core/stretch_core/detect_aruco_markers.py) ROS2 node for ArUco detection. These are used by many programs in the ROS2 world, but not by Stretch Docking. Stretch Docking uses the Python library for the Realsense, and the Python library for `cv2.aruco`. So what I’m suggesting is sticking these Python versions while you port the robot drivers to the `/cmd_vel` topic and ROS2 action servers. Hopefully, this makes your life easier since you’re not porting everything all at once. And you shouldn’t run into any issues as you’re not using the Realsense ROS drivers. Then later, you can port the camera/aruco code to ROS2.
