Search this site
Embedded Files
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
No Boredom
  • Home
    • Computer Geek
    • Learning
    • Math Geek
    • Projects
  • More
    • Home
      • Computer Geek
      • Learning
      • Math Geek
      • Projects

RViZ

< Back to ROS Beginner tutorials
What is RViZ ?
Description of what you see
First RViZ tutorial
Configuring RViZ
Coding the temperature sensor
Preparing the launch file

What is RViZ ?

RViZ (short for ROS Visualization) is a visualization tool in ROS. It's used to visualize things like data from sensors like cameras, temperature sensors, LiDARs, Point cloud data, odometry, etc. It can also be used to show a robot model, in case we want to view the single robot in isolation from an environment. In very short, it's a powerful 3D visualization tool in ROS. Keep in mind that it's to visualize and not to simulate anything. So it can only show you stuff, it can't do things on it's own, that is: it can't create simulation outcomes like what a simulator does, it can't do anything that involves interaction between two objects. There are other tools in ROS for doing exactly that, but we'll see them in later pages.

RViZ is made on top of various open libraries and frameworks, Qt (for the application graphical user interface), OpenGL (open graphics library) and PCL (point cloud library) being notable few ones. There are a lot of dependencies for this tool. But lucky for us, all this comes to us in one single package named "rviz", that too in only one executable node, named "rviz". Let's see the RViZ GUI first, then we'll go about doing more with it. Open terminals and execute the following commands on different terminals:

  • roscore
    • To start the ROS server
  • rosrun rviz rviz
    • To start the RViZ node.
    • You could also run rviz and it would yield the same results.

After the window is spawned, it must look something like this:

RViZ Application

Complete user guide here.

Description of what you see

  • The grid that you see in the center is the view section. Here is where most of the visualization happens.
  • On the left is the displays section. It's the menu that contains everything that is being displayed on the view section and is the place where you can alter almost every property about what's being displayed.
    • At the bottom of this menu, you can Add item to the menu, feel free to inspect the list and play around.
  • At the bottom is the time menu. It keeps track of visualization time.
  • On the right is the views menu. It allows you to see the items in different camera perspectives. Focal point is the center point about which you rotate.
  • There's a menu bar with some icons on the top (we'll discuss more about these later on).

All these menus are also called panels. You can check the Panels option in the menu bar and play around with arrangements a little.

First RViZ tutorial

Let's simulate a temperature sensor and see it's readings as a color on a square inside RViZ for this tutorial. This one is a little long, so I've divided it into stages.

Configuring RViZ

Execute the following commands on different terminals (or on different tabs):

  • roscore
    • Start the server
  • rosrun rviz rviz
    • Start RViZ

Then, in the Displays panel click on Add and choose Temperature from the list (under rviz items, by display type), click ok. Make the following modifications in the Displays panel:

  • Under "Global Options"
    • Change the "Fixed Frame" to 'source'.
  • Under "Temperature"
    • Change the "Topic" name to '/temp_readings'.
    • Change the "Size (m)" to '1.00'.
    • Change the "Min Intensity" to "18"
    • Change the "Max Intensity" to "52"

Then, in the Views panel, make the following modifications:

  • Change the "Type" to "TopDownOrtho (rviz)"
  • Change the "Scale" to "75" (This basically zooms in)

In the end, your RViZ window must look like what's shown below (in the Description photo).

Description photo

Your values in the Time panel might be different because of timing reasons. Rest everything must match.

After this, perform the following:

  • Click on the File option in the menu bar
  • Click on Save Config As option. Navigate to your package directory and create a folder named "rviz".
  • Save the file as "TempConfig.rviz".
  • Close rviz.

To verify that everything went fine, do the following:

  • Re-run RViZ using the rosrun command above
  • Click on File -> Open -> Navigate to the recently saved TempConfig.rviz file and select it.
  • Everything must look just as in the description photo.

Coding the temperature sensor

Code here

We'll deal with actual hardware later, for now we'll just simulate one using a node. This will just be a simple publisher publishing messages of type sensor_msgs/Temperature, you can know more about it by running rosmsg info sensor_msgs/Temperature. The procedure for it is the same as any other publisher, besides, we already made one here. There are a few key differences though:

  • There's a header that we need to take care of, it basically keeps everything coordinated in sequence and time. It also publishes data over a frame, we'll name it 'source' (because we've configured RViZ to use that frame as the fixed frame for now).
  • We have to maintain the sequence number, because RViZ keeps a track and it's good for debugging. The easiest and most effective way of doing this is to increment the sequence number every time after publishing the message.
Code here
  • To build the code, make the following modifications:
    • To CMakeLists.txt (file here):
      • Add sensor_msgs to the find_package function.
      • add_executable(TempSimSensor src/TempSensor.cpp)
      • target_link_libraries(TempSimSensor ${catkin_LIBRARIES})
    • To package.xml (file here):
      • Add sensor_msgs under tags build_depend, build_export_depend and exec_depend.

Then make the package, open a terminal and run the following:

  • cd ~/ROS_workspaces/ros_ws/
  • catkin_make

Preparing the launch file

Code here

Let's create a single file that will spawn everything. Here's a list of things that we'll do:

  • Create an argument named rvizconfig and assign it the full name and path to the rviz file that we created
  • Launch the node created by us.
  • Launch the RViZ node and loading the configuration file using the argument variable (you can get more using rosrun rviz rviz --help).
Code here

Here's a little more modified version of the launch file, this one has configurations set up as well.

Codes for launch file and source (C++) node

After all this, open a terminal and run a single command shown below. You must see the RViZ window open with a square in the middle that changes color over time based on temperature passed on the topic (observe for about 40 seconds, image shown below).

roslaunch intro_pkg1 TemperatureRViZ.launch

This is more or less how any RViZ related project is developed, fee free to explore more options about various other sensors.

Results about 40 seconds after RViZ gets launched

< Back to ROS Beginner tutorials
Google Sites
Report abuse
Page details
Page updated
Google Sites
Report abuse