Ask Your Question
0

How to share a library between ROS 1 and ROS 2?

asked 2019-07-11 03:28:49 -0500

rreignier gravatar image

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-...

edit retag flag offensive close merge delete

Comments

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.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-11 03:30:55 -0500 )edit

Thank you @gvdhoorn. Do you have an example of such library?

rreignier gravatar imagerreignier ( 2019-07-11 03:32:34 -0500 )edit

Ah, yes, I was looking for that special discussion but did not managed to find it :)

rreignier gravatar imagerreignier ( 2019-07-11 03:33:09 -0500 )edit

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?

rreignier gravatar imagerreignier ( 2019-07-11 03:44:35 -0500 )edit

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).

gvdhoorn gravatar imagegvdhoorn ( 2019-07-11 04:19:56 -0500 )edit

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?

rreignier gravatar imagerreignier ( 2019-07-11 05:23:02 -0500 )edit

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.

gvdhoorn gravatar imagegvdhoorn ( 2019-07-11 06:09:43 -0500 )edit

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.

rreignier gravatar imagerreignier ( 2019-07-11 06:17:32 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-07-11 07:28:40 -0500

rreignier gravatar image

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/sha...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-11 03:28:49 -0500

Seen: 23 times

Last updated: Jul 11