ROS2, the improved version of ROS (ROS1), is quickly becoming the standard for developing robotics applications.
In this post, we will learn how to release a ROS2 package as a binary file. Binary files are pre-built executables. They are easier to install because they do not require building from the source code. Binary files are perfect if you want to easily distribute a package to other people.
You can easily install them with apt-get install PKG_NAME, or sudo dpkg -i pkg-name.deb, for example.
Before anything else, in case you want to use the logo above on your own robot, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to release a ROS 2 binary package, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/4f2b155e/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
How to release a ROS 2 binary package – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Assumptions
We assume you have a GitHub account. If you don’t have it yet, you can easily create it by following this link: https://github.com/signup
Creating a ‘release repository’
When a release process runs, it outputs files for instance .md and .yaml files. This output is known as release artifacts. In ROS2, these artifacts need to be stored in a separate repository from the source code files. This repository is what we call the release repository.
So, if your repository name is wall_follower_ros2, you have to create a new repository that you can call, for instance, wall_follower_ros2-release to be used as a release repository for your package.
The ROS2 release process will use that repository to store artifacts as the automated release process runs.
Here, we will assume that no release team exists for our package yet. To request a new release team to be created we must complete the New Release Team issue template.
This form will allow you to create a new release team and add the release repository to your new team in one go.
Below we have an example of the New Release Team issue filled:
Starting a new ros2 release team on GitHub
After creating the issue, you submit it and wait for the ROS2 team to take it into account.
Installing the tools required on your machine
In order to install the required tools, we need to have a terminal. If you are on The Construct, after having opened a rosject, let’s open a terminal:
Open a new Terminal
Let’s take the chance and also open the Code Editor to be easier to modify our files:
Open the IDE – Code Editor
Now, let’s go to the terminal and use apt to install bloom together with the python3-catkin-pkg modules.
The package should have been installed with no problems.
Let’s now move to the next step.
Creating a GIT access token to authenticate
Every time you interact with a remote Git repository on the command line (for example, doing a pull, or push operation), you are asked for your GitHub username and password. In this step, we create a Git Access Token to prevent Git from repeatedly prompting for your username and password during the release operation.
You can create an Access Token by clicking the “Generate new token” button in the link below:
When filling out the form, set Note to a descriptive name such as Bloom, set Expiration to No expiration, and select the public_repo and workflow checkboxes.
After clicking on Generate token the page will display a string like CTA2AK1UMAPKSJGSZDR8HWS3GVRAFIQYYETWELT4.
This string is the token, copy it to your clipboard. Make sure to store it safely since you can’t display the token again in the GitHub interface.
In case you need more information on personal access tokens, please follow the link below:
Since hidden files do not appear by default in the Code Editor, you have to click File Open in order to find the .config folder.
Please remember to save your ~/config/boom file by pressing CTRL+S (or File -> Save)
Congratulations. We are halfway through the release of a ROS2 Binary package. We hope this post was really helpful to you. The second post is coming soon. If you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
In this post, you will learn how to install a ros2 binary package and make it available for use. This post was written in response to this question on ROS Answers.
Step 1: Fire up a system with ROS2 installation
“Hey, do you mean I have to install ros2 first?” Absolutely not! Just login to The Construct to get access to virtual machines pre-installed with ROS.
Once logged in, click on My Rosjects, then Create a New Rosject, supply the information as shown in the video and click Create. Then RUN the rosject.
You might also want to try this on a local PC if you have ros2 installed. However, please note that we cannot support local PCs and you will have to fix any errors you run into on your own. The rest of the instruction assumes that you are working on The Construct; please adapt them to your local PC and ros2 installation.
Step 2: Check the ros2 binaries currently installed
Open a web shell and run the following commands. You should see a long list of many binaries!
cd /opt/ros/foxy/share/
ls -al
ROS binaries are stored in /opt/ros/{distro}/share/ If you would like to check if some binary is already installed without going through the long list, use grep. In this case we want to check binaries related to joint_state.
Heck, if you were the user in this post, you wouldn’t need to install anything. “What would I do then?!” Read on to find out!
Step 3: Install the ros2 binary package
We will demo this with the same package the user was struggling with: ros-foxy-joint-state-publisher-gui. Since the package is already installed in our case, we need to uninstall it first, just to demonstrate. Run the following on the current shell:
The user got an error when they tried to launch the GUI binary. Let’s see what we get (fingers crossed).
ros2 run joint_state_publisher_gui joint_state_publisher_gui
You should get a GUI like the image below pop up, confirming that the binary is really there. Cheers!
Step 5: Check your learning
Do you understand how to install a ros2 binary package and make it available for use? The magic word here is source.
If you didn’t get the point above, please go over the post again, more carefully this time.
(Extra) Step 6: Watch the video to understand how to install a ros2 binary package
Here you go:
Feedback
Did you like this post? Do you have any questions about how to install a ros2 binary package? 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 ROS2 topics, please let us know in the comments area and we will do a video or post about it.
ROS2, the improved version of ROS (ROS1), is quickly becoming the standard for developing robotics applications.
In this post, we will quickly compare the differences between three main ROS2 ways of interacting with nodes: topics, services, and actions.
We will have some insights on when to use each of them.
ROS Inside!
ROS inside
Before anything else, in case you want to use the logo above on your own robot, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
Let’s assume you wish to wash your clothing. There are two possible ways you could go about it:
Go to the Laundry service provider
Put your clothes to wash.
Wait until the clothes are washed.
Get your clothes.
If you have a washing machine at home:
Put your clothes to wash
Instead of waiting, you can do other things and leave the watching machine doing its jobs
Check once in a while if the clothes are finished
Do other things.
Clothes are washed.
Option 1 is a blocking activity because you have to wait (in theory not able to do anything else) for the clothes to be washed, while option 2 is non-blocking because you can do some other things while your clothes are being washed.
This non-blocking is what defines an Action. If ROS2 Services are for instant request-responses, an Action is a task that may take a lot of time to be finished, and in the meantime, a robot (or you) is free to do other things and is also able to constantly check the status of the action.
Opening the rosject
In order to understand ROS2 Topics, Services, and Actions, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/4dc71d42/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
Learn ROS2 Topics vs Service vs Action – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Launching the simulation
Let’s run a simulation before actually starting with the comparison between these three ways of interacting with ROS2 nodes.
Let’s start by opening a terminal:
Open a new Terminal
Now, in the first terminal that we just open, let’s setup our environment:
cd ~/ros2_ws
colcon build
After our workspace is compiled, let’s source it:
source install/setup.bash
Now, we can start our simulation with the following commands:
cd ~/ros2_ws/src/t3_galactic
./start_sim_house.sh
If everything went well, you should have a simulation running, similar to what we have in the image below:
[ROS2 How-to] #5 – ROS2 Topics vs Services vs Actions – Simulation
ROS2 Topics
Topics are the channel of communication between a Publisher node and a Subscriber node.
Let’s see an example of ROS2 Topics.
Let’s open a second terminal and run the following command:
Topics are used for one-way communication. The publisher just sends messages, and the subscriber just “listen” to the messages being published.
Topics are useful when you need to react quickly, and useful also if you want to publish updates at a high frequency, like the values of the /odom topic, used to determine the position of the robot.
You can use topics to change the speed of a robot, for example, to accelerate or reduce its speed.
We could say that it is mostly used for real-time communication.
Topics provide a continuous flow of data, and can be used for one-to-many and many-to-many communications, which means you can have many publishers publishing on a given topic, and many subscribers subscribed to a given topic.
ROS2 Services
ROS2 Services allow connections between a Service Client and a Service Server. It’s used basically for “instant questions and answers“, like “retrieving the current time“, for example, or “getting the current battery state” of the robot.
Let’s create a Service Server using the following commands in the second terminal:
ros2 run services_pkg service
Now that the service server is created, let’s create the Service Client in the third terminal, that sends a request to the Service Server:
ros2 service call /moving std_srvs/srv/Empty
If everything went well, the robot should have started moving in circles.
To stop the robot, we can make use of ROS2 Topic again, just like we did in the previous section, by running the command below:
If we want to make the robot move to its initial position (reset the simulation), we can call the following service:
ros2 service call /reset_simulation std_srvs/srv/Empty
You can also call a service to get the list of models in the gazebo world:
ros2 service call /get_model_list gazebo_msgs/srv/GetModelList "{}"
When should you use a ROS2 Service?
ROS2 Services could be used ideally when the number of data requests is really small, especially if compared with ROS2 Topics.
With ROS2 Services, you have a request and a response, so, it is useful for communication that happens quickly.
ROS2 Actions
Somehow similar to ROS2 Services, for ROS2 Actions we need a server and a client. In this case, it would be an Action Server node and the Action Client node.
ROS2 Actions are more indicated for situations where you give a task to the robot, and you are not going to be there waiting until the task has finished. You could do other things while the robot is doing his work. An example of an action would be: Robot, please clean the house. You just give it a task, you don’t know when the task is going to finish, but you can have constant feedback on how the task is going.
Let’s start an action server, by running the following command in the second terminal:
ros2 launch turtlebot3_as action_server.launch.py
Now, in the third terminal, let’s send the goal to the Action Service:
Now, the robot will be moving for 20 seconds, but the Client used to send the goal has finished “instantly”. The terminal does not have to be stuck for 20 seconds until the robot finishes its task.
When should you use ROS2 Actions?
The ideal scenario when ROS2 Actions could be used is when the task takes several seconds to complete or minutes to complete.
ROS Actions are used mainly for the processing of longer tasks in the background.
Use it also for operations that might me terminated or canceled before completion.
Congratulations. You have just learned when to use Topics, Services, and Actions. We hope this post was really helpful to you. If you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
Software usually builds on other software. When you are creating a ROS2 Package, for example, you have to specify the packages that the created package depends on.
In this post, we are going to talk about different methods that you can use to properly handle package dependencies in ROS2.
ROS Inside!
ROS inside
Before anything else, in case you want to use the logo above on your own robot or laptop, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to learn how to install third-party Python packages using ROS2, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject for that: https://app.theconstructsim.com/l/4fefbbab/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
Installing Third-Party Python packages in ROS2 – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Installing packages via rosdep
The rosdep command helps you install external dependencies in an OS-independent manner.
In order to use rosdep, we need a terminal. Let’s open one:
Open a new Terminal
Ok, in this rosject, we have already some packages. They were created with the following commands (you don’t need to run those commands since the package already exists):
After checking that file, let’s pay attention to the following line:
<depend>python3-numpy</depend>
Do you remember that we specific python3-numpy as a dependency of our package when we created it?
You can also add a new dependency to an existing package by manually editing the package.xml file.
All right, now that our package is created, let’s install its dependencies using rosdep. For that, let’s run the following commands in the first terminal:
The last command above installs all the packages that are not yet installed in our system and are required by the packages in your workspace.
If the message says no package was installed, that is because all dependencies are already installed in the system, but you should have seen at least the package python3-websockets installed.
That python3-websockets package is a dependency of our second package called my_new_ros2_websockets_pkg in our workspace, which was created using the following commands
Installing packages using a package manager (apt, apt-get)
We just learned how to install packages using rosdep. Another way of installing dependencies is by using a package manager directly. If you are using Linux Ubuntu, for example, you can use apt or apt-get, which are command-line tools that can be used to install and manage packages.
You can use the following command to list the packages installed with apt;
apt list --installed
The output would be something similar to the following:
...
xxd/jammy,now 2:8.2.3995-1ubuntu2 amd64 [installed,automatic]
xz-utils/jammy,now 5.2.5-2ubuntu1 amd64 [installed,automatic]
yaru-theme-gnome-shell/now 21.10.2 all [installed,upgradable to: 22.04.4]
yaru-theme-gtk/jammy,jammy,now 22.04.4 all [installed,automatic]
yaru-theme-icon/jammy,jammy,now 22.04.4 all [installed,automatic]
yaru-theme-sound/jammy,jammy,now 22.04.4 all [installed,automatic]
yelp-xsl/jammy,jammy,now 42.0-1 all [installed,automatic]
yelp/jammy,now 42.1-1 amd64 [installed,automatic]
zenity-common/jammy-updates,jammy-updates,now 3.42.1-0ubuntu1 all [installed,automatic]
zenity/jammy-updates,now 3.42.1-0ubuntu1 amd64 [installed,automatic]
zip/jammy,now 3.0-12build2 amd64 [installed,automatic]
zlib1g-dev/jammy,now 1:1.2.11.dfsg-2ubuntu9 amd64 [installed,automatic]
zlib1g/jammy,now 1:1.2.11.dfsg-2ubuntu9 amd64 [installed,automatic]
zstd/jammy,now 1.4.8+dfsg-3build1 amd64 [installed,automatic]
If you want to see if a given package named xml is installed, you would run the command below:
apt list --installed| grep libxml
which would should packages that contain the word xml:
libxml-parser-perl/jammy,now 2.46-3build1 amd64 [installed,automatic]
libxml-twig-perl/jammy,jammy,now 1:3.52-1 all [installed,automatic]
libxml-xpathengine-perl/jammy,jammy,now 0.14-1 all [installed,automatic]
libxml2/jammy-updates,jammy-security,now 2.9.13+dfsg-1ubuntu0.1 amd64 [installed,automatic]
libxmlb2/jammy,now 0.3.6-2build1 amd64 [installed,automatic]
Another way of finding installed packages is by calling dpkg directly.
sudo dpkg -l | grep xml
If you know the name of the package you wish to install, you can install it by using this syntax:
Instead of installing python dependencies system-wide, you can install them in a virtual environment, so that you can have different versions of a given package being used by different projects, yet they do not conflict. For that, we need to use virtualenv.
To check if virtualenvis installed, we can use the following command:
virtualenv --version
If you have an error like the following, it means virtualenv is not installed:
bash: virtualenv: command not found
In order to install virtualenv, we would use the following commands:
Once virtualenv is installed, we can create our virtual environment this way:
cd ~
mkdir -p ~/ros2_ws_venv/src
cd ~/ros2_ws_venv
virtualenv -p python3 ./venv
If everything went well, you should now have a python virtual environment in the ~/ros2_ws_venv folder.
You can now activate your environment with the following command:
source ./venv/bin/activate
After you activate the environment, your command prompt will change to show that you are in a Python virtual environment, so, instead of having user:~/ros2_ws_venv$ in your terminal, you would see something like this:
(venv) user:~/ros2_ws_venv$
Ignoring the venv folder (virtual environment) when compiling our ros2 workspace
In order to tell ROS2 not to consider our venv folder when compiling our workspace, we just create a file named COLCON_IGNORE in the folder that we want to ignore.
Example:
touch ~/ros2_ws_venv/venv/COLCON_IGNORE
All right. In the previous section we activated our environment with:
cd ~/ros2_ws_venv
source ./venv/bin/activate
Now, we can install Python packages in this environment just like we did before. Example:
python3 -m pip install torch
Now you can build your workspace and run your python node that depends on packages installed in your virtual environment.
Let’s compile our workspace:
cd ~/ros2_ws_venv
colcon build
Now your packages can use the Python packages installed in your virtual environment, just like if they were installed system-wide.
As long as your virtual environment is activated, you can install packages into that specific environment and you will be able to import and use those packages in your application.
Bear in mind that you always need to have the virtual environment activated when you want o use it.
To exit/deactivate the virtual environment, you can run the following command:
deactivate
Congratulations on reaching the end of this post. I hope it was useful for you. If you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
In this post we are going to show are ROS Arguments are, how to use them from the command line with the ros-args flag, and how they can modify some aspects of a ROS Node in a ROS Network.
ROS Inside!
ROS inside
Before anything else, in case you want to use the logo above on your own robot or laptop, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to learn how to pass ROS2 arguments to a ROS2 Node via the command line, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/#/l/4e79d8dd/
You can download the rosject to your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
ROS2 Arguments – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Launching the simulation
The rosject we provided contains the packages needed to run a simulation in ROS2. The ros2_ws (ROS2 Workspace) is already compiled. Let’s compile it again just in case. For that, let’s first open a terminal:
Open a new Terminal
Now, let’s compile the ros2_ws folder:
cd ~/ros2_ws
colcon build
Once the workspace is compiled, let’s source it.
source install/setup.bash
Now that the workspace is compiled and sourced, let’s start the simulation by running the following commands:
cd ~/ros2_ws/src/t3_humble
./start_sim_house.sh
The simulation should have been loaded, as we can see on the left side of the image below:
ROS2 –ros-args: Simulation launched
Starting a normal obstacle avoidance node (without –ros-args)
Now that we have the simulation running, let’s run the obstacle avoidance node. For that, let’s open a new terminal, let’s call it second terminal and type the following command on it:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance
Let’s now to go to a third terminal and list the ROS2 nodes there:
ros2 node list
The expected list of nodes should be similar to the following:
Starting the obstacle avoidance node in a specific namespace (using –ros-args)
Now that we saw how to launch a normal node in ROS2, let’s see how to launch it in a specific namespace. For that, we are going to use the–ros-argsparameter when running ros2 run.
Let’s go to the second terminal where we launched the node, and stop the node by pressing CTRL+C.
After the node has stopped, let’s launch it again in the /robot1 namespace.
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args -r __ns:=/robot1
If we now list the nodes again, just as we did before in the third terminal, we should see something different:
As we can see, now the ObstacleAvoidance node that we just launched is under the /robot1 namespace. The reason why the other nodes are not under a namespace is that those nodes were launched in the first terminal, where we launched the simulation.
We can also check the topics now, in order to find whether the Obstacle Avoidance-related topics are under the namespace. Let’s run the following command in the third terminal:
The important difference in the list of topics here are the cmd_vel and scan topics, which are now under the /robot1 namespace, yet, some topics with the same name without the namespace:
The topics under the /robot1 namespace are the ones that the Obstacle Avoidance node subscribes to. The topics without the namespace are watched by other nodes in the Gazebo Simulation, not by the Obstacle Avoidance.
Why have a namespace for ROS2 Nodes?
One of the reasons why Namespaces are useful is because this way, you can run the same node multiple times, once for each robot. This way, you will not have two robots processing the same messages, nor will you have to change your code to consider whether the code is running on robot1 or robot2, for example.
You can run multiple instances of a node with the same name, as long as they are in different namespaces.
Examples:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args -r __ns:=/robot1
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args -r __ns:=/robot2
Assigning a different name to a ROS2 Node using –ros-args
In order to change the name of a given ROS2 Node, we use the __node variable.
In order to run this example, please remember to kill the node that we launched in the second terminal by pressing CTRL+C.
Once the old node is terminated, we can launch it again with a different name using the following command:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args --remap __node:=collision_avoidance
The above command will cause the node to be started under the node collision_avoidance name.
Let’s check it by listing the nodes using the third terminal:
ros2 node list
You should now see the /collision_avoidance. instead of /obstacle_avoidance that we had before.
Changing topic names in ROS2 (Remapping)
Remapping means changing topics’ names.
So far we have learned how to add a namespace to a node, and how to change the node name. Time now has come to learn how to change the topic that a given node publishes or subscribes to.
Let’s go again to the second terminal , kill the node we launched earlier by pressing CTRL+C, then launch the node again using the command below:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args -r scan:=laser_scan
The command above will make the node subscribe to the topic named laser_scan instead of the default scan.
If you now check the topics again in the third terminal, you should see the /laser_scan topic, which is the one that the Obstacle Avoidance subscribes to:
ros2 topic list
Setting parameters directly from the command line when the node starts up
If you pay attention carefully, you will see that up to now we have been using the —ros-args –remap parameters. Now, in order to pass parameters to the node, we use –ros-args -pinstead.
In order to set the “safety_distance” parameter to 0.5, for example, we would use the following command in the second terminal:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args -p safety_distance:=0.5
To check of the parameter was set, we can start by listing the parameters in the third terminal:
ros2 param list
With the command above you will see that we have a node called ObstacleAvoidance and there is a parameter called safety_distance associated with the node.
We can check the value of the node with the following command:
ros2 param get ObstacleAvoidance safety_distance
After retrieving the value, you will see that it matches exactly with the value we set in the second terminal when we ran the node.
Setting Logger Level using –ros-args
Now we will see that we can control log severity levels printed out to the terminal, using the command line.
Let’s go again to our second terminal and kill the node we launched previously by pressing CTRL+C.
After the node has stopped, let’s run the following command:
ros2 run rule_based_obstacle_avoidance obstacle_avoidance --ros-args --log-level debug
The command above specifies that our logger level is DEBUG, which means we will see basically all log messages, given that DEBUG is the lowest level.
We set the level to debug, but you could also use info, warn or error, for example.
After having launched the node, you should have seen a lot of log messages coming out, logs that we didn’t have the previous times.
Using different parameters, you can control which logs you are going to see, without having to recompile your nodes, in case the nodes are in C++.
Congratulations on reaching the end of this post. We really hope it was of great use to you.
If case you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
In this post, you will learn how to replay ros2 bags with changed Quality of Service (QoS) setting. You’ll discover how to set the QoS before recording the bag, and how to change the QoS when playing back the bag file.
Step 1: Get a Copy of the ROS package containing the code used in the post
Click here to copy the project. It would be copied to your cloud account at The Construct. That done, open the project using the Run button. This might take a few moments, please be patient.
PS: If you don’t have an account on the The Construct, you would need to create one. Once you create an account or log in, you will be able to follow the steps to read and write parameters in ros1 and ros2.
You might also want to try this on a local PC if you have ROS installed. In that case you need to read on and duplicate the source code of the package in your own local workspace. However, please note that we cannot support local PCs and you will have to fix any errors you run into on your own.
Step 2: Start a simulation and the Quality of Service publisher
Open a web shell (1) and run the following commands to start a simulation:
Now start the QoS publisher in the same web shell (2) where you published to /cmd_vel. Note that we set the reliability to reliable. The QoS publisher publishes to the /robot_pose topic.
ros2 run qos_pose_publisher qos_pose_publisher -reliability reliable
Now let’s look at the reliability of the /robot_pose topic in a new web shell (3):
ros2 topic info /robot_pose --verbose
You should see something like this as part of the output:
Step 3: Record and play back a ros2 bag file of a topic
Now let’s record a ros2 bag file of a topic in web shell (3). We are using the /robot_pose topic.
ros2 bag record -o ros2bag_qos_as_published /robot_pose
Let it run for 5 seconds and then kill it, in web shell (3). You should have a new file created:
ros2bag_qos_as_published
Now let’s play the ros2 bag. But before that kill the qos_pose_publisher node in web shell (2) by pressing Ctrl+C. In the same web shell (2), run the following command:
ros2 bag play ros2bag_qos_as_published
Now let’s examine the QoS of the /robot_pose topic (now being published to from the ros2 bag), in web shell (3):
And that’s it! That’s how to replay ros2 bags with changed quality of service setting.
Step 5: Check your learning
Do you understand how to set the QoS for the topic before recording a bag?
Do you understand how to replay ros2 bags with changed quality of service setting?
If you didn’t get any of the points above, please go over the post again, more carefully this time.
(Extra) Step 6: Watch the video to understand how to create ros2 XML launch files
Here you go:
Feedback
Did you like this post? Do you have any questions about how to read and write parameters in ros1 and ros2? 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 in the comments area and we will do a video or post about it.