How to release a ROS 2 binary package [Part 1/3]

How to release a ROS 2 binary package [Part 1/3]

What we are going to learn

  1. How to create a new release repository
  2. How to create a new release team
  3. How to install the tools that you will use
  4. How to create a Personal Access Token on GitHub

List of resources used in this post

  1. Use the rosject: https://app.theconstructsim.com/l/4f2b155e/
  2. The Construct: https://app.theconstructsim.com/
  3. ROS 2 Documentation: https://docs.ros.org/en/humble/How-To-Guides/Releasing/Releasing-a-Package.html
  4. ROS2 basic Courses –▸
    1. ROS2 Basics in 5 Days (Python): https://app.theconstructsim.com/Course/73
    2. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/Course/61
    3. ROS2 Basics in 5 Days Galactic (C++): https://app.theconstructsim.com/Course/117

Overview

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.

This is the first post in a series of two posts.

The second post can be found at:

ROS Inside!

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:

ROS Inside logo

Acknowledgment

This post is based on ROS2’s official documentation, check it out here:

https://docs.ros.org/en/humble/How-To-Guides/Releasing/Releasing-a-Package.html

Opening the rosject

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

Learn ROS2 Parameters - Run rosject

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.

I’m going to create a release repository for https://github.com/rfzeg/wall_follower_ros2
To make your life easier, assuming you may not have a repository with the same name, you can start by forking the repository aforementioned.
After that, please go to https://github.com/new and create a repository. The package name can be wall_follower_ros2-release.

You can leave the repository Public, and hit the “Create repository” button.

Creating a release package on GitHub

Creating a release package on GitHub

Start a new release team

release team is a group of users within an organization who has permission to manage all release operations.

If a release team exists in your organization, you can join that team by completing the Update Release Team Membership issue template.

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

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

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

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.

 

sudo apt update

sudo apt install python3-bloom python3-catkin-pkg

 

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:

https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

Use the GIT access token to authenticate

Now that we have the Access Token, using the terminal, let’s create a folder named .config:

mkdir -pv ~/.config

 

Inside that folder, let’s create a file named boom:

cd ~/.config

touch bloom

 

Using the code editor, insert your GitHub username and PAT into it with the format shown below:

{ 
    "github_user": "<your-github-username>", 
    "oauth_token": "<token-you-created-for-bloom>" 
}

 

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:

How to install a ros2 binary package

How to install a ros2 binary package

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.

Create a new 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 Code Editor
Open a web shell

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.

user:/opt/ros/foxy/share$ ls -al | grep joint_state
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_broadcaster
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_controller
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_publisher
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_publisher_gui

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:

sudo apt update -y
sudo apt remove ros-foxy-joint-state-publisher-gui -y

Now verify that this GUI binary is no longer present.

user:/opt/ros/foxy/share$ ros2 pkg list | grep joint_state
joint_state_broadcaster
joint_state_controller
joint_state_publisher

Gone! Now we will install this package again.

sudo apt install ros-foxy-joint-state-publisher-gui -y

Before anything else, and this is probably what was missing for our friend who also installed the package successfully, SOURCE the ros2 distribution!

source /opt/ros/foxy/setup.bash

And that’s it! Installation complete. We are going to use the package now, but let’s check that it’s in the list of binaries.

user:/opt/ros/foxy/share$ ls -al | grep joint_state
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_broadcaster
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_controller
drwxr-xr-x  1 root root 4096 Sep 17  2021 joint_state_publisher
drwxr-xr-x  2 root root 4096 Oct 11 15:10 joint_state_publisher_gui

Step 4: Use the ros2 binary package

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!

Hello, I am Joint State GUI

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 How-to] ROS2 Topics vs Services vs Actions #5

[ROS2 How-to] ROS2 Topics vs Services vs Actions #5

What we are going to learn

  1. When to use Topics
  2. When to use Services
  3. When to use Actions

List of resources used in this post

  1. Use the rosject: https://app.theconstructsim.com/l/4dc71d42/
  2. The Construct: https://app.theconstructsim.com/
  3. ROS2 Courses –▸
    1. ROS2 Basics in 5 Days (Python): https://app.theconstructsim.com/#/Course/73
    2. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/#/Course/61
    3. ROS2 Navigation training: https://www.theconstruct.ai/ros2-navigation-training/

Overview

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

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:

ROS Inside logo

 

What is a ROS2 Action

Let’s assume you wish to wash your clothing. There are two possible ways you could go about it:

  1. Go to the Laundry service provider
    1. Put your clothes to wash.
    2. Wait until the clothes are washed.
    3. Get your clothes.
  2. If you have a washing machine at home:
    1. Put your clothes to wash
    2. Instead of waiting, you can do other things and leave the watching machine doing its jobs
    3. Check once in a while if the clothes are finished
    4. Do other things.
    5. 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 Parameters - Run rosject

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

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

ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.2, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" -1

 

The above command will command the robot to drive with a forward velocity of 0.2 m/s.

We can now create a subscriber to the /odom topic in a third terminal with the command below:

ros2 topic echo /odom

 

You should see odometry messages published to the /odom topic in the console

Many messages will start coming. You can stop the subscriber by pressing CTRL+C in the terminal where you launched it.

To stop the robot, we can use the command below in the second terminal:

ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" -1

 

When should you use a topic?

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:

ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}" -1

 

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:

ros2 action send_goal /turtlebot3_as t3_action_msg/action/Move "{secs: 20}"

 

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:

[ROS2 How-to] Install third-party Python packages using ROS2 #5

[ROS2 How-to] Install third-party Python packages using ROS2 #5

What we are going to learn

  1. How to use rosdep
  2. How to use apt and apt-get
  3. How to create a virtual environment and install packages inside

List of resources used in this post

  1. Use this rosject: https://app.theconstructsim.com/l/4fefbbab/
  2. The Construct: https://app.theconstructsim.com/
  3. ROS2 Guide: https://docs.ros.org/en/humble/How-To-Guides/Using-Python-Packages.html
    1. https://github.com/ros/rosdistro/blob/master/rosdep/base.yaml
    2. https://github.com/ros/rosdistro/blob/master/rosdep/python.yaml
  4. ROS2 Courses –▸
    1. ROS2 Basics in 5 Days (Python): https://app.theconstructsim.com/#/Course/73
    2. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/#/Course/61
    3. ROS2 Navigation training: https://www.theconstruct.ai/ros2-navigation-training/

Overview

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

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:

ROS Inside logo

 

Opening the rosject

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

Learn ROS2 Parameters - Run rosject

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

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

cd ~/ros2_ws/src

ros2 pkg create --build-type ament_python my_new_ros2_numpy_pkg --dependencies rclpy std_msgs geometry_msgs python3-numpy

In the command above, we created the my_new_ros2_numpy_pkg package that depends on rclpy, std_msgs geometry_msgs, and python3-numpy.

You can see the command by running the commands below:

cd ~/ros2_ws/src

ls

 

You can now see the content of the package.xml file of that package using the command below:

cat ~/ros2_ws/src/my_new_ros2_numpy_pkg/package.xml

 

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:

cd ~/ros2_ws/src

source ~/ros2_ws/install/setup.bash

sudo apt-get update

rosdep install --from-paths ~/ros2_ws/src --ignore-src -r -y

 

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

cd ~/ros2_ws/src

ros2 pkg create --build-type ament_python my_new_ros2_websockets_pkg --dependencies rclpy python3-websockets

 

Packages that can be installed with rosdep

The list of packages that can be installed using rosdep can be found in the following links:

    1. https://github.com/ros/rosdistro/blob/master/rosdep/base.yaml
    2. https://github.com/ros/rosdistro/blob/master/rosdep/python.yaml

 

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:

sudo apt-get install <package1> <package2> <package3>

 

Replace the <package> with your desired package name. Example:

sudo apt-get install -y python3-pandas

 

Sometimes, it may happen that apt or apt-get install will fail and you will get this error message:

Package 'python3-pandas' has no installation candidate

when this happens, usually, running sudo apt update before the apt install command can solve the issue:

sudo apt-get update

sudo apt-get install python3-pandas

 

Installing packages using pip and virtualenv

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 virtualenv is 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:

sudo apt update

sudo apt install python3-virtualenv

 

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:

How to pass ROS2 arguments to a ROS2 Node via the command line

How to pass ROS2 arguments to a ROS2 Node via the command line

What we are going to learn

  1. How to put a node inside a namespace
  2. How to remap a topic
  3. How to set a node parameter
  4. How to set the logger level

List of resources used in this post

  1. Use the rosject: https://app.theconstructsim.com/#/l/4e79d8dd/
  2. The Construct: https://app.theconstructsim.com/
  3. ROS2 Guide: https://docs.ros.org/en/humble/How-To-Guides/Node-arguments.html
  4. ROS2 Courses –▸
    1. ROS2 Basics in 5 Days (Python): https://app.theconstructsim.com/#/Course/73
    2. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/#/Course/61

Overview

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

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:

ROS Inside logo

 

Opening the rosject

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

Learn ROS2 Parameters - Run rosject

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

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

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:

/ObstacleAvoidance
/camera_driver
/gazebo
/robot_state_publisher
/turtlebot3_diff_drive
/turtlebot3_imu
/turtlebot3_joint_state
/turtlebot3_laserscan

 

Let’s take the chance and also check the list of ROS2 topics still in the third terminal:

ros2 topic list

We should have something like this:

/camera/camera_info
/camera/image_raw
/camera/image_raw/compressed
/camera/image_raw/compressedDepth
/camera/image_raw/theora
/clock
/cmd_vel
/imu
/joint_states
/odom
/parameter_events
/performance_metrics
/robot_description
/rosout
/scan
/tf
/tf_static

 

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-args parameter 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:

ros2 node list

The output must be something like this:

/camera_driver
/gazebo
/robot1/ObstacleAvoidance
/robot_state_publisher
/turtlebot3_diff_drive
/turtlebot3_imu
/turtlebot3_joint_state
/turtlebot3_laserscan

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:

ros2 topic list

 

We should have something similar to this:

/camera/camera_info
/camera/image_raw
/camera/image_raw/compressed
/camera/image_raw/compressedDepth
/camera/image_raw/theora
/clock
/cmd_vel
/imu
/joint_states
/odom
/parameter_events
/performance_metrics
/robot1/cmd_vel
/robot1/scan
/robot_description
/rosout
/scan
/tf
/tf_static

 

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:

...
/cmd_vel
...
/robot1/cmd_vel
/robot1/scan
...
/scan

 

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

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:

How to Replay ros2 bags with changed Quality of Service

How to Replay ros2 bags with changed Quality of Service

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.

Run rosject

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 Code Editor
Open a web shell

Open a web shell (1) and run the following commands to start a simulation:

export GAZEBO_RESOURCE_PATH=/home/user/ros2_ws/src/turtlebot/turtlebot3_simulations/turtlebot3_gazebo:${GAZEBO_RESOURCE_PATH}
export GAZEBO_MODEL_PATH=/home/user/ros2_ws/src/turtlebot/turtlebot3_simulations/turtlebot3_gazebo/models:${GAZEBO_MODEL_PATH}
export TURTLEBOT3_MODEL=waffle
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

You should see a simulation like this. If the robot does not show up, shutdown using Ctrl+C and run the above command again.

TurtleBot3 simulation
TurtleBot3 Simulation

Now make the robot move by publishing to the /cmd_vel topic, in another web shell (2). You should see the robot move.

ros2 topic pub --once /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.1, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.0}}"

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:

QoS profile:
  Reliability: RELIABLE
  Durability: VOLATILE
  Lifespan: 9223372036854775807 nanoseconds
  Deadline: 9223372036854775807 nanoseconds
  Liveliness: AUTOMATIC
  Liveliness lease duration: 9223372036854775807 nanoseconds

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

ros2 topic info /robot_pose --verbose

You should see something like we saw before:

QoS profile:
  Reliability: RELIABLE
  Durability: VOLATILE
  Lifespan: 9223372036854775807 nanoseconds
  Deadline: 9223372036854775807 nanoseconds
  Liveliness: AUTOMATIC
  Liveliness lease duration: 9223372036854775807 nanoseconds

Step 4: Change the Quality of Service profile for ros2 bag playback

Create a profile file for ros2 bag playback. In web shell (3):

touch override.yaml

Open override.yaml in the code editor and paste in the following content:

/robot_pose:
  history: keep_last
  depth: 10
  reliability: best_effort
  durability: volatile
  deadline:
    # unspecified/infinity
    sec: 0
    nsec: 0
  lifespan:
    # unspecified/infinity
    sec: 0
    nsec: 0
  liveliness: system_default
  liveliness_lease_duration:
    # unspecified/infinity
    sec: 0
    nsec: 0
  avoid_ros_namespace_conventions: false

Now go to web shell (2), stop the ros2 bag playback (if it’s still running), and run the following command instead:

ros2 bag play --qos-profile-overrides-path override.yaml ros2bag_qos_as_published 

Now, let’s see the quality of service of the /robot_pose topic. In web shell (3):

ros2 topic info /robot_pose --verbose

You should now see something similar to the following in the output:

QoS profile:
  Reliability: BEST_EFFORT
  Durability: VOLATILE
  Lifespan: 9223372036854775807 nanoseconds
  Deadline: 9223372036854775807 nanoseconds
  Liveliness: AUTOMATIC
  Liveliness lease duration: 9223372036854775807 nanoseconds

And that’s it! That’s how to replay ros2 bags with changed quality of service setting.

Step 5: Check your learning

  1. Do you understand how to set the QoS for the topic before recording a bag?
  2. 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.

Pin It on Pinterest