Many of the coolest and most useful capabilities of ROS already exist somewhere in its community. Often, stable resources exist as easily downloadable debian packages. Alternately, some resources are less tested or more “cutting edge” and have not reached a stable release state; you can still access many of these resources by downloading them from their repository (usually housed on Github). Getting these git packages takes a few more steps than the debian packages. In this module we will access both types of packages and install them on our system.
Scan-N-Plan Application: Problem Statement¶
We have a good installation of ROS, and we have an idea of some packages that exist in ROS that we would like to use within our program. We have found a package which is stable and has a debian package we can download. We’ve also found a less stable git package that we are interested in. Go out into the ROS world and download these packages!
A certain message type exists which you want to use. The stable ROS package is called: nav_2d_msgs
You are using an AR tag, but for testing purposes you would like a node to publish similar info : fake_ar_publisher
Your goal is to have access to both of these packages’ resources within your package/workspace:
nav_2d_msgs (using apt-get)
fake_ar_publisher (from git)
Scan-N-Plan Application: Guidance¶
Install Package from apt Repository¶
Open a terminal window. Use the
ros2 pkgcommand to search for a package.
ros2 pkg --help ros2 pkg prefix nav_2d_msgs
If successful, this command prints the directory where ROS
nav_2d_msgspackage is installed.
You should see an error message Package not found.
This package is not installed on the system, so we will install it.
Use the APT package manager to try to install the package.
apt install ros-foxy-nav-2d-msgs
Note the naming convention for the APT package name:
ROS APT packages follow this naming pattern:
underscores (“_”) in the package name are replaced with dashes (“-“).
The program will say it cannot install the package, and suggests that we must run the program as root.
Try pressing the TAB key while typing the package name.
The system will try to automatically complete the package name, if possible.
Frequent use of the TAB key will help speed up entry of many typed commands and provide early detection of typing errors or environment-setup issues.
Install using sudo.
sudo apt install ros-foxy-nav-2d-msgs
Note the use of the sudo command to run a command with “root” (administrator) privileges.
Enter your password, and (if asked) confirm you wish to install the program.
Search for the package again.
ros2 pkg prefix nav_2d_msgs
Linux Tip: use the up/down arrow keys to scroll through previous command history, to avoid re-typing common commands.
This time, you will see a directory output of /opt/ros/foxy.
Remove the package from the system.
sudo apt remove ros-foxy-nav-2d-msgs
Don’t worry. We won’t be needing this package for any future exercises, so it’s safe to remove.
Download and Build a Package from Source¶
Identify the source repository for the desired package:
Go to github.
Search for fake_ar_publisher.
Click on this repository, and look to the right for the Code link, then copy the URL listed under Clone to the clipboard.
Open a new terminal and clone the fake_ar_publisher repository into the workspace’s src directory.
cd ~/ros2_ws/src git clone -b ros2 https://github.com/ros-industrial/fake_ar_publisher.git
Use Ctrl-Shift-V to paste within the terminal, or use your mouse to right-click and select paste
Git commands are outside of the scope of this class, but there are good tutorials available here
Specifying the correct branch name with the
-bis important since repositories often contain multiple incompatible versions on different branches.
ros2 pkg prefixto see if this package is visible from ROS:
ros2 pkg prefix fake_ar_publisher
You may see an error (“ros2: command not found”). Remember that none of the ROS commands are visible until you’ve sourced the base ROS distro
setup.bashfile (either directly, or chained through your development workspace’s
Even after you’ve sourced the appropriate
setup.bashfile, the package is still not visible. Packages you download as source must first be built before they’re visible to ROS.
Switch back to your “build terminal” and build the new package using
remember this command must be run from your workspace root (~/ros2_ws/)
Once the build completes, explore the build and install directories to see what files were created.
Switch back to your 2nd terminal and again use
ros2 pkg prefixto see if ROS can find the package.
This is a helpful command to troubleshoot problems with a ROS workspace. If this command can’t find your package, other nodes can’t either.
The package is still not visible to ROS. Even if you’ve previously sourced the
setup.bashfile in this terminal, you must re-source the setup file after adding new packages to the terminal. You don’t need to re-source the file after small changes (like recompiling code edits).
Re-run the source command to make the new package visible to ROS, then verify that ROS can see it using the
ros2 pkg prefixcommand:
source ~/ros2_ws/install/setup.bash ros2 pkg prefix fake_ar_publisher
remember to use TAB while typing. This can be an even quicker test than using the
ros2 pkg prefixcommand.