Can I mix ROS1 and ROS2 packages?
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?
Asked by mdeegan on 2020-02-09 18:56:05 UTC
Answers
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
Asked by Fetullah Atas on 2020-02-09 20:17:31 UTC
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.
Asked by MCornelis on 2020-02-10 10:24:25 UTC
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.
Asked by Dirk Thomas on 2020-02-10 12:05:56 UTC
Comments
Hi, you can use ros1_bridge
to 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=uPN2pDWK6hQ&ab_channel=TheConstruct
Asked by rodrigo55 on 2021-03-10 06:15:42 UTC
Comments
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
Asked by jayess on 2021-03-11 01:03:29 UTC
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.
Asked by MCornelis on 2020-02-10 09:35:56 UTC
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).
Asked by MCornelis on 2020-02-10 09:42:31 UTC