Step 3 – Creating the RViz plugin definition

In this step, we will create the main C++ file that contains the definition of the plugin. The file is teleop_pad.cpp, and you will get it from the src package folder.

The main responsibilities of this file are as follows:

  • It acts as a container for a Qt GUI element, such as QLineEdit, to accept text entries
  • It publishes the command velocity using the ROS publisher
  • It saves and restores the RViz config files

The following is the explanation for each section of the code:

TeleopPanel::TeleopPanel( QWidget* parent ) 
  : rviz::Panel( parent ) 
  , linear_velocity_( 0 ) 
  , angular_velocity_( 0 ) { 

This is the constructor and initialize rviz::Panel with QWidget, setting linear and angular velocity as

Get Mastering ROS for Robotics Programming - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.