ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Can I mix ROS1 and ROS2 packages?

asked 2020-02-09 17:56:05 -0500

mdeegan gravatar image

I am creating several ROS2 packages in my ROS2 workspace

~/ros2_ws/src/my_pkgs/
  - pkg1
  - pkg2

I am using Colcon as my build tool. Could I mix ROS1 and ROS2 packages if pkg2 was ROS2 with ament_cmake and pkg1 was ROS1 with catkin_cmake?

In particular, I am trying to use MIT Flight Goggles (ROS1) as a simulator with the control software written with ROS2. If not, can I create a launchfile which launches nodes from my ros2 workspace and ros1 workspace?

edit retag flag offensive close merge delete

Comments

You can simply use ROS1 packages together with ROS2 packages using the ros1_bridge. Make sure to source the ros1 environment first and then the ros2 environment to prevent issues from mixing environments. W.r.t. launchfiles, I think you can write your ROS2 launchfile in python in such a way that it calls your ROS1 launchfile.

MCornelis gravatar image MCornelis  ( 2020-02-10 08:35:56 -0500 )edit

The easiest way to get this working however is from 3 terminals.

Terminal 1: Source ROS1 environment roslaunch whatever you want

Terminal 2: Source ROS1 environment Source ROS2 environment run ros1_bridge

Terminal 3: Source ROS2 environment ros2 launch whatever you want

Once you have your system working like this you can start looking into some fancy python or bash magic or use systemd to get everything to start automatically.

I'm not sure if there are proper guidelines on how you should start a ROS1 + ROS2 hybrid system.

Alternatively, Port the ROS1 packages to ROS2 and make a full ROS2 system (might be easier depending on the amount of ROS1 packages you're dealing with).

MCornelis gravatar image MCornelis  ( 2020-02-10 08:42:31 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2020-02-10 11:05:56 -0500

Dirk Thomas gravatar image

Technically colcon doesn't mind from which ROS version a package is. From its point of view it only sees packages with a name and named dependencies and builds them in the order they need to be processed.

Practically this kind of mixing is more difficult. All packages in such mixed workspace share the same namespace. So if you have a ROS 1 and ROS 2 package with the same name the problem is that you can commonly only refer to one of them. E.g. if you want to import the C++ or Python code of a message the same package will likely exist in both ROS version and which ever is in the front of the search path will be found / used.

The ros1_bridge e.g. uses CMake to find ROS 2 packages as well as pkg-config to find ROS 1 packages to get around some of the limitation. But it is only possible to write a C++ program which talks to ROS 1 and ROS 2 at the same time because roscpp and rclcpp have different names / namespaces and no common dependencies.

Therefore I would suggest to limit the workspace mixing both ROS versions to a minimum and keep everything else you can in separate homogeneous workspaces, one for ROS 1, one for ROS 2, and the smallest possible for a mixture of packages which really need to access both ROS systems.

edit flag offensive delete link more
0

answered 2020-02-09 19:17:31 -0500

if your ROS1 package can be built with your build tool Colcon under ROS2 workspace then I don't see a reason for that not happening. If your ROS1 package have a lot of dependent packages from the same ROS distro (e.g Melodic) then it might cause you some trouble. You should keep in mind that, it is not possible to have running two packages under same workspace with different ROS distros, try to built ROS1 package under ROS2

edit flag offensive delete link more

Comments

I'm not sure I understand your answer. I am aware/heard/read somewhere, that you can write ROS packages in such a way that they can be compiled for both/either ROS1 and ROS2, but this is not trivial (Porting/Rewriting a ROS1 package for ROS2 to me sounds easier). Additionally, like you mention, If the package depends on other packages that are only available in ROS1 then you will run into issues (to my understanding you will also have to port these packages, right?).

I don't have a lot of experience in this area, so please correct me where I'm wrong. When I ported packages from ROS1 to ROS2 I had to update all the publish/subscribe/client/server API and edit my CMakeList.txt and Package.xml. Can you please clarify your answer or link some examples? I'm interested in learning more about this.

MCornelis gravatar image MCornelis  ( 2020-02-10 09:24:25 -0500 )edit
0

answered 2021-03-10 05:15:42 -0500

rodrigo55 gravatar image

Hi, you can use ros1_bridgeto communicate between ROS1 and ROS2 packages. Here's the link: https://github.com/ros2/ros1_bridge

If you need help in the step by step process, I made this video that can help: https://www.youtube.com/watch?v=uPN2p...

edit flag offensive delete link more

Comments

1

Can you please update your answer with main points from the video? If your video goes down or isn't available for certain regions then your answer/solution isn't as useful. Also, some prefer text to 12+ minute video

jayess gravatar image jayess  ( 2021-03-11 00:03:29 -0500 )edit

Question Tools

3 followers

Stats

Asked: 2020-02-09 17:56:05 -0500

Seen: 3,433 times

Last updated: Mar 10 '21