ROS2 Transition Strategy

I’ve been recently trying to rewrite a lot of ROS packages in a way that the same repo and branch works in both ROS1 and ROS2.

This is accomplished by conditionals in package.xml/CMakeLists.txt. Although you can use conditionals and have both ROS1 and ROS2 code live in the repo, I also wrote a library that allows you do use the same Python code for a ROS1 and ROS2 node:

An example of how it is used is my web-based visualization tool, ROSboard:

ROSboard can be cloned and used in either a catkin/ROS1 workspace OR a colcon/ROS2 workspace.

I’m also exploring creating a C++ analogue of the rospy2 library, i.e. roscpp2, that could allow the same C++ code to be used for ROS1 or ROS2.

Although I encourage people to move on to ROS2 way of doing things (rclcpp and rclpy) for new projects, I think such libraries like rospy2 (and maybe roscpp2 in the future) can be very helpful for things that specifically want to maintain compatibility with ROS1 and ROS2, e.g. hardware drivers, where the bulk of the logic is just a hardware interfacing logic and very little ROS logic, usually just a single publisher or single subscriber in many cases. In such cases it is extremely beneficial to not have to reproduce the hardware interfacing logic in multiple branches or repos and have to sync them every time you change something.

2 Likes