Introduction to ROS¶
In this exercise, we will setup ROS to be used from the terminal, and start roscore.
In order to start programming in ROS, you should know how to install ROS on a new machine as well and check that the installation worked properly. This module will walk you through a few simple checks of your installed ROS system.
ROS Installation¶
As ROS is already preinstalled to your system, this section can be fast forwarded. Nevertheless, You are still encouredged to have a look on the installation instructions needed to get ROS going on a freshly installed Ubuntu Linux.
Testing the environment¶
We believe we have a good installation of ROS but let’s test it to make sure.
A good way to start is to ensure that environment variables like ROS_ROOT and ROS_PACKAGE_PATH are set:
printenv | grep ROS
If the variables are empty or do not contain paths to ROS workspaces you would like to work with, it is most likely that you might need to ‘source’ some setup.*sh files.
Let’s do that by entering:
source /opt/ros/kinetic/setup.bash
Now we have sourced the default workspace for ROS kinetic.
Run the
printenv | grep ROS
command again and verify that the variables have been set.
Tip
If you are ever having problems finding or using your ROS packages make sure that you have your environment properly setup.
Note
In a “bare” ROS install, you will need to run this command on every new shell you open to have access to the ROS commands. One of the setup steps in a typical ROS install is to add that command to the end of your ~/.bashrc
file, which is run automatically in every new terminal window.
To check that your
.bashrc
file has already been configured to source the ROS-kinetic setup.bash script:tail ~/.bashrc
For ease of this workshop, use the following oneliner to add automatic sourcing to the
.bashrc
:echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
Note
As one can observe, we sourced the ROS environment for a specific ROS distribution (kinetic). Using this sourcing process allows you to install several ROS distributions (e.g. indigo and kinetic) on the same computer and switch between them by sourcing the distribution-specific setup.bash file.
See also
More information on configuring the environment can be found from: ROS Wiki – Installing and Configuring Your ROS Environment.
Installing and Running your first ROS node¶
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. Alternatively, you can download the “cutting edge” versions (usually hosted on Github), but then you would need to set up a catkin workspace and build the packages yourself. This is a topic of day 2. Today, we use apt
to install a precompiled ROS packages from the ROS repository.
Install the package
roscpp_tutorials
, which can be found under metapackageros_tutorials
:sudo apt install ros-kinetic-ros-tutorials
Note
Pay attention to the distribution
kinetic
in the command.Use the commands you learned in section Navigating the ROS Filesystem to explore the location and content of the
roscpp_tutorials
package.Let’s run a
talker
node from this package. For that, we use the followingrosrun
command:rosrun roscpp_tutorials talker
Now, open another terminal and from the same package run the node
listener
.If you receive hello world messages with the listener node then congratulations! You are successfully running two nodes in the ROS system with one sending text messages to another.