Step 2 – Creating RViz plugin header file

Let's create a new header inside the src folder called teleop_pad.h. You will get this source code from the existing package. This header file consists of the class and methods declaration for the plugin.

The following is the explanation of this header file:

#include <ros/ros.h>
#include <ros/console.h>
#include <rviz/panel.h>

The preceding is the header file required to build this plugin; we need ROS headers for publishing teleop topic and <rviz/panel.h> for getting the base class of the RViz panel for creating a new panel:

class TeleopPanel: public rviz::Panel
{

This is a plugin class and is inherited from the rviz::Panel base class:

Q_OBJECT
public:

This class is using Qt signal and slots, and it's also a subclass of QObject in Qt.
In that case, we should use Q_OBJECT macro:

  TeleopPanel( QWidget* parent = 0 );

This is the constructor of the TeleopPanel() class and we are initializing a QWidget class to 0. We are using the QWidget instance inside the TeleopPanel class for implementing the GUI of the teleop plugin:

  virtual void load( const rviz::Config& config );
virtual void save( rviz::Config config ) const;

The following is the overriding of rviz::Panel functions for saving and loading the RViz config file:

public Q_SLOTS:

After this line, we can define some public Qt slots:

  void setTopic( const QString& topic );

When we enter the topic name in the GUI and press Enter, this slot will be called and will create topic publisher on the given name:

protected Q_SLOTS:
void sendVel();
void update_Linear_Velocity();
void update_Angular_Velocity();
void updateTopic();

These are the protected slots for sending velocity, updating linear velocity and angular velocity, and updating the topic name, when we change the name of the
existing topic:

  QLineEdit* output_topic_editor_;
QLineEdit* output_topic_editor_1;
QLineEdit* output_topic_editor_2;

We are creating Qt LineEdit object to create three text fields in the plugin to receive: topic name, linear velocity, and angular velocity.

ros::Publisher velocity_publisher_;
ros::NodeHandle nh_;

These are the publisher object and the Nodehandle object for publishing topics and handling a ROS node.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.77.98