Hi,
I am using a rqt plugin made with the [tutorial](http://wiki.ros.org/rqt/Tutorials/Create%20your%20new%20rqt%20plugin) and I have made a simple GUI composed with a slider and a button. I would like to connect the button, to send the value of the slider to a message. This message which contents a integer, would be publish when the button is clicked. Then in another file I have made a "listener" based on the tutorial and I would like to see on my screen the integer.
I can't catkin_make it because I have many errors. I know that I am mixing GUI and ros things, and signals and messages, I am lost. Can someone helpme with that ?
This is my header file :
#ifndef rqt_mypkg__my_plugin_H
#define rqt_mypkg__my_plugin_H
#include
#include
#include
#include
#include
#include
#include "std_msgs/String.h"
#include
namespace rqt_mypkg {
class MyPlugin
: public rqt_gui_cpp::Plugin
{
Q_OBJECT
public:
MyPlugin();
virtual void initPlugin(qt_gui_cpp::PluginContext& context);
virtual void shutdownPlugin();
virtual void saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const;
virtual void restoreSettings(const qt_gui_cpp::Settings& plugin_settings, const qt_gui_cpp::Settings& instance_settings);
// Comment in to signal that the plugin has a way to configure it
//bool hasConfiguration() const;
//void triggerConfiguration();
private:
Ui::MyPluginWidget ui_;
QWidget* widget_;
ros::NodeHandle ros_node_handle;
ros::Publisher my_publisher;
ros::Subscriber sub;
public Q_SLOTS:
virtual void publier();
};
} // namespace
#endif // rqt_mypkg_my_plugin_H
This is my cpp file :
(I know that the thing I've done with the "dac=0 and dac=1" is not working and stupid but I wanted to test it.)
#include "rqt_mypkg/my_plugin.h"
#include
#include "ros/ros.h"
#include
#include "std_msgs/String.h"
#include
#include
int dac= 0;
namespace rqt_mypkg {
MyPlugin::MyPlugin()
: rqt_gui_cpp::Plugin()
, widget_(0)
{
setObjectName("MyPlugin");
}
void MyPlugin::initPlugin(qt_gui_cpp::PluginContext& context)
{
QStringList argv = context.argv();
// create QWidget
widget_ = new QWidget();
ui_.setupUi(widget_);
// add widget to the user interface
context.addWidget(widget_);
connect(ui_.m_bouton, SIGNAL(clicked()), this, SLOT(publier()));
}
void MyPlugin::publier ()
{
dac = 1;
}
int main(int argc, char **argv)
{
ros::init(argc, argv,"envoyeur");
ros::NodeHandle ros_node_handle;
ros::Publisher my_publisher = ros_node_hand
le.advertise("chatter", 1000);
ros::Rate loop_rate(1);
int count = 0;
while(ros::ok())
{
std_msgs::Int8 msg;
std::stringstream ss;
msg.data = ui_.m_hSlider.display(int);
ROS_INFO("%d", msg.data);
if (dac==1) {
my_publisher.publish(msg);
}
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
void MyPlugin::shutdownPlugin()
{
}
void MyPlugin::saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const
{
}
void MyPlugin::restoreSettings(const qt_gui_cpp::Settings& plugin_settings, const qt_gui_cpp::Settings& instance_settings)
{
}
} // namespace
PLUGINLIB_DECLARE_CLASS(rqt_mypkg, MyPlugin, rqt_mypkg::MyPlugin, rqt_gui_cpp::Plugin)
↧