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!

Launch the Turtlesim Robot Simulation in ROS

In this section, we will work with the turtlesim application. This application comes pre-installed with ROS and consists of a 2D simulation of a turtle. You can move the turtle around and do a lot of other cool stuff as described here at the turtlesim ROS Wiki page.

Turtlesim isn’t the most exciting application, but it is a popular tool for learning the basics of ROS before working with real robots. You can think of the turtle as an actual robot. All of the things you can do with this turtle, you can do with a real, physical robot.

15-turtlesim

You Will Need

In order to complete this tutorial, you will need:

Directions

Let’s run this program now with rospy, the Python library for ROS. 

Let’s launch turtlesim now. Open up a new terminal window, and type:

roscore

Open a new terminal tab, and launch the turtlesim application.

rosrun turtlesim turtlesim_node
launch-turtlesim

Let’s see the list of topics. Remember that a topic in ROS is a named bus (or channel) over which a node publishes messages for other nodes to receive.  Open a new terminal tab, and type:

rostopic list
17-rostopic-list

Now, up until now, the model that I have shown you of how ROS nodes communicate with each other is the ROS Topics model, in which a Publisher Node sends messages via a Topic to one or more registered Subscriber nodes. We worked with this model in the Hello World project in the previous section. This model looks like this:

ros-master-nodes

Notice that the flow of information between nodes is one-way, from Publisher to Subscriber. What do we do in a situation where we have a node that wants to request information from another node and receive an immediate reply? How is this two-way communication implemented in ROS? Request/reply in ROS is performed via ROS Services.

A ROS Service consists of a pair of messages: one for the request and one for the reply. A service-providing ROS node (i.e. Service Server) offers a service (e.g. read sensor data). A client node (i.e. Service Client) calls the service by sending a request message to the service provider. The client node then awaits the reply. Here is what the ROS Service model looks like:

ros-service-model

The ROS tutorials present a good explanation of when you would want to use the ROS Topic model and when you would want to use the ROS Service model.

Now that we understand what a ROS Service is, let’s see a list of all active services in our turtlesim application. Open a new terminal window and type:

rosservice list
18-rosservice-list

Let’s see a list of ROS parameters. Think of parameters as the global settings for our current ROS environment (e.g. things like the background color of the turtlesim screen, version of ROS we are using, etc.).

rosparam list
19-rosparam-list

OK, now that we have covered some more ROS terminology, let’s have some fun and make this turtle move around the blue window. In order to do that, I need to create another ROS node. I have to open up a new terminal tab and type this command:

rosrun turtlesim turtle_teleop_key
20-move-turtle

If you use the arrow keys on your keyboard from within the terminal where you typed the command above, you should see the turtle moving around the screen. Each time you press an arrow key, the teleop_turtle node publishes a message to the /turtle1/cmd_vel topic. turtlesim node is subscribed to that topic. It receives the message and moves the turtle. 

21-move-turtle-2

Open a new terminal window and see a list of active nodes using this command:

rosnode list
23-active-nodes
setup-with-turtle

Here is the block diagram of our application:

teleop-turtle

Now draw a square with turtlesim. Press Ctrl+C to stop the simulation. Close all terminal windows, and start a new terminal window. Type:

roscore
rosrun turtlesim turtlesim_node 
rosrun turtlesim draw_square

The robot will go around and around along a square-shaped path.

24-draw-square
25-draw-square-2

To reset the simulator, type:

rosservice call /reset

Then type:

rosrun turtlesim draw_square

And now you have seen how to launch and run Turtlesim in ROS!

Create a Hello World Project in ROS

In this section, we will develop our first ROS application. We are not going to do anything fancy here…just a basic “Hello World” project to get our feet wet with ROS. But before we get started on that, let’s cover some basic ROS terminology on a high level.

You Will Need

In order to complete this tutorial, you will need:

Directions

Our goal in this project is to get two pieces of ROS software (called nodes) to talk to each other. You can think of nodes as small single-purpose programs within a larger robotic system. One way nodes communicate with each other is by using messages. These messages are passed via channels called topics.

Nodes that send data are known as publisher nodes, and nodes that receive data are known as subscriber nodes. The node that keeps track (i.e. a register) of which nodes are publisher nodes and which nodes are subscriber nodes is called the ROS Master. Without the ROS Master, nodes would not be able to communicate with each other.

Nodes that are interested in a particular piece of data subscribe to the relevant topic; nodes that generate data publish to the relevant topic. There can be multiple publishers and subscribers to a topic. You can think of topics like a middle man between publishers (nodes that generate data) and subscribers (nodes that receive data). The communication is anonymous, so nodes do not know what nodes they are sending data to/receiving data from.

Here is a basic high-level diagram of the ROS Topic communication architecture I described above.

ros_master_1

A good analogy is to think of YouTube (or even other social media sites like Twitter or Instagram). YouTubers (publisher nodes) publish videos (messages) to a channel (topic), and you (subscriber node) can subscribe to that channel (topic) so that you receive all the videos (messages) on that channel (topic). YouTube (ROS Master) keeps track of who is a publisher and who is a subscriber. One thing to keep in mind is that (in contrast to YouTube) in ROS there can be multiple publishers to the same topic, and publishers and subscribers don’t know each other.

In the robotic world, we need different parts of a robot to send data to each other so that the robot can sense the world, process what it sees, and then act on the world. For example, suppose we are working on a humanoid robot. We might have one small program (publisher node) responsible for reading sensor data from a camera mounted on the head of the robot. That program might send that data (i.e. message) via a topic called “vision scan” to another program (subscriber node) which is responsible for controlling the joint in the robot’s arm. Note that messages in ROS can be a variety of data types, including strings, floats, integers, etc.

So with that terminology under our belts, we are ready to get started on our Hello World project. Let’s develop an application that consists of two nodes: talker and listener. The talker node will publish a “Hello World” message to the /chatter topic. The listener will subscribe to the /chatter topic so that it can receive the “Hello World” message. Here is a diagram of what I described above.

ros_master_2

To launch ROS, open a new Linux terminal window and type the following command:

roscore
10-roscore-1

roscore is the main process that is responsible for managing everything in ROS. Anytime you are trying to run a program in ROS, roscore needs to be running. roscore ensures that nodes (i.e. programs you write in Python and C++) are able to communicate with each other.

Open up a new terminal window, and start the talker node.

rosrun roscpp_tutorials talker

You should see hello world messages repeatedly printing to the screen.

11-roscpp-tutorials-talker

Use this command on a new terminal tab (File -> New Tab) to see a list of current active topics.

rostopic list
12-rostopic

The topic of the hello world messages is /chatter.

Now let’s start the listener node. The listener node will subscribe to the /chatter topic so that it can receive the hello world messages published by talker.

Open up a new terminal tab and type:

rosrun roscpp_tutorials listener
13-listener-output

The listener “hears” hello world.

Now, let’s run the two nodes side-by-side just to see what that looks like. Open a new terminal tab and type:

roslaunch roscpp_tutorials talker_listener.launch
14-hello-world-input-output

The roslaunch command is useful when you want to launch multiple ROS nodes all at once.

To stop ROS, press this command on your keyboard:

Ctrl+C 

Then type the following command in the terminal to close the terminal.

exit

That’s it! Congrats! You have made your first ROS application.