This 14th of December of 2018, ROS2 Crystal Clemmyswas released officially. It’s a very important step due to the fact that it adds enough new functionality versus its prior older brother ROS2 Bouncy Bolson to be a real option to consider to make the jump from ROS to ROS2.
So here are some of my findings and facts about ROS2 versus ROS1. Just bear in mind that crystal is evolving really fast and it wouldn’t be a surprise that more improvements appear in the near future.
Use differences between ROS2 and ROS1
We will talk about ROS2 Crystal being the latest release. We will talk about the main basic differences in the way you use ROS2 versus ROS1:
Launch files using .xml format are gone. Forget what you knew about launching nodes and other launch files using the package structure. The system now relies upon python files launching binaries or python scripts. You will use the python module launch and package launch_ros. Here you have a basic example of how the binary tc_node from a package called the_construct_pkg would be launched now.
from launch import LaunchDescription import launch_ros.actions
Catkin_make is gone: Catkin has been replaced by colcon. This new building system is in essence a universal building system for the ROS ecosystem. This means that it can compile not only ROS2 packages, but packages from ROS1 or even packages without any manifest. This is really useful to compile non-ROS-Packages like Gazebo, which traditionally was something to compile separated from ROS. Its grammar is very similar to the good old catkin_make:
ROS Packages support exists but with some manual labor: ROS2 supports perfectly Cpp projects with the rclcpp. Python projects is another story. Although you can create rospackages that use python code with rclpy ros library in their scripts and rosrun those programs, the packages need to be configured manually for python use adding the ament_python export in the package xml. But that is defining the build type of the package and therefore, for the moment you won’t have easy mixing cpp and python code in the same package.
As for the main great features that ROS2 gives among others is the great capability of managing easily multiple robots and preliminary real-time programming support, features that are very welcomed by the community no doubt about that.
Can I use ROS2 completely forgetting ROS1? ROS1Bridge
The quick answer is: Yes but with drawbacks. So ROS2 Crystal has worked with the new GAzebo with ROS2 support, so you have access to creating your own simulations using only ROS2. You have access to the main ROS packages like tf, navigation, image_transport, rqt, and the big RVIZ. So it would seem that 90% of the current ROS users would be satisfied.
But the reality is that a huge amount of packages don’t come out of the bix working for ROS2 or are installed through debians. You will be obliged to compile them and probably make the modifications for ROS2 system. But there is an option which is using the ros1_bridge package.
This package allows you to run for example Gazebo simulations using ROS1, but communicate and control with ROS2 packages. It connects topics and services with the same message type and name. Crystal supports ros1bridge by default but only basic message types. If you want to use nonbasic message types, such as gazebo_ros_msgs you will have to compile ros1-bridge from source and in the same workspace have all the necessary messages you want to use with ROS2. Probably in the near future, it will support more message by default.
ROS2 Recommended?
Absolutely! It feels cleaner and faster for sure. And unless you need to use specific packages that don’t exist yet in ROS2 and are difficult to port, I would use it no doubt. Its obvious that ROS2 will become the main ROS on the long run and now its functional enough to do practically anything that you did with the good old ROS1. And you have the added bonus of all the improvements added to the mix. So my recommendation is to go there and have a try with ROS2.
If you are a previous ROS1 Developer:
You are bound to stumble upon some functionality that you were used to that now has no support or is buggy. But no doubt this is the future and is just like when rosbuild was removed back in the old days of ROS1. Just deal with the changes and you will see its worth the initial headaches. Here you have a migration ROS1 to ROS2 guide.
But I would highly recommend to for the next years until ROS2 gets total support, combine ROS1 and ROS2. Especially in simulations which are not yet ported to ROS2 because they tend to be the less updated and more critical to change. Just until more and more simulations get ROS2 versions.
If you are new in the ROS world:
You won’t notice most of the missing or buggy features that another person used to ROS1 would notice. You will undoubtedly have a headstart and ROS2 is not much more difficult to learn than ROS1, as far as the basics are concerned.
In this video we’re going to show how you can easily have ROS2 crystal running on your computer, in just a few steps, without the need of installing anything.
This video shows you how start running ROS 2 in your computer in a few seconds without having to install anything. You will also learn how to create a ROS 2 package and how to interact with a Gazebo simulation that runs on ROS 1, using the ros1_bridge
—
Feedback
—
Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it;)
—
Feedback
—
Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.
Use the ROS Development Studio (ROSDS), an online platform for developing for ROS within a PC browser. Easy-peasy. I’m using this option for this post.
Once you log in, click on the New ROSject button to create a project that will host your code. Then Click on Open ROSject to launch the development/simulation environment.
To open a “terminal” on ROSDS, pick the Shellapp from the Tools menu.
You can find the IDE app on the Tools menu.
You have ROS installed on a local PC. Okay, skip to Step 2.
Next step!
Step 2: Create a package with the code given in the post
1. If you are working on ROSDS, please create a ROSject first, as indicated in Step 1.
2. Open a terminal and create a package that holds the Python code:
user:~$ cd catkin_ws/src
user:~/catkin_ws/src$ catkin_create_pkg test_shutdown rospy
Created file test_shutdown/CMakeLists.txt
Created file test_shutdown/package.xml
Created folder test_shutdown/src
Successfully created files in /home/user/catkin_ws/src/test_shutdown. Please adjust the values in package.xml.
user:~/catkin_ws/src$ cd test_shutdown/src
user:~/catkin_ws/src/test_shutdown/src$ touch test_shutdown.py
user:~/catkin_ws/src/test_shutdown/src$ chmod +x test_shutdown.py
3. Open test_shutdown.py in the IDE and paste in the following code:
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
try:
talker()
except rospy.ROSInterruptException:
rospy.loginfo("TEST")
4. Compile and run the code: go back to the catkin_ws directory and run the following commands
(PS: Please run nohup roscore & to start ROS master in the background if you get an error that says “cannot connect to master”)
5. Stop the program with Ctrl + C:
Nothing happened? Yes, nothing happened like the OP explained. The OP expected that the word “TEST” would be printed, but it wasn’t. Let’s fix that next.
Step 3: Modify the code so that it triggers some actions when our ROS program ends
The key tool here is the rospy.on_shutdown() hook, which takes a function that should be called when ROS gets the shutdown signal.
Replace the code in test_shutdown.py with the following code that creates the shutdown hook function and registers it.
Now run the program again and then stop it with Ctrl + C:
user:~/catkin_ws$ rosrun test_shutdown test_shutdown.py
[INFO] [1586198566.464600]: hello world 1586198566.46
[INFO] [1586198566.564763]: hello world 1586198566.56
^C[INFO] [1586198568.326002]: It's shutdown time!
And that was it! Of course, the shutdown hook could perform more useful tasks, like stopping the robot for example.
Extra: Video of the post
Here below you have a “sights and sounds” version of this post, just in case you prefer it that way. Enjoy!
Feedback
Did you like this post? Do you have any questions about the explanations? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS or ROS2 topics, please let us know in the comments area and we will do a video or post about it.
About:
In the following video, we are going to explain, using a simple example with Summit XL robot, what are the main differences between the global costmap and the local costmap.
—
Feedback
—
Did you like this video? Do you have questions about what is explained? Whatever the case, please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS topics, please let us know on the comments area and we will do a video about it.