MrRqt.cpp
Go to the documentation of this file.
00001 /*
00002  * MrmRqt.cpp
00003  *
00004  *  Created on: Nov 14, 2013
00005  *      Author: blackpc
00006  */
00007 
00008 #include <mr_rqt/MrRqt.h>
00009 
00010 namespace mr_rqt
00011 {
00012 
00013 MrRqt::MrRqt()
00014         : _outputReady(false), _widget(NULL), _velocityWidget(NULL), _spinThread(boost::bind(&MrRqt::spin, this))
00015 {
00016 //      _setInputPublisher              = _node.advertise<std_msgs::Int32>("/velocity_dispatcher/set_input", 1, false);
00017 //      _setOutputPublisher     = _node.advertise<std_msgs::Int32>("/velocity_dispatcher/set_output", 1, false);
00018 //
00019 //      _cmdvelSubscriber               = _node.subscribe("/pioneer_1/cmd_vel", 1, &MrRqt::onVelocityMessage, this);
00020 }
00021 
00022 MrRqt::~MrRqt()
00023 {
00024 //      delete _widget;
00025 }
00026 
00027 void MrRqt::wireUpEvents()
00028 {
00029 //      connect(_mrmControllerUi.selectOutputButton,    SIGNAL(clicked()), this, SLOT(selectOutputClicked()));
00030 //      connect(_mrmControllerUi.selectInputButton,             SIGNAL(clicked()), this, SLOT(selectInputClicked()));
00031 
00032         connect(_mrmControllerUi.addControllerButton,    SIGNAL(clicked()), this, SLOT(addControllerClicked()));
00033 }
00034 
00035 //void MrRqt::refreshInputOutput(map<string, string>& inputs, vector<string> outputs)
00036 //{
00037 //      /**
00038 //       * Inputs
00039 //       */
00040 //      _mrmControllerUi.inputMethods->clear();
00041 //      pair<string, string> input;
00042 //      foreach(input, inputs) {
00043 //              _mrmControllerUi.inputMethods->addItem(QString::fromStdString(
00044 //                              input.first + " [" + input.second + "]"));
00045 //
00046 //              if (input.first == "Mouse") {
00047 //                      ROS_INFO("Mouse velocity topic = %s", input.second.c_str());
00048 //                      _mouseVelocityPublisher = _node.advertise<geometry_msgs::Twist>(input.second, 1, false);
00049 //              }
00050 //
00051 //              if (input.first == "Keyboard") {
00052 //                      ROS_INFO("Keyboard velocity topic = %s", input.second.c_str());
00053 //                      _keyboardVelocityPublisher = _node.advertise<geometry_msgs::Twist>(input.second, 1, false);
00054 //              }
00055 //      }
00056 //
00057 //      /**
00058 //       * Outputs
00059 //       */
00060 //      _mrmControllerUi.controllableRobots->clear();
00061 //      _mrmControllerUi.controllableRobots->addItem(QString::fromStdString("None"));
00062 //
00063 //      int robotId = 1;
00064 //      foreach(string velocityTopic, outputs) {
00065 //              _mrmControllerUi.controllableRobots->addItem(QString::fromStdString(
00066 //                              "Robot #" + boost::lexical_cast<string>(robotId++) + " [" + velocityTopic + "]"));
00067 //      }
00068 //
00069 //      if (robotId > 1)
00070 //              _mrmControllerUi.controllableRobots->setCurrentIndex(1);
00071 //
00072 //      _outputReady = true;
00073 //}
00074 
00075 bool MrRqt::setupInputOuput(ros::NodeHandle& node)
00076 {
00077 
00078         if (node.hasParam("/mr_teleoperator/output_topics"))
00079                 node.getParam("/mr_teleoperator/output_topics", _outputTopics);
00080         else {
00081                 ROS_ERROR("No output topics provided");
00082                 return false;
00083         }
00084 
00088     _mrmControllerUi.controllableRobots->clear();
00089 
00090     foreach(string velocityTopic, _outputTopics){
00091         _mrmControllerUi.controllableRobots->addItem(
00092                 QString::fromStdString(velocityTopic));
00093     }
00094 
00095     _outputReady = true;
00096 
00097         return true;
00098 }
00099 
00100 void MrRqt::initPlugin(qt_gui_cpp::PluginContext& context)
00101 {
00102         QStringList argv = context.argv();
00103         _widget = new QWidget();
00104         _mrmControllerUi.setupUi(_widget);
00105 
00106 //      _velocityWidget = new VelocityWidget(_widget);
00107 //      _velocityWidget->setObjectName(QString::fromUtf8("canvas"));
00108 //      _velocityWidget->setMinimumSize(QSize(200, 200));
00109 //      _velocityWidget->setMaximumSize(QSize(200, 200));
00110 //      _velocityWidget->setCallback(boost::bind(&MrRqt::publishMouseVelocity, this, _1, _2));
00111 //      _mrmControllerUi.gridLayout->addWidget(_velocityWidget, 3, 0, 1, 1, Qt::AlignHCenter);
00112 
00113         context.addWidget(_widget);
00114 
00115 //      _mrmControllerUi.keyboardTeleop->installEventFilter(&_keyboardTeleop);
00116 //      _keyboardTeleop.setCallback(boost::bind(&MrRqt::publishKeyboardVelocity, this, _1, _2));
00117 //
00118 //      _mrmControllerUi.keyboardTeleop->setVisible(false);
00119 
00120         wireUpEvents();
00121 
00122         setupInputOuput(_node);
00123 }
00124 
00125 void MrRqt::shutdownPlugin()
00126 {
00127 }
00128 
00129 void MrRqt::saveSettings(qt_gui_cpp::Settings& plugin_settings,
00130                 qt_gui_cpp::Settings& instance_settings) const
00131 {
00132 }
00133 
00134 void MrRqt::restoreSettings(
00135                 const qt_gui_cpp::Settings& plugin_settings,
00136                 const qt_gui_cpp::Settings& instance_settings)
00137 {
00138 }
00139 
00140 //void MrRqt::refreshConfiguration()
00141 //{
00142 //      if (_currentOutput >= 0) {
00143 //              _mrmControllerUi.lblCurrentRobot->setText(QString::fromStdString("#" + boost::lexical_cast<string>(_currentOutput + 1)));
00144 //              _mrmControllerUi.lblCurrentTopic->setText(QString::fromStdString(_outputTopics[_currentOutput]));
00145 //      }
00146 //      else {
00147 //              _mrmControllerUi.lblCurrentRobot->setText(QString::fromStdString("None"));
00148 //              _mrmControllerUi.lblCurrentTopic->setText(QString::fromStdString("None"));
00149 //      }
00150 //
00151 //      _mrmControllerUi.lblCurrentInput->setText(_mrmControllerUi.inputMethods->currentText());
00152 //
00153 //}
00154 
00155 //void MrRqt::publishMouseVelocity(double linearPercent, double angularPercent)
00156 //{
00157 //      geometry_msgs::Twist message;
00158 //
00159 //      message.linear.x = (linearPercent / 100.0) * 3;
00160 //      message.angular.z = (angularPercent / 100.0) * 3;
00161 //
00162 //      if (_outputReady)
00163 //              _mouseVelocityPublisher.publish(message);
00164 //}
00165 
00166 //void MrRqt::publishKeyboardVelocity(double linear, double angular)
00167 //{
00168 //      geometry_msgs::Twist message;
00169 //
00170 //      message.linear.x = linear;
00171 //      message.angular.z = angular;
00172 //
00173 //      if (_outputReady)
00174 //              _keyboardVelocityPublisher.publish(message);
00175 //}
00176 
00177 //void MrRqt::onVelocityMessage(const geometry_msgs::Twist::Ptr velocity)
00178 //{
00179 //      if (_velocityWidget == NULL)
00180 //              return;
00181 //
00182 //      _velocityWidget->setVelocity(velocity->linear.x, velocity->angular.z);
00183 //      _mrmControllerUi.lcdLinear->display(velocity->linear.x);
00184 //      _mrmControllerUi.lcdAngular->display(velocity->angular.z);
00185 //
00186 //
00187 //}
00188 
00189 void MrRqt::spin()
00190 {
00191         ros::spin();
00192 }
00193 
00194 void MrRqt::addControllerClicked()
00195 {
00196     QDockWidget* dock = new QDockWidget();
00197 
00198     dock->setAttribute(Qt::WA_DeleteOnClose);
00199 
00200     TeleoperatorInstanceWidget::InputMethod inputMethod = (TeleoperatorInstanceWidget::InputMethod)(_mrmControllerUi.inputMethods->currentIndex());
00201     string velocityTopic = _mrmControllerUi.controllableRobots->currentText().toStdString();
00202     string feedbackVelocityTopic = inputMethod == TeleoperatorInstanceWidget::Joystick ? "/joy_cmd_vel" : velocityTopic;
00203 
00204     QWidget* dockContent = new TeleoperatorInstanceWidget(
00205                 _node,
00206                 inputMethod,
00207                 _mrmControllerUi.controllableRobots->currentIndex() + 1,
00208                 velocityTopic,
00209                 feedbackVelocityTopic);
00210 
00211     dock->setWidget(dockContent);
00212     _mrmControllerUi.horizontalLayoutContainer->addWidget(dock);
00213 }
00214 
00215 //void MrRqt::selectInputClicked()
00216 //{
00217 //      if (!_outputReady)
00218 //              return;
00219 //
00220 //      string inputMethod = _mrmControllerUi.inputMethods->currentText().toStdString();
00221 //
00222 //
00223 //      if (boost::starts_with(inputMethod, "Mouse")) {
00224 //              _velocityWidget->enableMouseControl();
00225 //      } else
00226 //              _velocityWidget->disableMouseControl();
00227 //
00228 //
00229 //      if (boost::starts_with(inputMethod, "Keyboard")) {
00230 //              _mrmControllerUi.keyboardTeleop->setVisible(true);
00231 //      } else {
00232 //              _mrmControllerUi.keyboardTeleop->setVisible(false);
00233 //      }
00234 //
00235 //      std_msgs::Int32 selectedInput;
00236 //      selectedInput.data = _mrmControllerUi.inputMethods->currentIndex() + 1;
00237 //      _setInputPublisher.publish(selectedInput);
00238 //
00239 //      _currentInput = selectedInput.data - 1;
00240 //
00241 //      _velocityWidget->resetLimits();
00242 //
00243 //      refreshConfiguration();
00244 //}
00245 
00246 //void MrRqt::selectOutputClicked()
00247 //{
00248 //      if (!_outputReady)
00249 //              return;
00250 //
00251 //      std_msgs::Int32 selectedOutput;
00252 //      selectedOutput.data = _mrmControllerUi.controllableRobots->currentIndex();
00253 //      _setOutputPublisher.publish(selectedOutput);
00254 //
00255 //      _cmdvelSubscriber.shutdown();
00256 //
00257 //      if (selectedOutput.data - 1 >= 0)
00258 //              _cmdvelSubscriber = _node.subscribe(_outputTopics[selectedOutput.data - 1], 1, &MrRqt::onVelocityMessage, this);
00259 //
00260 //      _currentOutput = selectedOutput.data - 1;
00261 //
00262 //      refreshConfiguration();
00263 //}
00264 
00265 } /* namespace mrm_rqt */
00266 
00267 
00268 PLUGINLIB_EXPORT_CLASS(mr_rqt::MrRqt, rqt_gui_cpp::Plugin)


mr_rqt
Author(s): Igor Makhtes
autogenerated on Fri Aug 28 2015 11:35:38