flipper_control.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Dirk Thomas, TU Darmstadt
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  *   * Redistributions of source code must retain the above copyright
00010  *     notice, this list of conditions and the following disclaimer.
00011  *   * Redistributions in binary form must reproduce the above
00012  *     copyright notice, this list of conditions and the following
00013  *     disclaimer in the documentation and/or other materials provided
00014  *     with the distribution.
00015  *   * Neither the name of the TU Darmstadt nor the names of its
00016  *     contributors may be used to endorse or promote products derived
00017  *     from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00027  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00029  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  */
00032 
00033 #include <rqt_flipper_control/flipper_control.h>
00034 
00035 #include <pluginlib/class_list_macros.h>
00036 #include <sensor_msgs/JointState.h>
00037 
00038 #include <QMessageBox>
00039 
00040 namespace rqt_flipper_control {
00041 
00042 FlipperControl::FlipperControl()
00043     : rqt_gui_cpp::Plugin()
00044     , widget_(0)
00045 {
00046     setObjectName("FlipperControl");
00047 }
00048 
00049 void FlipperControl::initPlugin(qt_gui_cpp::PluginContext& context)
00050 {
00051     // access standalone command line arguments
00052     QStringList argv = context.argv();
00053     // create QWidget
00054     widget_ = new QWidget();
00055     // extend the widget with all attributes and children from UI file
00056     ui_.setupUi(widget_);
00057     // add widget to the user interface
00058     context.addWidget(widget_);
00059 
00060     ros::NodeHandle n;
00061 
00062    // flipperFrontSubs = n.subscribe("/flipper/state/front", 1000, &FlipperControl::frontFlipperCallback, this);
00063    // flipperRearSubs = n.subscribe("/flipper/state/rear", 1000, &FlipperControl::rearFlipperCallback, this);
00064 
00065     connect(ui_.sliderFront,SIGNAL(valueChanged(int)),this,SLOT(sliderFrontChanged(int)));
00066     connect(ui_.sliderRear,SIGNAL(valueChanged(int)),this,SLOT(sliderRearChanged(int)));
00067 
00068     this->jointStatePub = n.advertise<sensor_msgs::JointState>("/jointstate_cmd", 100);
00069 
00070 }
00071 
00072 void FlipperControl::shutdownPlugin()
00073 {
00074     // TODO unregister all publishers here
00075 }
00076 
00077 void FlipperControl::saveSettings(qt_gui_cpp::Settings& plugin_settings, qt_gui_cpp::Settings& instance_settings) const
00078 {
00079     // TODO save intrinsic configuration, usually using:
00080     // instance_settings.setValue(k, v)
00081 }
00082 
00083 void FlipperControl::restoreSettings(const qt_gui_cpp::Settings& plugin_settings, const qt_gui_cpp::Settings& instance_settings)
00084 {
00085 
00086 }
00087 
00088 void FlipperControl::frontFlipperCallback(const std_msgs::Float64::ConstPtr& msg){
00089     this->setFlipperFrontPose(msg->data);
00090 }
00091 
00092 void FlipperControl::rearFlipperCallback(const std_msgs::Float64::ConstPtr& msg){
00093     this->setFlipperRearPose(msg->data);
00094 }
00095 
00096 void FlipperControl::setFlipperFrontGoal(const int goal){
00097     ui_.lcdNumFrontGoal->display(goal);
00098 }
00099 
00100 void FlipperControl::setFlipperRearGoal(const int goal){
00101     ui_.lcdNumRearGoal->display(goal);
00102 }
00103 
00104 
00105 void FlipperControl::setFlipperFrontPose(const int pose){
00106     ui_.lcdNumFrontPose->display(pose);
00107 }
00108 
00109 void FlipperControl::setFlipperRearPose(const int pose){
00110     ui_.lcdNumRearPose->display(pose);
00111 }
00112 
00113 
00114 void FlipperControl::sliderFrontChanged(int value){
00115     float fvalue = value /1000.0;
00116     sensor_msgs::JointState msg;
00117     msg.name.push_back("flipper_front");
00118     msg.position.push_back(fvalue);
00119     this->jointStatePub.publish(msg);
00120 }
00121 
00122 void FlipperControl::sliderRearChanged(int value){
00123 
00124 }
00125 
00126 void FlipperControl::updateModel(){
00127 
00128 }
00129 
00130 }
00131 
00132 PLUGINLIB_EXPORT_CLASS(rqt_flipper_control::FlipperControl, rqt_gui_cpp::Plugin)


hector_rqt_plugins
Author(s): Dirk Thomas, Thorsten Graber, Gregor Gebhardt
autogenerated on Thu Jun 6 2019 22:10:05