how to add a simple button in RVIZ
Hello
I would like to add a button on rviz (in plugin format) that when I click on it, it publishes a Boolean message ROS informing the robot to light a led for example. Does anyone know how to do this?
I have an example of a plugin I made to publish a pose message on the map, but I need to interact with the mouse on the map. In that case I would like the message to be published as soon as I click on the button for the "light up led" plugin. Would it be possible to make this change?
setDock.cpp:
#ifndef SETDOCK_HPP
#define SETDOCK_HPP
#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
#include <QObject>
#include <ros/ros.h>
#include "rviz/default_plugin/tools/pose_tool.h"
#endif
namespace rviz_plugin_setDock
{
//class SetDock;
class SetDock : public rviz::PoseTool
{
Q_OBJECT
public:
SetDock();
//virtual ~SetDock();
//virtual void onInitialize();
protected:
virtual void onPoseSet(double x, double y, double theta);
public Q_SLOTS:
void updateTopic();
protected:
ros::NodeHandle nh_;
ros::Publisher pub_;
};
} // namespace rviz_plugin_setDock
#endif // SETDOCK_HPP
setDock.cpp:
#include <tf/transform_listener.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include "rviz/display_context.h"
#include "setDock/setDock.hpp"
namespace rviz_plugin_setDock
{
SetDock::SetDock()
{
updateTopic();
}
void SetDock::updateTopic()
{
pub_ = nh_.advertise<geometry_msgs::PoseWithCovarianceStamped>("dock_position", 1 );
}
void SetDock::onPoseSet(double x, double y, double theta)
{
std::string fixed_frame = context_->getFixedFrame().toStdString();
geometry_msgs::PoseWithCovarianceStamped pose;
pose.header.frame_id = fixed_frame;
pose.header.stamp = ros::Time::now();
pose.pose.pose.position.x = x;
pose.pose.pose.position.y = y;
tf::Quaternion quat;
quat.setRPY(0.0, 0.0, theta);
tf::quaternionTFToMsg(quat,
pose.pose.pose.orientation);
pub_.publish(pose);
}
} // namespace rviz_plugin_setDock
#include <pluginlib/class_list_macros.h>
PLUGINLIB_EXPORT_CLASS(rviz_plugin_setDock::SetDock, rviz::Tool)
Thank you
You could take a look at InstitutMaupertuis/simple_rviz_plugin.