ROS: installation and shell tools

rosorg-logo1.png

This tutorial will walk you through the Robot Operating System (ROS) installation process and the shell tools provided with ROS. As a prerequisite, please make sure you understand Ubuntu repositories documented here. As this is targeted for Ubuntu 18.04 users, we will be installing the melodic version of ROS.

Installation

Set up your machine to accept ROS software, accept keys from Ubuntu’s keyserver, update your apt service AFTER you have accepted ROS software, and install the full desktop version of ROS:

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update

sudo apt install ros-melodic-desktop-full

If you don’t wish to install the full set of ROS packages you can install the non-full desktop:

sudo apt install ros-melodic-desktop

or the bare bones packages:

sudo apt install ros-melodic-ros-base

or you can even install package by package, though I wouldn’t recommend this for first time users:

sudo apt install ros-melodic-<PACKAGE-NAME>

to search by package:

apt search ros-melodic

Environment Setup

For convenience, it’s useful to redirect the output to your ~/.bashrc file (or your .zshrc file, or whatever shell you are using). Note the >> denotes output redirection in a Linux shell.

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc source ~/.bashrc

source ~/.bashrc'

If you are ever having problems finding or using your ROS packages make sure that you have your environment properly setup. A good way to check is to ensure that environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set:

printenv | grep ROS

If they are not then you might need to source some setup.*sh files.

Note: sometimes you need to log out and back in again for environment changes to take effect.

ROS Dependencies

You’re going to want the build-essential apt package if you don’t have it already:

sudo apt install build-essential

Tip: To run ROS with Python you are going to want:

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool

Now initialize rosdep:

sudo apt install python-rosdep

sudo rosdep init

rosdep update

Create a ROS Workspace

Photo by Tim Mossholder on Unsplash

Let's create and build a catkin workspace:

mkdir -p ~/catkin_ws/src

cd ~/catkin_ws/ catkin_make

NOTE: Python 3 users in ROS Melodic and earlier: note, if you are building ROS from source to achieve Python 3 compatibility, and have setup your system appropriately (ie: have the Python 3 versions of all the required ROS Python packages installed, such as catkin) the first catkin_make command in a clean catkin workspace must be:

catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3

This will configure catkin_make with Python 3. You may then proceed to use just catkin_make for subsequent builds.

Note to the NOTE:

sudo apt install ros-melodic-catkin-pip ros-melodic-catkin-virtualenv

The catkin_make command is a convenience tool for working with catkin workspaces. Running it the first time in your workspace, it will create a CMakeLists.txt link in your 'src' folder.

If you look in your current directory you should now have a 'build' and 'devel' folder. Inside the 'devel' folder you can see that there are now several setup.*sh files. Sourcing any of these files will overlay this workspace on top of your environment. To understand more about this see the general catkin documentation: catkin. Before continuing source your new setup.*sh file:

source devel/setup.bash

To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you're in.

echo $ROS_PACKAGE_PATH

/home/<youruser>/catkin_ws/src:/opt/ros/<your_ros_distro>/share

The ROS Filesystem

Tip: if you prefer to you can just use the normal filesystem tools for Linux, though things like packages will be easier to use within the ROS filesystem.

For this tutorial we will inspect a package in ros-tutorials, please install it using

sudo apt-get install ros-<distro>-ros-tutorials

Replace '<distro>' (including the '<>') with the name of your ROS distribution (e.g. indigo, kinetic, lunar, melodic, etc.)

Packages: Packages are the software organization unit of ROS code. Each package can contain libraries, executables, scripts, or other artifacts.

Manifests (package.xml): A manifest is a description of a package. It serves to define dependencies between packages and to capture meta information about the package like version, maintainer, license, etc.

rospack allows you to get information about packages. In this tutorial, we are only going to cover the find option, which returns the path to package.

rospack find [package_name]

Example:

rospack find roscpp

would return:

<YOUR_INSTALL_PATH>/share/roscpp

If you installed ROS Melodic from apt on Ubuntu Linux you would see exactly:

/opt/ros/melodic/share/roscpp

roscd is part of the rosbash suite. It allows you to change directory (cd) directly to a package or a stack.

roscd <package-or-stack>[/subdir]

To verify that we have changed to the roscpp package directory, run this example:

roscd roscpp

Now let's print the working directory using the Unix command pwd. You should see:

YOUR_INSTALL_PATH/share/roscpp

You can see that YOUR_INSTALL_PATH/share/roscpp is the same path that rospack find gave in the previous example.

Note that roscd, like other ROS tools, will only find ROS packages that are within the directories listed in your ROS_PACKAGE_PATH. To see what is in your ROS_PACKAGE_PATH, type:

echo $ROS_PACKAGE_PATH

Your ROS_PACKAGE_PATH should contain a list of directories where you have ROS packages separated by colons. A typical ROS_PACKAGE_PATH might look like this:

Evie note: no colons in this example

/opt/ros/melodic/base/install/share

Similar to other environment paths, you can add additional directories to your ROS_PACKAGE_PATH, with each path separated by a colon ':'.

rosls is part of the rosbash suite. It allows you to ls directly into a package by name rather than by absolute path.

rosls <package-or-stack>[/subdir]

Example:

rosls roscpp_tutorials

would return:

cmake launch package.xml srv

It can get tedious to type out an entire package name. In the previous example, roscpp_tutorials is a fairly long name. Luckily, some ROS tools support TAB completion.

Start by typing:

roscd roscpp_tut
<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out the rest:

roscd roscpp_tutorials/

This works because roscpp_tutorials is currently the only ROS package that starts with roscpp_tut.

Now try typing:

roscd tur
<<< now push the TAB key >>>

After pushing the TAB key, the command line should fill out as much as possible:

roscd turtle

However, in this case there are multiple packages that begin with turtle. Try typing TAB another time. This should display all the ROS packages that begin with turtle:

turtle_actionlib/ turtlesim/ turtle_tf/

On the command line you should still have:

roscd turtle

Now type an s after turtle and then push TAB:

roscd turtles
<<< now push the TAB key >>>

Since there is only one package that starts with turtles, you should see:

roscd turtlesim/

If you want to see a list of all currently installed packages, you can use tab completion for that as well:

rosls
<<< now push the TAB key twice >>>

Credits

http://wiki.ros.org/ROS/Tutorials/InstallingandConfiguringROSEnvironment

http://wiki.ros.org/ROS/Tutorials/NavigatingTheFilesystem


Previous
Previous

Visual Studio Code

Next
Next

Robot Operating System