Quantcast
Channel: ROS Answers: Open Source Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 255

Callback when user presses radio button in my rqt plugin?

$
0
0
I am writing a C++ rqt plugin which has the following layout: ![image description](http://i.imgur.com/YleaQiy.png) I would like to know how one would implement a callback function which executes when the user clicks one of the radio buttons? I.e. I want: - callback function `startEvent` to be executed when the user clicks the "Start experiment" radio button - callback function `stopEvent` to be executed when the user clicks the "STOP experiment" radio button What follows below is the current state of my code, if you need that info. Otherwise you can ignore it. Thanks for helping! Project tree: . ├── CMakeLists.txt ├── include │   └── rqt_example_cpp │   └── my_plugin.h ├── package.xml ├── plugin.xml ├── setup.py └── src └── rqt_example_cpp ├── my_plugin.cpp └── my_plugin.ui my_plugin.ui: MyPluginWidget00400300Form201014121Start experiment20401912175trueSTOP experiment my_plugin.h: #ifndef RQT_EXAMPLE_CPP_MY_PLUGIN_H #define RQT_EXAMPLE_CPP_MY_PLUGIN_H #include #include #include #include namespace rqt_plugin { 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_nh_; ros::Publisher ros_pub_; }; } // namespace rqt_example_cpp #endif // RQT_EXAMPLE_CPP_MY_PLUGIN_H my_plugin.cpp: #include "rqt_example_cpp/my_plugin.h" #include #include namespace rqt_plugin { MyPlugin::MyPlugin() : rqt_gui_cpp::Plugin() , widget_(0) { // Constructor is called first before initPlugin function, needless to say. // give QObjects reasonable names setObjectName("MyPlugin"); } void MyPlugin::initPlugin(qt_gui_cpp::PluginContext& context) { // access standalone command line arguments QStringList argv = context.argv(); // create QWidget widget_ = new QWidget(); // extend the widget with all attributes and children from UI file ui_.setupUi(widget_); // add widget to the user interface context.addWidget(widget_); // getNodeHandle().subscribe(); } void MyPlugin::shutdownPlugin() { // unregister all publishers here } void MyPlugin::saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const { // instance_settings.setValue(k, v) } void MyPlugin::restoreSettings(const qt_gui_cpp::Settings& plugin_settings, const qt_gui_cpp::Settings& instance_settings) { // v = instance_settings.value(k) } /*bool hasConfiguration() const { return true; } void triggerConfiguration() { // Usually used to open a dialog to offer the user a set of configuration }*/ } // namespace rqt_example_cpp PLUGINLIB_DECLARE_CLASS(rqt_plugin, MyPlugin, rqt_plugin::MyPlugin, rqt_gui_cpp::Plugin)

Viewing all articles
Browse latest Browse all 255

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>