00001 // -*- mode: c++ -*- 00002 /********************************************************************* 00003 * Software License Agreement (BSD License) 00004 * 00005 * Copyright (c) 2014, JSK Lab 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/o2r other materials provided 00017 * with the distribution. 00018 * * Neither the name of the JSK Lab nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 *********************************************************************/ 00035 00036 00037 #ifndef JSK_RVIZ_PLUGINS_TABLET_CONTROLLER_PANEL_H_ 00038 #define JSK_RVIZ_PLUGINS_TABLET_CONTROLLER_PANEL_H_ 00039 00040 #ifndef Q_MOC_RUN 00041 #include <ros/ros.h> 00042 #include <rviz/panel.h> 00043 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) 00044 # include <QtWidgets> 00045 #else 00046 # include <QtGui> 00047 #endif 00048 #include <QPainter> 00049 #include <QLineEdit> 00050 #include <QPushButton> 00051 #include <QVBoxLayout> 00052 #include <QHBoxLayout> 00053 #include <QDialog> 00054 #include <QListWidget> 00055 #include <QListWidgetItem> 00056 #include <QLabel> 00057 #include <QTimer> 00058 #include <QRadioButton> 00059 #include <QPaintEvent> 00060 #include <QMouseEvent> 00061 #include <geometry_msgs/Twist.h> 00062 #include <jsk_rviz_plugins/StringStamped.h> 00063 #include <visualization_msgs/MarkerArray.h> 00064 #include <boost/thread.hpp> 00065 #endif 00066 00067 namespace jsk_rviz_plugins 00068 { 00069 class TabletCmdVelArea: public QWidget 00070 { 00071 Q_OBJECT 00072 public: 00073 TabletCmdVelArea(QWidget* parent, ros::Publisher& pub_cmd_vel); 00074 virtual QSize minimumSizeHint() const; 00075 virtual QSize sizeHint() const; 00076 protected: 00077 virtual void paintEvent(QPaintEvent* event); 00078 virtual void mouseMoveEvent(QMouseEvent* event); 00079 virtual void mousePressEvent(QMouseEvent* event); 00080 virtual void mouseReleaseEvent(QMouseEvent* event); 00081 virtual void publishVelocity(int mouse_x, int mouse_y, int cx, int cy); 00082 virtual void publishCmdVel(double x, double y, double theta); 00083 int mouse_x_; 00084 int mouse_y_; 00085 ros::Publisher pub_cmd_vel_; 00086 }; 00087 00088 class TabletControllerPanel: public rviz::Panel 00089 { 00090 Q_OBJECT 00091 public: 00092 TabletControllerPanel(QWidget* parent = 0); 00093 virtual ~TabletControllerPanel(); 00094 virtual void load(const rviz::Config& config); 00095 virtual void save(rviz::Config config) const; 00096 00097 protected: 00099 // methods 00101 virtual void spotCallback( 00102 const visualization_msgs::MarkerArray::ConstPtr& marker); 00103 virtual QString defaultButtonStyleSheet(); 00104 virtual QString executeButtonStyleSheet(); 00105 virtual QString radioButtonStyleSheet(); 00106 virtual QString listStyleSheet(); 00108 // GUI variables 00110 00111 QVBoxLayout* layout_; 00112 QPushButton* task_button_; 00113 QPushButton* spot_button_; 00114 TabletCmdVelArea* cmd_vel_area_; 00115 00116 QDialog* task_dialog_; 00117 QVBoxLayout* task_dialog_layout_; 00118 QHBoxLayout* task_dialog_button_layout_; 00119 QPushButton* task_execute_button_; 00120 QPushButton* task_cancel_button_; 00121 std::vector<QRadioButton*> task_radio_buttons_; 00122 00123 std::vector<std::string> spots_; 00124 QDialog* spot_dialog_; 00125 QVBoxLayout* spot_dialog_layout_; 00126 QHBoxLayout* spot_dialog_button_layout_; 00127 QPushButton* spot_go_button_; 00128 QPushButton* spot_cancel_button_; 00129 QListWidget* spot_list_; 00131 // ROS variables 00133 ros::Publisher pub_cmd_vel_; 00134 ros::Publisher pub_spot_; 00135 ros::Publisher pub_start_demo_; 00136 ros::Subscriber sub_spots_; 00137 boost::mutex mutex_; 00138 00139 00140 protected Q_SLOTS: 00142 // callbacks 00144 void taskButtonClicked(); 00145 void taskCancelClicked(); 00146 void taskExecuteClicked(); 00147 void spotButtonClicked(); 00148 void spotGoClicked(); 00149 void spotCancelClicked(); 00150 private: 00151 00152 }; 00153 } 00154 00155 #endif