How to share a library between ROS 1 and ROS 2?
Does anyone found a solution to share a C++ library (ROS agnostic) between ROS 1 and ROS 2?
There were some discussions about it but I did not found any clear solution. This use case should be more and more common while organizations are moving to ROS 2 but want to share some code as library in a single repo.
Previous discussion: https://discourse.ros.org/t/software-...
Within ROS-Industrial there was also a discussion about this (this one). The conclusion so far: make the "common" library a pure cmake package and treat it like a system dependency in both ROS 1 and ROS 2.
edit: You even participated in that discussion I just noticed.
Thank you @gvdhoorn. Do you have an example of such library?
Ah, yes, I was looking for that special discussion but did not managed to find it :)
I have browsed the ros-industriel github but did not found a repo hosting a library that could be used in both ROS 1 and ROS 2. Do you know if there is one somewhere?
I think a public example of this setup would be opw_kinematics as a shared dependency, with tesseract depending on that. The public version of all that is only ROS 1, but it's also being used in ROS 2 in the same way.
We've not completely made up our minds, but this is most likely the approach we'll take. Whether the two ROS versions will be hosted in a single repository (branches) or in separate repositories has not been decided yet.
Note btw that this idea (treat common functionality as system dependencies) is nothing new, and was (and is!) actually a recommended practice in ROS 1 as well. You just need to make sure to not "contaminate" your ROS-agnostic library with ROS datastructures (ie: using ROS msgs as generic data containers, etc).
Thanks you. I know that it is the recommended practice to make pure cmake packages but I have hardly seen it in ROS. And the
package.xml
should contain<buildtool_depend>catkin</buildtool_depend>
while it is different for ros 2 with ament.I have not found the use of
opw_kinematics
intesseract
is it already in use?tesseract
is undergoing extensive refactoring right now, so the publicly available code does not yet depend on the pure cmake version ofopw_kinematics
. It might already be available in ros-industrial-consortium/tesseract#72, but I'm not sure.That is only required if you want to build it as a package in a catkin/colcon workspace. System dependencies do not need that necessarily.
Ok for tesseract.
When you say System dependencies, you mean directly installed in /usr/lib or it still can be use in a workspace?
Following
opw_kinematics
example, I think I have managed to make such library. I need to test it further and will report.