Repository Summary
Description | A tutorial on how to make rviz plugins |
Checkout URI | https://github.com/metrorobots/rviz_plugin_tutorial.git |
VCS Type | git |
VCS Version | main |
Last Updated | 2025-05-13 |
Dev Status | UNKNOWN |
Released | UNRELEASED |
Tags | No category tags. |
Contributing |
Help Wanted (-)
Good First Issues (-) Pull Requests to Review (-) |
Packages
Name | Version |
---|---|
rviz_plugin_tutorial | 0.0.0 |
rviz_plugin_tutorial_msgs | 0.0.0 |
README
Building a Custom RViz Display
Background
There are many types of data that have existing visualizations in RViz. However, if there is a message type that does not yet have a plugin to display it, there are two choices to see it in RViz.
- Convert the message to another type, such as
visualization_msgs/Marker
. - Write a Custom RViz Display.
With the first option, there is more network traffic and limitations to how the data can be represented. It is also quick and flexible. The latter option is explained in this tutorial. It takes a bit of work, but can lead to much richer visualizations.
All of the code for this tutorial can be found in this repository <https://github.com/MetroRobots/rviz_plugin_tutorial>
__.
In order to see the incremental progress of the plugin written in this tutorial,
the repository has different branches (step2
, step3
…) that can each be compiled and run as you go.
Point2D Message
We’ll be playing with a toy message defined in the rviz_plugin_tutorial_msgs
package: Point2D.msg
:
std_msgs/Header header
float64 x
float64 y
Boilerplate for Basic Plugin
Strap in, there’s a lot of code. You can view the full version of this code with the branch name step1
.
Header File
Here are the contents of point_display.hpp
#ifndef RVIZ_PLUGIN_TUTORIAL__POINT_DISPLAY_HPP_
#define RVIZ_PLUGIN_TUTORIAL__POINT_DISPLAY_HPP_
#include <rviz_common/message_filter_display.hpp>
#include <rviz_plugin_tutorial_msgs/msg/point2_d.hpp>
namespace rviz_plugin_tutorial
{
class PointDisplay
: public rviz_common::MessageFilterDisplay<rviz_plugin_tutorial_msgs::msg::Point2D>
{
Q_OBJECT
protected:
void processMessage(const rviz_plugin_tutorial_msgs::msg::Point2D::ConstSharedPtr msg) override;
};
} // namespace rviz_plugin_tutorial
#endif // RVIZ_PLUGIN_TUTORIAL__POINT_DISPLAY_HPP_
- We’re implementing the
MessageFilterDisplay
class which can be used with any message with astd_msgs/Header
. - The class is templated with our
Point2D
message type. -
For reasons outside the scope of this tutorial, you need the
Q_OBJECT
macro in there to get the QT parts of the gui to work. -
processMessage
is the only method that needs to be implemented, which we’ll do in the cpp file.
Source File
#include <rviz_plugin_tutorial/point_display.hpp>
#include <rviz_common/logging.hpp>
namespace rviz_plugin_tutorial
{
void PointDisplay::processMessage(const rviz_plugin_tutorial_msgs::msg::Point2D::ConstSharedPtr msg)
{
RVIZ_COMMON_LOG_INFO_STREAM("We got a message with frame " << msg->header.frame_id);
}
} // namespace rviz_plugin_tutorial
#include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(rviz_plugin_tutorial::PointDisplay, rviz_common::Display)
- The logging is not strictly necessary, but helps with debugging.
- In order for RViz to find our plugin, we need this
PLUGINLIB
invocation in our code (as well as other things below)
package.xml
We need the following three dependencies in our package.xml:
<depend>pluginlib</depend>
<depend>rviz_common</depend>
<depend>rviz_plugin_tutorial_msgs</depend>
rviz_common_plugins.xml
<library path="point_display">
<class type="rviz_plugin_tutorial::PointDisplay" base_class_type="rviz_common::Display">
<description></description>
</class>
</library>
- This is standard
pluginlib
code. - The library
path
is the name of the library we’ll assign in the CMake.
File truncated at 100 lines see the full file