00001 /**************************************************************** 00002 * 00003 * Copyright (c) 2010 00004 * 00005 * Fraunhofer Institute for Manufacturing Engineering 00006 * and Automation (IPA) 00007 * 00008 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: care-o-bot 00011 * ROS stack name: cob_3d_environment_perception_intern 00012 * ROS package name: cob_3d_mapping_demonstrator 00013 * Description: Feature Map for storing and handling geometric features 00014 * 00015 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00016 * 00017 * Author: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de 00018 * Supervised by: Georg Arbeiter, email:georg.arbeiter@ipa.fhg.de 00019 * 00020 * Date of creation: 03/2012 00021 * ToDo: 00022 * 00023 * 00024 * 00025 * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00026 * 00027 * Redistribution and use in source and binary forms, with or without 00028 * modification, are permitted provided that the following conditions are met: 00029 * 00030 * * Redistributions of source code must retain the above copyright 00031 * notice, this list of conditions and the following disclaimer. 00032 * * Redistributions in binary form must reproduce the above copyright 00033 * notice, this list of conditions and the following disclaimer in the 00034 * documentation and/or other materials provided with the distribution. 00035 * * Neither the name of the Fraunhofer Institute for Manufacturing 00036 * Engineering and Automation (IPA) nor the names of its 00037 * contributors may be used to endorse or promote products derived from 00038 * this software without specific prior written permission. 00039 * 00040 * This program is free software: you can redistribute it and/or modify 00041 * it under the terms of the GNU Lesser General Public License LGPL as 00042 * published by the Free Software Foundation, either version 3 of the 00043 * License, or (at your option) any later version. 00044 * 00045 * This program is distributed in the hope that it will be useful, 00046 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00047 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00048 * GNU Lesser General Public License LGPL for more details. 00049 * 00050 * You should have received a copy of the GNU Lesser General Public 00051 * License LGPL along with this program. 00052 * If not, see <http://www.gnu.org/licenses/>. 00053 * 00054 ****************************************************************/ 00055 00056 #include "cob_3d_mapping_demonstrator/wx_rviz_buttons_panel.h" 00057 #include <wx/sizer.h> 00058 00059 using namespace std; 00060 00061 00062 namespace rviz 00063 { 00064 00065 const int ID_BUTTON_START(101); 00066 const int ID_BUTTON_STEP(106); 00067 const int ID_BUTTON_STOP(102); 00068 const int ID_BUTTON_RESET(103); 00069 const int ID_BUTTON_CLEAR(104); 00070 const int ID_BUTTON_RECOVER(105); 00071 00072 RvizButtonsPanel::~RvizButtonsPanel() { 00073 00074 } 00075 00079 RvizButtonsPanel::RvizButtonsPanel(wxWindow *parent, const wxString& title/*, rviz::WindowManagerInterface * wmi */) 00080 : wxPanel( parent, wxID_ANY, wxDefaultPosition, wxSize(280, 180), wxTAB_TRAVERSAL, title) 00081 //, m_wmi( wmi ) 00082 { 00083 //parent_ = parent; 00084 00085 button_start_ = new wxButton(this, ID_BUTTON_START, wxT("Start"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00086 button_step_ = new wxButton(this, ID_BUTTON_STEP, wxT("Step"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00087 //button_stop_ = new wxButton(this, ID_BUTTON_STOP, wxT("Stop"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00088 button_reset_ = new wxButton(this, ID_BUTTON_RESET, wxT("Reset"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00089 button_clear_ = new wxButton(this, ID_BUTTON_CLEAR, wxT("Clear"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00090 button_recover_ = new wxButton(this, ID_BUTTON_RECOVER, wxT("Recover"),wxDefaultPosition,wxDefaultSize,wxBU_EXACTFIT); 00091 00092 /*m_text_status = new wxStaticText(this, -1, wxT("status: waiting")); 00093 m_text_object = new wxStaticText(this, -1, wxT("object: none")); 00094 m_text_timeout = new wxStaticText(this, -1, wxT("timeout: none")); 00095 m_text_dist = new wxStaticText(this, -1, wxT("closest pos.: none"));*/ 00096 00097 button_start_->Enable(true); 00098 button_step_->Enable(true); 00099 //button_stop_->Enable(true); 00100 button_reset_->Enable(true); 00101 button_clear_->Enable(true); 00102 button_recover_->Enable(true); 00103 00104 wxSizer *vsizer = new wxBoxSizer(wxVERTICAL); // top sizer 00105 00106 00107 /*wxSizer *vsizer_top = new wxStaticBoxSizer(wxVERTICAL,this,wxT("Trajectory planning")); 00108 wxSizer *hsizer_traj_top = new wxBoxSizer(wxHORIZONTAL); 00109 wxSizer *hsizer_traj_mid = new wxBoxSizer(wxHORIZONTAL); 00110 wxSizer *hsizer_traj_bot = new wxBoxSizer(wxHORIZONTAL);*/ 00111 00112 00113 //wxSizer *vsizer_mes = new wxStaticBoxSizer(wxVERTICAL,this,wxT("Messages")); 00114 00115 //wxSizer *hsizer_add = new wxStaticBoxSizer(wxHORIZONTAL,this,wxT("Additional controls")); 00116 00117 00118 /* Trajectory planning related buttons, on top*/ 00119 vsizer->Add(button_start_, ID_BUTTON_START, wxEXPAND); 00120 //vsizer->Add(button_stop_, ID_BUTTON_STOP, wxEXPAND); 00121 vsizer->Add(button_step_, ID_BUTTON_STEP, wxEXPAND); 00122 vsizer->Add(button_reset_, ID_BUTTON_RESET, wxEXPAND); 00123 vsizer->Add(button_clear_, ID_BUTTON_CLEAR, wxEXPAND); 00124 vsizer->Add(button_recover_, ID_BUTTON_RECOVER, wxEXPAND); 00125 00126 00127 /* Status messages*/ 00128 /*vsizer_mes->Add(m_text_status); 00129 vsizer_mes->Add(m_text_object); 00130 vsizer_mes->Add(m_text_timeout); 00131 vsizer_mes->Add(m_text_dist);*/ 00132 00133 00134 vsizer->SetSizeHints(this); 00135 this->SetSizerAndFit(vsizer); 00136 00137 //ros::NodeHandle nh; 00138 //service_start_ = nh.advertiseService("arm_nav_start",&RvizButtons::nav_start,this); 00139 action_client_ = new actionlib::SimpleActionClient<cob_script_server::ScriptAction>("cob_3d_mapping_demonstrator", true); 00140 00141 } 00143 00144 void RvizButtonsPanel::OnStart(wxCommandEvent& event) 00145 { 00146 00147 ROS_INFO("On start"); 00148 cob_script_server::ScriptGoal goal; 00149 goal.function_name = "start"; 00150 // Fill in goal here 00151 action_client_->sendGoal(goal); 00152 action_client_->waitForResult(ros::Duration(1.0)); 00153 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00154 ROS_INFO("Demonstrator was started"); 00155 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str()); 00156 } 00157 00158 void RvizButtonsPanel::OnStep(wxCommandEvent& event) 00159 { 00160 00161 ROS_INFO("On step"); 00162 cob_script_server::ScriptGoal goal; 00163 goal.function_name = "step"; 00164 // Fill in goal here 00165 action_client_->sendGoal(goal); 00166 action_client_->waitForResult(ros::Duration(1.0)); 00167 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00168 ROS_INFO("Demonstrator step"); 00169 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str()); 00170 } 00171 00172 void RvizButtonsPanel::OnStop(wxCommandEvent& event) 00173 { 00174 00175 ROS_INFO("On stop"); 00176 /*cob_script_server::ScriptGoal goal; 00177 goal.function_name = "stop"; 00178 // Fill in goal here 00179 action_client_->sendGoal(goal); 00180 action_client_->waitForResult(ros::Duration(1.0)); 00181 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00182 ROS_INFO("Demonstrator was recovered"); 00183 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str());*/ 00184 action_client_->cancelGoal(); 00185 /*srs_ui_but::ArmNavNew srv; 00186 00187 if ( ros::service::exists("arm_nav_plan",true) && ros::service::call("arm_nav_plan",srv) ) { 00188 00189 if (srv.response.completed) { 00190 00191 m_button_new->Enable(false); 00192 m_button_plan->Enable(false); 00193 m_button_play->Enable(true); 00194 m_button_execute->Enable(true); 00195 //m_button_finish->Enable(false); 00196 m_button_success->Enable(false); 00197 m_button_failed->Enable(true); 00198 00199 m_text_status->SetLabel(wxString::FromAscii("status: Trajectory is ready")); 00200 00201 } else { 00202 00203 m_text_status->SetLabel(wxString::FromAscii(srv.response.error.c_str())); 00204 00205 } 00206 00207 } else { 00208 00209 ROS_ERROR("failed when calling arm_nav_plan service"); 00210 m_text_status->SetLabel(wxString::FromAscii("Communication error")); 00211 00212 }*/ 00213 00214 00215 } 00216 00217 void RvizButtonsPanel::OnReset(wxCommandEvent& event) 00218 { 00219 00220 ROS_INFO("On reset"); 00221 cob_script_server::ScriptGoal goal; 00222 goal.function_name = "reset"; 00223 // Fill in goal here 00224 action_client_->sendGoal(goal); 00225 action_client_->waitForResult(ros::Duration(1.0)); 00226 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00227 ROS_INFO("Demonstrator was recovered"); 00228 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str()); 00229 00230 /*srs_ui_but::ArmNavNew srv; 00231 00232 if ( ros::service::exists("arm_nav_play",true) && ros::service::call("arm_nav_play",srv) ) { 00233 00234 if (srv.response.completed) { 00235 00236 m_button_new->Enable(false); 00237 m_button_plan->Enable(false); 00238 m_button_execute->Enable(true); 00239 //m_button_finish->Enable(false); 00240 m_button_success->Enable(false); 00241 m_button_failed->Enable(true); 00242 00243 m_text_status->SetLabel(wxString::FromAscii("status: Playing trajectory...")); 00244 00245 } else { 00246 00247 m_text_status->SetLabel(wxString::FromAscii(srv.response.error.c_str())); 00248 00249 } 00250 00251 } else { 00252 00253 ROS_ERROR("failed when calling arm_nav_play service"); 00254 m_text_status->SetLabel(wxString::FromAscii("status: Communication error")); 00255 00256 }*/ 00257 00258 } 00259 00260 void RvizButtonsPanel::OnClear(wxCommandEvent& event) 00261 { 00262 ROS_INFO("On clear"); 00263 cob_script_server::ScriptGoal goal; 00264 goal.function_name = "clear"; 00265 // Fill in goal here 00266 action_client_->sendGoal(goal); 00267 action_client_->waitForResult(ros::Duration(1.0)); 00268 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00269 ROS_INFO("Demonstrator was recovered"); 00270 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str()); 00271 00272 /*srs_ui_but::ArmNavNew srv; 00273 00274 if ( ros::service::exists("arm_nav_execute",true) && ros::service::call("arm_nav_execute",srv) ) { 00275 00276 if (srv.response.completed) { 00277 00278 m_button_plan->Enable(false); 00279 m_button_execute->Enable(false); 00280 m_button_reset->Enable(false); 00281 m_button_play->Enable(false); 00282 m_button_new->Enable(false); 00283 //m_button_finish->Enable(true); 00284 m_button_success->Enable(true); 00285 m_button_failed->Enable(true); 00286 00287 m_text_status->SetLabel(wxString::FromAscii("status: Executing trajectory...")); 00288 00289 } else { 00290 00291 m_text_status->SetLabel(wxString::FromAscii(srv.response.error.c_str())); 00292 00293 } 00294 00295 } else { 00296 00297 ROS_ERROR("failed when calling arm_nav_execute service"); 00298 m_text_status->SetLabel(wxString::FromAscii("Communication error")); 00299 00300 }*/ 00301 00302 } 00303 00304 void RvizButtonsPanel::OnRecover(wxCommandEvent& event) 00305 { 00306 ROS_INFO("On recover"); 00307 cob_script_server::ScriptGoal goal; 00308 goal.function_name = "recover"; 00309 // Fill in goal here 00310 action_client_->sendGoal(goal); 00311 action_client_->waitForResult(ros::Duration(1.0)); 00312 if (action_client_->getState() == actionlib::SimpleClientGoalState::SUCCEEDED) 00313 ROS_INFO("Demonstrator was recovered"); 00314 ROS_INFO("Current State: %s\n", action_client_->getState().toString().c_str()); 00315 00316 /*srs_ui_but::ArmNavNew srv; 00317 00318 if ( ros::service::exists("arm_nav_reset",true) && ros::service::call("arm_nav_reset",srv) ) { 00319 00320 if (srv.response.completed) { 00321 00322 m_button_plan->Enable(false); 00323 m_button_execute->Enable(false); 00324 m_button_reset->Enable(false); 00325 m_button_play->Enable(false); 00326 m_button_new->Enable(true); 00327 //m_button_finish->Enable(true); 00328 m_button_success->Enable(false); 00329 m_button_failed->Enable(true); 00330 00331 // TODO: vratit rameno do puvodni polohy!!!!! 00332 00333 m_text_status->SetLabel(wxString::FromAscii("status: Ok, try it again")); 00334 00335 } else { 00336 00337 m_text_status->SetLabel(wxString::FromAscii(srv.response.error.c_str())); 00338 00339 } 00340 00341 } else { 00342 00343 ROS_ERROR("failed when calling arm_nav_reset service"); 00344 m_text_status->SetLabel(wxString::FromAscii("status: Communication error")); 00345 00346 m_button_plan->Enable(false); 00347 m_button_execute->Enable(false); 00348 m_button_reset->Enable(false); 00349 m_button_play->Enable(false); 00350 m_button_new->Enable(true); 00351 //m_button_finish->Enable(false); 00352 m_button_success->Enable(false); 00353 m_button_failed->Enable(true); 00354 00355 }*/ 00356 00357 } 00358 00359 00360 00362 00363 00365 BEGIN_EVENT_TABLE(RvizButtonsPanel, wxPanel) 00366 EVT_BUTTON(ID_BUTTON_START, RvizButtonsPanel::OnStart) 00367 EVT_BUTTON(ID_BUTTON_STEP, RvizButtonsPanel::OnStep) 00368 EVT_BUTTON(ID_BUTTON_STOP, RvizButtonsPanel::OnStop) 00369 EVT_BUTTON(ID_BUTTON_RESET, RvizButtonsPanel::OnReset) 00370 EVT_BUTTON(ID_BUTTON_CLEAR, RvizButtonsPanel::OnClear) 00371 EVT_BUTTON(ID_BUTTON_RECOVER, RvizButtonsPanel::OnRecover) 00372 END_EVENT_TABLE() 00373 }