0
$\begingroup$

Rosanswers logo

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-reuse-in-ros1-and-ros2/2262


Originally posted by rreignier on ROS Answers with karma: 544 on 2019-07-11

Post score: 0


Original comments

Comment by gvdhoorn on 2019-07-11:
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.

Comment by rreignier on 2019-07-11:
Thank you @gvdhoorn. Do you have an example of such library?

Comment by rreignier on 2019-07-11:
Ah, yes, I was looking for that special discussion but did not managed to find it :)

Comment by rreignier on 2019-07-11:
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?

Comment by gvdhoorn on 2019-07-11:
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).

Comment by rreignier on 2019-07-11:
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 in tesseract is it already in use?

Comment by gvdhoorn on 2019-07-11:
tesseract is undergoing extensive refactoring right now, so the publicly available code does not yet depend on the pure cmake version of opw_kinematics. It might already be available in ros-industrial-consortium/tesseract#72, but I'm not sure.

And the package.xml should contain <buildtool_depend>catkin</buildtool_depend> while it is different for ros 2 with ament.

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.

Comment by rreignier on 2019-07-11:
Ok for tesseract.

System dependencies do not need that necessarily.

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.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

With the help of @gvdhoorn I have managed to create a demo using a pure CMake library used by both a ROS 1 and a ROS 2 nodes.

https://github.com/romainreignier/share_ros1_ros2_lib_demo


Originally posted by rreignier with karma: 544 on 2019-07-11

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.