Go to the documentation of this file.00001
00002 #include <pluginlib/class_list_macros.h>
00003 #include <QStringList>
00004 #include <rqt_gauges/my_plugin.h>
00005 #include <rqt_gauges/qcgaugewidget.h>
00006 #include <stdlib.h>
00007 #include <sstream>
00008
00009 namespace rqt_gauges {
00010
00011
00012 void MyPlugin::newDataCallback(const std_msgs::Float64& msg)
00013 {
00014 mSpeedNeedle_-> setCurrentValue(msg.data);
00015 }
00016
00017
00018 MyPlugin::MyPlugin()
00019 : rqt_gui_cpp::Plugin()
00020 , widget_(0)
00021 {
00022
00023 setObjectName("Gauge");
00024 }
00025
00026 void MyPlugin::initPlugin(qt_gui_cpp::PluginContext& context)
00027 {
00028
00029
00030
00031
00032 mSpeedGauge_ = new QcGaugeWidget();
00033 widget_ = mSpeedGauge_;
00034
00035 ui_.setupUi(widget_);
00036
00037
00038 widget_->setWindowTitle("Gauge[*]");
00039 if (context.serialNumber() != 1)
00040 {
00041 widget_->setWindowTitle(widget_->windowTitle() + " (" + QString::number(context.serialNumber()) + ")");
00042 }
00043
00044
00045
00046
00047
00048 std::string gaugeNum;
00049 std::stringstream out;
00050 out << context.serialNumber();
00051 gaugeNum = out.str();
00052
00053
00054 if (!getNodeHandle().hasParam("topic"+gaugeNum))
00055 getNodeHandle().setParam("topic"+gaugeNum, "/roll");
00056 if (!getNodeHandle().hasParam("gauge_name"+gaugeNum))
00057 getNodeHandle().setParam("gauge_name"+gaugeNum, "Roll");
00058 if (!getNodeHandle().hasParam("minimum"+gaugeNum))
00059 getNodeHandle().setParam("minimum"+gaugeNum, 0);
00060 if (!getNodeHandle().hasParam("maximum"+gaugeNum))
00061 getNodeHandle().setParam("maximum"+gaugeNum, 100);
00062 if (!getNodeHandle().hasParam("danger_threshold"+gaugeNum))
00063 getNodeHandle().setParam("danger_threshold"+gaugeNum, 50);
00064 if (! getNodeHandle().hasParam("pixel_size"+gaugeNum))
00065 getNodeHandle().setParam("pixel_size"+gaugeNum, 200);
00066
00067
00068 int gauge_size = 150;
00069 getNodeHandle().getParam("pixel_size"+gaugeNum, gauge_size);
00070 mSpeedGauge_->setFixedHeight(gauge_size);
00071 mSpeedGauge_->setFixedWidth(gauge_size);
00072 mSpeedGauge_->addBackground(99);
00073 QcBackgroundItem *bkg1 = mSpeedGauge_->addBackground(92);
00074 bkg1->clearrColors();
00075 bkg1->addColor(0.1,Qt::black);
00076 bkg1->addColor(1.0,Qt::white);
00077
00078 QcBackgroundItem *bkg2 = mSpeedGauge_->addBackground(88);
00079 bkg2->clearrColors();
00080 bkg2->addColor(0.1,Qt::gray);
00081 bkg2->addColor(1.0,Qt::darkGray);
00082
00083
00084 std::string gaugeName;
00085 getNodeHandle().getParam("gauge_name"+gaugeNum, gaugeName);
00086 mSpeedGauge_->addLabel(70)->setText(gaugeName.c_str());
00087
00088
00089 int minimum = 0;
00090 getNodeHandle().getParam("minimum"+gaugeNum, minimum);
00091 int maximum = 100;
00092 getNodeHandle().getParam("maximum"+gaugeNum, maximum);
00093
00094 mSpeedGauge_->addDegrees(65)->setValueRange(minimum, maximum);
00095
00096 mSpeedGauge_->addValues(80)->setValueRange(minimum, maximum);
00097
00098
00099 QcLabelItem *lab = mSpeedGauge_->addLabel(40);
00100 lab->setText("0");
00101 mSpeedNeedle_ = mSpeedGauge_->addNeedle(60);
00102 mSpeedNeedle_->setLabel(lab);
00103 mSpeedNeedle_->setColor(Qt::black);
00104 mSpeedNeedle_->setValueRange(minimum,maximum);
00105 mSpeedGauge_->addBackground(7);
00106 mSpeedGauge_->addGlass(88);
00107
00108
00109 double threshold = 0.;
00110 getNodeHandle().getParam("danger_threshold"+gaugeNum, threshold);
00111 mSpeedGauge_->addColorBand(threshold);
00112
00113
00114 context.addWidget(widget_);
00115
00116
00117 std::string topicName;
00118 getNodeHandle().getParam("topic"+gaugeNum, topicName);
00119 needleSub_ = getNodeHandle().subscribe (topicName, 1, &rqt_gauges::MyPlugin::newDataCallback, this);
00120 }
00121
00122 void MyPlugin::shutdownPlugin()
00123 {
00124 needleSub_.shutdown();
00125 }
00126
00127 void MyPlugin::saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const
00128 {
00129
00130
00131 }
00132
00133 void MyPlugin::restoreSettings(const qt_gui_cpp::Settings& plugin_settings, const qt_gui_cpp::Settings& instance_settings)
00134 {
00135
00136
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 }
00150 PLUGINLIB_DECLARE_CLASS(rqt_gauges, MyPlugin, rqt_gauges::MyPlugin, rqt_gui_cpp::Plugin)