How to Create a ROS Workspace

Before you start writing code in ROS, you need to create a workspace. A workspace is a set of directories (or folders) where you store related pieces of ROS code. The official name for workspaces in ROS is catkin workspaces. The word ‘catkin’ comes from the tail-shaped flower cluster found on willow trees (see photo below) — a reference to Willow Garage, the original developers of ROS. 

willow_catkins_blossom_bloom

All the ROS packages that you create need to reside inside a catkin workspace. The name of this catkin workspace is typically called catkin_ws.

The official instructions for creating a ROS workspace are at ROS.org, but I will walk you through the process below so you can see how it is done.

Directions

Open up a new terminal window (I’m assuming you are using ROS on Ubuntu Linux), and type the following commands to create and build at catkin workspace.

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
1-catkin-workspace

Type the dir command, and you will see three folders inside of this directory: build, devel, and src.

2-dir-command

Now we need to source the setup.bash file. This file sets the path of the workspace so that packages and code inside the workspace can be found.

source devel/setup.bash
3-set-path

Make sure the workspace is properly overlayed by the setup script (which we ran above).

echo $ROS_PACKAGE_PATH
4-make-sure

So we don’t have to source the setup.bash file every time we open a new Linux terminal, let’s add the ~/catkin_ws/devel/setup.bash command to the .bashrc file. Open a new Linux terminal window.

Type the following command to edit the .bashrc text file:

gedit ~/.bashrc

Add this line to the end of the .bashrc file:

source ~/catkin_ws/devel/setup.bash
5-edit-bashrc-file

That’s it! You’re all done. Just click Save and exit the text editor.

How to Launch Gazebo in Ubuntu

Gazebo is a 3D simulator that is a really good tool if you want to simulate your robot in a complex outdoor or indoor environment. In this post, I will show you how to launch Gazebo in Ubuntu.

You Will Need

Before you launch Gazebo, it is important you have it installed on your Ubuntu Linux distribution. If you already have ROS on your system or you followed my ROS installation tutorial, Gazebo is already installed. Otherwise, check out this link at the official Gazebo website and follow the instructions to install Gazebo on Ubuntu.

Directions

To launch Gazebo for the first time, open up a new terminal window, and type the following command. It normally takes a while to launch the first time, so just sit back and relax while Gazebo does its thing:

gazebo

Here is what your screen should look like.

1-launch-gazeboJPG

But that is not what my screen looked like at all. I got this ugly error message on my terminal window.

2-terminal-messageJPG

The error is:

[Err] [REST.cc:205] Error in REST request

libcurl: (51) SSL: no alternative certificate subject name matches target host name ‘apt.ignitionfuel.org’

To resolve this error, press CTRL+C on your keyboard to close Gazebo.

Open up a new terminal tab and type:

cd ~/.ignition/fuel/
3-config-yamlJPG

Type dir and press Enter.

You should see the config.yaml file.

4-change-urlJPG

Open up that file.

gedit config.yaml 

Change:

url: https://api.ignitionfuel.org

to

url: https://api.ignitionrobotics.org

Click Save.

Close the window.

Now open up a new terminal window and launch Gazebo.

gazebo
5-no-errorJPG

You will see there is now no error. That’s it!

How to Launch RViz and RQt in ROS

Up until now we have been interacting with ROS via the Linux terminal. ROS also has some really cool graphical user interface (GUI) tools that enable you to interact with ROS in a more visual way than we have done so far. Two of these tools are rviz and rqt.

  • rviz is a 3D visualizer for ROS
  • rqt is a ROS visualization tool based on Qt, a free and open-source widget toolkit for creating GUIs.

In this tutorial, I’ll show you how to set up both of these tools.

You Will Need

In order to complete this tutorial, you will need:

Directions

To launch rviz, open a new terminal window and type:

roscore

Open up a new terminal tab and type:

rosrun rviz rviz
26-rviz

To launch rqt, open a new terminal window and type:

roscore

Open up a new terminal tab and type:

rosrun rqt_gui rqt_gui
27-rqt-empty-gui

You can see a list of available Plugins by going to the Plugins option. Let’s go to Plugins -> Visualization -> Plot to get a blank plot.

28-blank-plot

That’s it!