Installing Packages

Motivation

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.

Reference Example

apt-get usage

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!

  1. A certain message type exists which you want to use. The stable ROS package is called: nav_2d_msgs

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

  1. nav_2d_msgs (using apt-get)

  2. fake_ar_publisher (from git)

Scan-N-Plan Application: Guidance

Install Package from apt Repository

  1. Open a terminal window. Use the ros2 pkg command 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_msgs package is installed.

    • You should see an error message Package not found.

    • This package is not installed on the system, so we will install it.

  2. 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: ros-<distro>-<package>.

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

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

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

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

  1. Identify the source repository for the desired package:

    1. Go to github.

    2. Search for fake_ar_publisher.

    3. Click on this repository, and look to the right for the Code link, then copy the URL listed under Clone to the clipboard.

  2. 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 -b is important since repositories often contain multiple incompatible versions on different branches.

  3. Use ros2 pkg prefix to 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.bash file (either directly, or chained through your development workspace’s setup.bash).

    • Even after you’ve sourced the appropriate setup.bash file, the package is still not visible. Packages you download as source must first be built before they’re visible to ROS.

  4. Switch back to your “build terminal” and build the new package using colcon build

    • remember this command must be run from your workspace root (~/ros2_ws/)

  5. Once the build completes, explore the build and install directories to see what files were created.

  6. Switch back to your 2nd terminal and again use ros2 pkg prefix to 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.bash file 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).

  7. Re-run the source command to make the new package visible to ROS, then verify that ROS can see it using the ros2 pkg prefix command:

    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 prefix command.