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 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-eloquent-nav-2d-msgs
    
    • Note that dashes are used for the APT package name even though the ROS name uses underscores.
    • 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.
  3. Install using sudo.

    sudo apt install ros-eloquent-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
    
    • This time, you will see a directory output of /opt/ros/eloquent.
  5. Remove the package from the system.

    sudo apt remove ros-eloquent-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 Clone or Download, then copy to clipboard.
  2. 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. Build the new package using colcon build inside ~/ros2_ws/

  4. Once the build completes, the contents of the workspace have changed and the setup.bash file must be re-sourced in order to see the new package.

    • In the previous exercise, we added a line to our ~/.bashrc file to automatically re-source the setup files in each new terminal.

    • This is sufficient for most development activities, but you may sometimes need to re-execute the source command in your current terminal (e.g. when adding new packages):

      source ~/ros2_ws/install/setup.bash
      
  5. Once the build completes, explore the build and install directories to see what files were created.

  6. Use ros2 pkg to verify the new packages are visible to ROS.

    ros2 pkg prefix fake_ar_publisher
    
    • This is a helpful command to troubleshoot problems with a ROS workspace.
    • If ROS can’t find your package, try re-building the workspace and then re-sourcing the workspace’s setup.bash file.