00001 /****************************************************************************** 00002 * \file 00003 * \brief RVIZ plugin which provides simplified GUI based on Warehouse Viewer. 00004 * 00005 * $Id:$ 00006 * 00007 * Copyright (C) Brno University of Technology 00008 * 00009 * This file is part of software developed by dcgm-robotics@FIT group. 00010 * 00011 * Author: Zdenek Materna (imaterna@fit.vutbr.cz) 00012 * Supervised by: Michal Spanel (spanel@fit.vutbr.cz) 00013 * Date: 5/4/2012 00014 * 00015 * This file is free software: you can redistribute it and/or modify 00016 * it under the terms of the GNU Lesser General Public License as published by 00017 * the Free Software Foundation, either version 3 of the License, or 00018 * (at your option) any later version. 00019 * 00020 * This file is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU Lesser General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU Lesser General Public License 00026 * along with this file. If not, see <http://www.gnu.org/licenses/>. 00027 */ 00028 00029 #pragma once 00030 #ifndef BUT_GRASPING_H 00031 #define BUT_GRASPING_H 00032 00033 00034 #include <ros/ros.h> 00035 #include <string.h> 00036 00037 #include <wx/wx.h> 00038 #include <wx/menu.h> 00039 #include <wx/panel.h> 00040 #include <wx/dialog.h> 00041 #include <wx/msgdlg.h> 00042 #include <wx/sizer.h> 00043 #include <wx/radiobox.h> 00044 #include <wx/checkbox.h> 00045 #include <wx/thread.h> 00046 #include <wx/choice.h> 00047 00048 00049 #include "cob_script_server/ScriptAction.h" 00050 #include <actionlib/client/simple_action_client.h> 00051 #include <boost/thread.hpp> 00052 #include <boost/date_time/posix_time/posix_time.hpp> 00053 #include <map> 00054 #include <iostream> 00055 #include <sstream> 00056 00057 #include "srs_assisted_grasping_msgs/ReactiveGraspingAction.h" 00058 #include "srs_assisted_grasping_msgs/GraspingAllow.h" 00059 #include "srs_assisted_grasping/services_list.h" 00060 #include "srs_assisted_grasping/topics_list.h" 00061 00062 #include "schunk_sdh/TactileSensor.h" 00063 00064 namespace rviz 00065 { 00066 class WindowManagerInterface; 00067 } 00068 00069 namespace srs_assisted_grasping_ui { 00070 00071 static const double ABS_MAX_FORCE = 3000.0; 00072 static const bool WAIT_FOR_ALLOW = true; 00073 00074 struct Preset { 00075 00076 std::string name; 00077 std::vector<double> forces; 00078 std::vector<double> target_pos; 00079 ros::Duration time; 00080 00081 }; 00082 00083 00084 class CButGraspingControls : public wxPanel 00085 { 00086 public: 00088 CButGraspingControls(wxWindow *parent, const wxString& title, rviz::WindowManagerInterface * wmi ); 00089 ~CButGraspingControls(); 00090 00091 //void GraspingFeedback(const srs_assisted_grasping_msgs::ManualGraspingFeedbackConstPtr& feedback); 00092 void GraspingActive() {}; 00093 void GraspingDone(const actionlib::SimpleClientGoalState& state, 00094 const srs_assisted_grasping_msgs::ReactiveGraspingResultConstPtr& result); 00095 00096 00097 bool GraspingAllow(srs_assisted_grasping_msgs::GraspingAllow::Request &req, srs_assisted_grasping_msgs::GraspingAllow::Response &res); 00098 00099 00100 protected: 00101 00102 std::vector<Preset> presets_; 00103 00104 typedef actionlib::SimpleActionClient<srs_assisted_grasping_msgs::ReactiveGraspingAction> grasping_action_client; 00105 00107 rviz::WindowManagerInterface * m_wmi; 00108 00109 typedef std::map<std::string, wxButton *> ButtonsMap; 00110 00111 ButtonsMap buttons_; 00112 00113 wxWindow *parent_; 00114 00115 wxStaticText *m_text_status_; 00116 wxStaticText *m_text_max_force_; 00117 00118 wxSlider *max_force_slider_; 00119 00120 wxSlider *finger1_force_slider_; 00121 wxSlider *finger2_force_slider_; 00122 wxSlider *finger3_force_slider_; 00123 00124 wxChoice *presets_choice_; 00125 00126 00127 bool grasping_finished_; 00128 00129 bool grasping_allowed_; 00130 00131 void setButton(std::string but, bool state); 00132 00133 void OnStop(wxCommandEvent& event); 00134 void OnGrasp(wxCommandEvent& event); 00135 //void OnMaxForceSlider(wxCommandEvent& event); 00136 void OnChoice(wxCommandEvent& event); 00137 00138 void EnableControls(); // get ready for grasping 00139 void DisableControls(bool state_of_stop_button=false); 00140 00141 00142 bool wait_for_allow_; 00143 00144 double abs_max_force_; 00145 00146 grasping_action_client *as_client_; 00147 00148 void GraspingThread(); 00149 00150 boost::thread t_grasping; 00151 00152 ros::ServiceServer service_grasping_allow_; 00153 00154 ros::Subscriber tact_sub_; // for receiving tactile data 00155 00156 std::vector<int16_t> tactile_data_; 00157 boost::mutex tactile_data_mutex_; 00158 00159 void TactileDataCallback(const schunk_sdh::TactileSensor::ConstPtr& msg); 00160 00161 //void timerCallback(const ros::TimerEvent& ev); // timer for updating gui 00162 //ros::Timer gui_update_timer_; 00163 00164 boost::thread t_gui_update; 00165 void GuiUpdateThread(); 00166 00167 bool stop_gui_thread_; 00168 00169 bool tactile_data_received_; 00170 00171 private: 00172 00173 DECLARE_EVENT_TABLE(); 00174 00175 00176 }; 00177 00178 } // namespace 00179 00180 #endif // BUT_GRASPING_H