00001 #include <ros/ros.h>
00002
00003 #include <tf/tf.h>
00004 #include <tf/transform_listener.h>
00005 #include <tf/transform_broadcaster.h>
00006
00007 #include <interactive_markers/interactive_marker_server.h>
00008 #include <jsk_interactive_marker/interactive_marker_helpers.h>
00009
00010 #include <interactive_markers/menu_handler.h>
00011 #include <jsk_interactive_marker/SetPose.h>
00012 #include <jsk_interactive_marker/MarkerSetPose.h>
00013
00014 #include <math.h>
00015 #include <jsk_interactive_marker/MarkerMenu.h>
00016 #include <jsk_interactive_marker/MarkerPose.h>
00017
00018 #include <std_msgs/Int8.h>
00019
00020 #include <jsk_interactive_marker/interactive_marker_interface.h>
00021 #include <jsk_interactive_marker/interactive_marker_utils.h>
00022
00023 #include <dynamic_tf_publisher/SetDynamicTF.h>
00024
00025 visualization_msgs::InteractiveMarker InteractiveMarkerInterface::make6DofControlMarker( std::string name, geometry_msgs::PoseStamped &stamped, float scale, bool fixed_position, bool fixed_rotation){
00026
00027 visualization_msgs::InteractiveMarker int_marker;
00028 int_marker.header = stamped.header;
00029 int_marker.name = name;
00030 int_marker.scale = scale;
00031 int_marker.pose = stamped.pose;
00032
00033 visualization_msgs::InteractiveMarkerControl control;
00034
00035
00036 if(fixed_rotation){
00037 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00038 }else{
00039 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00040 }
00041
00042 control.orientation.w = 1;
00043 control.orientation.x = 1;
00044 control.orientation.y = 0;
00045 control.orientation.z = 0;
00046 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00047 int_marker.controls.push_back(control);
00048
00049 if(fixed_position){
00050 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00051 }else{
00052 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00053 }
00054
00055 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00056 int_marker.controls.push_back(control);
00057
00058
00059
00060 if(fixed_rotation){
00061 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00062 }else{
00063 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00064 }
00065 control.orientation.w = 1;
00066 control.orientation.x = 0;
00067 control.orientation.y = 1;
00068 control.orientation.z = 0;
00069 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00070 int_marker.controls.push_back(control);
00071
00072 if(fixed_position){
00073 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00074 }else{
00075 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00076 }
00077
00078 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00079 int_marker.controls.push_back(control);
00080
00081
00082 if(fixed_rotation){
00083 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00084 }else{
00085 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00086 }
00087
00088 control.orientation.w = 1;
00089 control.orientation.x = 0;
00090 control.orientation.y = 0;
00091 control.orientation.z = 1;
00092 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00093 int_marker.controls.push_back(control);
00094 if(fixed_position){
00095 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00096 }else{
00097 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::INHERIT;
00098 }
00099 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00100 int_marker.controls.push_back(control);
00101
00102 return int_marker;
00103 }
00104
00105
00106
00107 void InteractiveMarkerInterface::proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ) {
00108 if(feedback->control_name == "center_sphere"){
00109 proc_feedback(feedback, jsk_interactive_marker::MarkerPose::SPHERE_MARKER);
00110 }else{
00111 proc_feedback(feedback, jsk_interactive_marker::MarkerPose::GENERAL);
00112 }
00113
00114 }
00115
00116 void InteractiveMarkerInterface::proc_feedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int type ) {
00117
00118 jsk_interactive_marker::MarkerPose mp;
00119 mp.pose.header = feedback->header;
00120 mp.pose.pose = feedback->pose;
00121 mp.marker_name = feedback->marker_name;
00122 mp.type = type;
00123 pub_.publish( mp );
00124
00125
00126 control_state_.marker_pose_.pose = feedback->pose;
00127 control_state_.marker_pose_.header = feedback->header;
00128
00129 pub_marker_tf(feedback->header, feedback->pose);
00130
00131 }
00132
00133 void InteractiveMarkerInterface::pub_marker_tf ( std_msgs::Header header, geometry_msgs::Pose pose){
00134 geometry_msgs::Transform tf;
00135 tf.translation.x = pose.position.x;
00136 tf.translation.y = pose.position.y;
00137 tf.translation.z = pose.position.z;
00138 tf.rotation = pose.orientation;
00139
00140 dynamic_tf_publisher::SetDynamicTF SetTf;
00141 SetTf.request.freq = 10;
00142 SetTf.request.cur_tf.header.stamp = ros::Time::now();
00143 SetTf.request.cur_tf.header.frame_id = header.frame_id;
00144 SetTf.request.cur_tf.child_frame_id = "/moving_marker";
00145 SetTf.request.cur_tf.transform = tf;
00146 dynamic_tf_publisher_client_.call(SetTf);
00147 }
00148
00149 void InteractiveMarkerInterface::pub_marker_pose ( std_msgs::Header header, geometry_msgs::Pose pose, std::string name, int type ) {
00150 jsk_interactive_marker::MarkerPose mp;
00151 mp.pose.header = header;
00152 mp.pose.pose = pose;
00153 mp.marker_name = name;
00154 mp.type = type;
00155 pub_.publish( mp );
00156 }
00157
00158
00159
00160
00161 void InteractiveMarkerInterface::pub_marker_menuCb(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu){
00162 jsk_interactive_marker::MarkerMenu m;
00163 m.marker_name = feedback->marker_name;
00164 m.menu=menu;
00165 pub_move_.publish(m);
00166 }
00167
00168 void InteractiveMarkerInterface::pub_marker_menuCb(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, int menu, int type){
00169 jsk_interactive_marker::MarkerMenu m;
00170 m.marker_name = feedback->marker_name;
00171 m.menu = menu;
00172 m.type = type;
00173 pub_move_.publish(m);
00174 }
00175
00176
00177 void InteractiveMarkerInterface::pub_marker_menu(std::string marker, int menu, int type){
00178 jsk_interactive_marker::MarkerMenu m;
00179 m.marker_name = marker;
00180 m.menu=menu;
00181 m.type = type;
00182 pub_move_.publish(m);
00183 }
00184
00185 void InteractiveMarkerInterface::pub_marker_menu(std::string marker, int menu){
00186 pub_marker_menu(marker, menu, 0);
00187 }
00188
00189 void InteractiveMarkerInterface::IMSizeLargeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00190 geometry_msgs::PoseStamped pose;
00191 pose.header = feedback->header;
00192 pose.pose = feedback->pose;
00193 changeMarkerMoveMode(feedback->marker_name, 0, 0.5, pose);
00194 }
00195
00196 void InteractiveMarkerInterface::IMSizeMiddleCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00197 geometry_msgs::PoseStamped pose;
00198 pose.header = feedback->header;
00199 pose.pose = feedback->pose;
00200 changeMarkerMoveMode(feedback->marker_name, 0, 0.3, pose);
00201 }
00202
00203 void InteractiveMarkerInterface::IMSizeSmallCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00204 geometry_msgs::PoseStamped pose;
00205 pose.header = feedback->header;
00206 pose.pose = feedback->pose;
00207 changeMarkerMoveMode(feedback->marker_name, 0, 0.1, pose);
00208 }
00209
00210 void InteractiveMarkerInterface::changeMoveModeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00211 changeMarkerMoveMode(feedback->marker_name,0);
00212 pub_marker_menu(feedback->marker_name,13);
00213
00214 }
00215 void InteractiveMarkerInterface::changeMoveModeCb1( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00216 changeMarkerMoveMode(feedback->marker_name,1);
00217 pub_marker_menu(feedback->marker_name,13);
00218
00219 }
00220 void InteractiveMarkerInterface::changeMoveModeCb2( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00221 changeMarkerMoveMode(feedback->marker_name,2);
00222 pub_marker_menu(feedback->marker_name,13);
00223 }
00224
00225 void InteractiveMarkerInterface::changeForceModeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00226 ROS_INFO("%s changeForceMode",feedback->marker_name.c_str());
00227 changeMarkerForceMode(feedback->marker_name,0);
00228 pub_marker_menu(feedback->marker_name,12);
00229
00230 }
00231 void InteractiveMarkerInterface::changeForceModeCb1( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00232 ROS_INFO("%s changeForceMode1",feedback->marker_name.c_str());
00233 changeMarkerForceMode(feedback->marker_name,1);
00234 pub_marker_menu(feedback->marker_name,12);
00235
00236 }
00237 void InteractiveMarkerInterface::changeForceModeCb2( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00238 ROS_INFO("%s changeForceMode2",feedback->marker_name.c_str());
00239 changeMarkerForceMode(feedback->marker_name,2);
00240 pub_marker_menu(feedback->marker_name,12);
00241 }
00242
00243 void InteractiveMarkerInterface::targetPointMenuCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00244 ROS_INFO("targetPointMenu callback");
00245
00246 control_state_.head_on_ ^= true;
00247 control_state_.init_head_goal_ = true;
00248
00249 if(control_state_.head_on_){
00250 menu_head_.setCheckState(head_target_handle_, interactive_markers::MenuHandler::CHECKED);
00251 control_state_.look_auto_on_ = false;
00252 menu_head_.setCheckState(head_auto_look_handle_, interactive_markers::MenuHandler::UNCHECKED);
00253 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::HEAD_TARGET_POINT, jsk_interactive_marker::MarkerMenu::HEAD_MARKER);
00254 }else{
00255 menu_head_.setCheckState(head_target_handle_, interactive_markers::MenuHandler::UNCHECKED);
00256 }
00257 menu_head_.reApply(*server_);
00258
00259 initControlMarkers();
00260 }
00261
00262 void InteractiveMarkerInterface::lookAutomaticallyMenuCB( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback ){
00263 ROS_INFO("targetPointMenu callback");
00264
00265 control_state_.head_on_ = false;
00266 control_state_.look_auto_on_ ^= true;
00267 control_state_.init_head_goal_ = true;
00268
00269 if(control_state_.look_auto_on_){
00270 menu_head_.setCheckState(head_auto_look_handle_, interactive_markers::MenuHandler::CHECKED);
00271 menu_head_.setCheckState(head_target_handle_, interactive_markers::MenuHandler::UNCHECKED);
00272 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::PUBLISH_MARKER, jsk_interactive_marker::MarkerMenu::HEAD_MARKER);
00273 }else{
00274 menu_head_.setCheckState(head_auto_look_handle_, interactive_markers::MenuHandler::UNCHECKED);
00275 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::HEAD_TARGET_POINT, jsk_interactive_marker::MarkerMenu::HEAD_MARKER);
00276 }
00277 menu_head_.reApply(*server_);
00278 initControlMarkers();
00279 }
00280
00281
00282 void InteractiveMarkerInterface::ConstraintCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00283 {
00284 menu_handler.setCheckState( h_mode_last2, interactive_markers::MenuHandler::UNCHECKED );
00285 h_mode_last2 = feedback->menu_entry_id;
00286 menu_handler.setCheckState( h_mode_last2, interactive_markers::MenuHandler::CHECKED );
00287
00288 switch(h_mode_last2-h_mode_constrained){
00289 case 0:
00290 pub_marker_menu(feedback->marker_name,jsk_interactive_marker::MarkerMenu::MOVE_CONSTRAINT_T);
00291 ROS_INFO("send 23");
00292 break;
00293 case 1:
00294 pub_marker_menu(feedback->marker_name,jsk_interactive_marker::MarkerMenu::MOVE_CONSTRAINT_NIL);
00295 ROS_INFO("send 24");
00296 break;
00297 default:
00298 ROS_INFO("Switching Arm Error");
00299 break;
00300 }
00301
00302 menu_handler.reApply( *server_ );
00303 server_->applyChanges();
00304
00305 }
00306
00307 void InteractiveMarkerInterface::useTorsoCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00308 {
00309 if(feedback->menu_entry_id == use_torso_t_menu_){
00310 menu_handler.setCheckState( use_torso_t_menu_ , interactive_markers::MenuHandler::CHECKED );
00311 menu_handler.setCheckState( use_torso_nil_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00312 menu_handler.setCheckState( use_fullbody_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00313 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::USE_TORSO_T);
00314 }else if(feedback->menu_entry_id == use_torso_nil_menu_){
00315 menu_handler.setCheckState( use_torso_t_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00316 menu_handler.setCheckState( use_torso_nil_menu_ , interactive_markers::MenuHandler::CHECKED );
00317 menu_handler.setCheckState( use_fullbody_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00318 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::USE_TORSO_NIL);
00319 }else{
00320 menu_handler.setCheckState( use_torso_t_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00321 menu_handler.setCheckState( use_torso_nil_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00322 menu_handler.setCheckState( use_fullbody_menu_ , interactive_markers::MenuHandler::CHECKED );
00323 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::USE_FULLBODY);
00324 }
00325 menu_handler.reApply( *server_ );
00326 server_->applyChanges();
00327
00328 }
00329
00330 void InteractiveMarkerInterface::usingIKCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00331 {
00332 if(feedback->menu_entry_id == start_ik_menu_){
00333 menu_handler.setCheckState( start_ik_menu_ , interactive_markers::MenuHandler::CHECKED );
00334 menu_handler.setCheckState( stop_ik_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00335 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::PLAN);
00336 }else if(feedback->menu_entry_id == stop_ik_menu_){
00337 menu_handler.setCheckState( start_ik_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00338 menu_handler.setCheckState( stop_ik_menu_ , interactive_markers::MenuHandler::CHECKED );
00339 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::CANCEL_PLAN);
00340 }
00341 menu_handler.reApply( *server_ );
00342 server_->applyChanges();
00343
00344 }
00345
00346 void InteractiveMarkerInterface::toggleStartIKCb( const std_msgs::EmptyConstPtr &msg)
00347 {
00348 interactive_markers::MenuHandler::CheckState check_state;
00349 if(menu_handler.getCheckState( start_ik_menu_ , check_state)){
00350
00351 if(check_state == interactive_markers::MenuHandler::CHECKED){
00352
00353 menu_handler.setCheckState( start_ik_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00354 menu_handler.setCheckState( stop_ik_menu_ , interactive_markers::MenuHandler::CHECKED );
00355 pub_marker_menu("", jsk_interactive_marker::MarkerMenu::CANCEL_PLAN);
00356
00357 }else{
00358
00359 menu_handler.setCheckState( start_ik_menu_ , interactive_markers::MenuHandler::CHECKED );
00360 menu_handler.setCheckState( stop_ik_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00361 pub_marker_menu("" , jsk_interactive_marker::MarkerMenu::PLAN);
00362 }
00363
00364 menu_handler.reApply( *server_ );
00365 server_->applyChanges();
00366 }
00367 }
00368
00369
00370 void InteractiveMarkerInterface::modeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00371 {
00372 menu_handler.setCheckState( h_mode_last, interactive_markers::MenuHandler::UNCHECKED );
00373 h_mode_last = feedback->menu_entry_id;
00374 menu_handler.setCheckState( h_mode_last, interactive_markers::MenuHandler::CHECKED );
00375
00376 switch(h_mode_last - h_mode_rightarm){
00377 case 0:
00378 changeMoveArm( feedback->marker_name, jsk_interactive_marker::MarkerMenu::SET_MOVE_RARM);
00379 break;
00380 case 1:
00381 changeMoveArm( feedback->marker_name, jsk_interactive_marker::MarkerMenu::SET_MOVE_LARM);
00382 break;
00383 case 2:
00384 changeMoveArm( feedback->marker_name, jsk_interactive_marker::MarkerMenu::SET_MOVE_ARMS);
00385 break;
00386 default:
00387 ROS_INFO("Switching Arm Error");
00388 break;
00389 }
00390 menu_handler.reApply( *server_ );
00391 server_->applyChanges();
00392 }
00393
00394 void InteractiveMarkerInterface::changeMoveArm( std::string m_name, int menu ){
00395 switch(menu){
00396 case jsk_interactive_marker::MarkerMenu::SET_MOVE_RARM:
00397 pub_marker_menu(m_name,jsk_interactive_marker::MarkerMenu::SET_MOVE_RARM);
00398 control_state_.move_arm_ = ControlState::RARM;
00399 ROS_INFO("move Rarm");
00400 changeMarkerMoveMode( marker_name.c_str(), 0, 0.5, control_state_.marker_pose_);
00401 break;
00402 case jsk_interactive_marker::MarkerMenu::SET_MOVE_LARM:
00403 pub_marker_menu(m_name,jsk_interactive_marker::MarkerMenu::SET_MOVE_LARM);
00404 control_state_.move_arm_ = ControlState::LARM;
00405 ROS_INFO("move Larm");
00406 changeMarkerMoveMode( marker_name.c_str(), 0, 0.5, control_state_.marker_pose_);
00407 break;
00408 case jsk_interactive_marker::MarkerMenu::SET_MOVE_ARMS:
00409 pub_marker_menu(m_name,jsk_interactive_marker::MarkerMenu::SET_MOVE_ARMS);
00410 control_state_.move_arm_ = ControlState::ARMS;
00411 ROS_INFO("move Arms");
00412 changeMarkerMoveMode( marker_name.c_str(), 0, 0.5, control_state_.marker_pose_);
00413 break;
00414 default:
00415 ROS_INFO("Switching Arm Error");
00416 break;
00417 }
00418 }
00419
00420 void InteractiveMarkerInterface::setOriginCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, bool origin_hand){
00421 if(origin_hand){
00422 control_state_.move_origin_state_ = ControlState::HAND_ORIGIN;
00423 changeMarkerMoveMode( marker_name.c_str(), 0, 0.5, control_state_.marker_pose_);
00424 if(control_state_.move_arm_ == ControlState::RARM){
00425 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::SET_ORIGIN_RHAND);}else{
00426 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::SET_ORIGIN_LHAND);}
00427 }else{
00428 control_state_.move_origin_state_ = ControlState::DESIGNATED_ORIGIN;
00429 changeMarkerMoveMode( marker_name.c_str(), 0, 0.5, control_state_.marker_pose_);
00430 pub_marker_menuCb(feedback, jsk_interactive_marker::MarkerMenu::SET_ORIGIN);
00431 }
00432
00433
00434 }
00435
00436
00437 void InteractiveMarkerInterface::ikmodeCb( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback )
00438 {
00439
00440
00441
00442
00443 if(feedback->menu_entry_id == rotation_t_menu_){
00444 menu_handler.setCheckState( rotation_nil_menu_, interactive_markers::MenuHandler::UNCHECKED );
00445 pub_marker_menu(feedback->marker_name,jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_T);
00446 ROS_INFO("Rotation Axis T");
00447 }else{
00448 menu_handler.setCheckState( rotation_t_menu_, interactive_markers::MenuHandler::UNCHECKED );
00449 pub_marker_menu(feedback->marker_name ,jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_NIL);
00450 ROS_INFO("Rotation Axis NIL");
00451 }
00452
00453
00454 menu_handler.setCheckState( feedback->menu_entry_id, interactive_markers::MenuHandler::CHECKED );
00455
00456 menu_handler.reApply( *server_ );
00457 server_->applyChanges();
00458 }
00459
00460
00461 void InteractiveMarkerInterface::toggleIKModeCb( const std_msgs::EmptyConstPtr &msg)
00462 {
00463 interactive_markers::MenuHandler::CheckState check_state;
00464 if(menu_handler.getCheckState( rotation_t_menu_ , check_state)){
00465 if(check_state == interactive_markers::MenuHandler::CHECKED){
00466
00467 menu_handler.setCheckState( rotation_t_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00468 menu_handler.setCheckState( rotation_nil_menu_ , interactive_markers::MenuHandler::CHECKED );
00469 pub_marker_menu("", jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_NIL);
00470
00471 }else{
00472
00473 menu_handler.setCheckState( rotation_t_menu_ , interactive_markers::MenuHandler::CHECKED );
00474 menu_handler.setCheckState( rotation_nil_menu_ , interactive_markers::MenuHandler::UNCHECKED );
00475 pub_marker_menu("" , jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_T);
00476 }
00477
00478 menu_handler.reApply( *server_ );
00479 server_->applyChanges();
00480 }
00481 }
00482
00483 void InteractiveMarkerInterface::marker_menu_cb( const jsk_interactive_marker::MarkerMenuConstPtr &msg){
00484 switch (msg->menu){
00485 case jsk_interactive_marker::MarkerMenu::SET_MOVE_RARM:
00486 case jsk_interactive_marker::MarkerMenu::SET_MOVE_LARM:
00487 case jsk_interactive_marker::MarkerMenu::SET_MOVE_ARMS:
00488 changeMoveArm(msg->marker_name, msg->menu);
00489 break;
00490 case jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_NIL:
00491 case jsk_interactive_marker::MarkerMenu::IK_ROTATION_AXIS_T:
00492 {
00493 std_msgs::EmptyConstPtr empty;
00494 toggleIKModeCb(empty);
00495 }
00496 break;
00497 case jsk_interactive_marker::MarkerMenu::PLAN:
00498 case jsk_interactive_marker::MarkerMenu::CANCEL_PLAN:
00499 {
00500 std_msgs::EmptyConstPtr empty;
00501 toggleStartIKCb(empty);
00502 }
00503 break;
00504 default:
00505 pub_marker_menu(msg->marker_name , msg->menu, msg->type);
00506 break;
00507 }
00508 }
00509
00510
00511 void InteractiveMarkerInterface::updateHeadGoal( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
00512 {
00513 ros::Time now = ros::Time(0);
00514
00515 switch ( feedback->event_type )
00516 {
00517 case visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK:
00518 ROS_INFO_STREAM( feedback->marker_name << " was clicked on." );
00519 break;
00520 case visualization_msgs::InteractiveMarkerFeedback::MENU_SELECT:
00521 ROS_INFO_STREAM( "Marker " << feedback->marker_name
00522 << " control " << feedback->control_name
00523 << " menu_entry_id " << feedback->menu_entry_id);
00524 break;
00525 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
00526
00527 break;
00528 }
00529 }
00530
00531 void InteractiveMarkerInterface::updateBase( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
00532 {
00533 switch ( feedback->event_type )
00534 {
00535 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
00536 proc_feedback(feedback, jsk_interactive_marker::MarkerPose::BASE_MARKER);
00537 break;
00538 }
00539 }
00540
00541 void InteractiveMarkerInterface::updateFinger( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback, std::string hand)
00542 {
00543 ros::Time now = ros::Time(0);
00544
00545 switch ( feedback->event_type )
00546 {
00547 case visualization_msgs::InteractiveMarkerFeedback::BUTTON_CLICK:
00548 if(hand == "rhand"){
00549 control_state_.r_finger_on_ ^= true;
00550 }else if(hand == "lhand"){
00551 control_state_.l_finger_on_ ^= true;
00552 }
00553 initControlMarkers();
00554 ROS_INFO_STREAM( hand << feedback->marker_name << " was clicked on." );
00555 break;
00556 case visualization_msgs::InteractiveMarkerFeedback::POSE_UPDATE:
00557 ROS_INFO_STREAM( hand << feedback->marker_name << " was clicked on." );
00558 if(hand == "rhand"){
00559 proc_feedback(feedback, jsk_interactive_marker::MarkerPose::RFINGER_MARKER);
00560 }
00561 if(hand == "lhand"){
00562 proc_feedback(feedback, jsk_interactive_marker::MarkerPose::LFINGER_MARKER);
00563 }
00564
00565
00566 break;
00567 }
00568 }
00569
00570
00571
00572
00573 void InteractiveMarkerInterface::changeMarkerForceMode( std::string mk_name , int im_mode){
00574 ROS_INFO("changeMarkerForceMode marker:%s mode:%d\n",mk_name.c_str(),im_mode);
00575 interactive_markers::MenuHandler reset_handler;
00576 menu_handler_force = reset_handler;
00577 menu_handler_force1 = reset_handler;
00578 menu_handler_force2 = reset_handler;
00579
00580 geometry_msgs::PoseStamped pose;
00581 pose.header.frame_id = base_frame;
00582 if ( target_frame != "" ) {
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 }
00596 visualization_msgs::InteractiveMarker mk;
00597
00598 mk.name = mk_name.c_str();
00599 mk.scale = 0.5;
00600 mk.header = pose.header;
00601 mk.pose = pose.pose;
00602
00603
00604
00605
00606 visualization_msgs::InteractiveMarkerControl control;
00607
00608 if ( false )
00609 {
00610
00611
00612 control.orientation_mode = visualization_msgs::InteractiveMarkerControl::FIXED;
00613 }
00614
00615 control.orientation.w = 1;
00616 control.orientation.x = 1;
00617 control.orientation.y = 0;
00618 control.orientation.z = 0;
00619 control.name = "rotate_x";
00620 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00621 mk.controls.push_back(control);
00622 control.name = "move_x";
00623 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00624 mk.controls.push_back(control);
00625
00626 control.orientation.w = 1;
00627 control.orientation.x = 0;
00628 control.orientation.y = 1;
00629 control.orientation.z = 0;
00630 control.name = "rotate_z";
00631 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00632 mk.controls.push_back(control);
00633
00634
00635
00636
00637 control.orientation.w = 1;
00638 control.orientation.x = 0;
00639 control.orientation.y = 0;
00640 control.orientation.z = 1;
00641 control.name = "rotate_y";
00642 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00643 mk.controls.push_back(control);
00644
00645
00646
00647
00648
00649 switch(im_mode){
00650 case 0:
00651 menu_handler_force.insert("MoveMode",boost::bind( &InteractiveMarkerInterface::changeMoveModeCb, this, _1));
00652 menu_handler_force.insert("Delete Force",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::DELETE_FORCE));
00653 server_->insert( mk );
00654 server_->setCallback( mk.name,
00655 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
00656 menu_handler_force.apply(*server_,mk.name);
00657
00658 server_->applyChanges();
00659 break;
00660 case 1:
00661 mk.scale = 0.5;
00662 menu_handler_force1.insert("MoveMode",boost::bind( &InteractiveMarkerInterface::changeMoveModeCb1, this, _1));
00663 menu_handler_force1.insert("Delete Force",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::DELETE_FORCE));
00664 server_->insert( mk );
00665 server_->setCallback( mk.name,
00666 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
00667 menu_handler_force1.apply(*server_,mk.name);
00668
00669 server_->applyChanges();
00670 break;
00671 case 2:
00672 mk.scale = 0.5;
00673 menu_handler_force2.insert("MoveMode",boost::bind( &InteractiveMarkerInterface::changeMoveModeCb2, this, _1));
00674 menu_handler_force2.insert("Delete Force",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::DELETE_FORCE));
00675 server_->insert( mk );
00676 server_->setCallback( mk.name,
00677 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
00678 menu_handler_force2.apply(*server_,mk.name);
00679
00680 server_->applyChanges();
00681 break;
00682 default:
00683 break;
00684 }
00685
00686
00687
00688
00689 std::list<visualization_msgs::InteractiveMarker>::iterator it = imlist.begin();
00690
00691 while( it != imlist.end() )
00692 {
00693 if(it->name == mk_name.c_str()){
00694 imlist.erase(it);
00695 break;
00696 }
00697 it++;
00698 }
00699 imlist.push_back( mk );
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
00711
00712
00713 ROS_INFO("add mk");
00714
00715
00716
00717 }
00718
00719 void InteractiveMarkerInterface::initBodyMarkers(void){
00720 geometry_msgs::PoseStamped ps;
00721 ps.header.stamp = ros::Time(0);
00722
00723 double scale_factor = 1.02;
00724
00725
00726 ps.header.frame_id = head_link_frame_;
00727 visualization_msgs::InteractiveMarker im =
00728 im_helpers::makeMeshMarker(head_link_frame_, head_mesh_, ps, scale_factor);
00729 makeIMVisible(im);
00730 server_->insert(im);
00731 menu_head_.apply(*server_, head_link_frame_);
00732
00733
00734 if(hand_type_ == "sandia_hand"){
00735 geometry_msgs::PoseStamped ps;
00736 ps.header.stamp = ros::Time(0);
00737
00738 ps.header.frame_id = "/right_f0_base";
00739 for(int i=0;i<4;i++){
00740 for(int j=0;j<3;j++){
00741 visualization_msgs::InteractiveMarker fingerIm =
00742 makeSandiaHandInteractiveMarker(ps, "right", i, j);
00743 makeIMVisible(fingerIm);
00744 server_->insert(fingerIm, boost::bind( &InteractiveMarkerInterface::updateFinger, this, _1, "rhand"));
00745 }
00746 }
00747
00748 ps.header.frame_id = "/left_f0_base";
00749 for(int i=0;i<4;i++){
00750 for(int j=0;j<3;j++){
00751 visualization_msgs::InteractiveMarker fingerIm =
00752 makeSandiaHandInteractiveMarker(ps, "left", i, j);
00753 makeIMVisible(fingerIm);
00754 server_->insert(fingerIm, boost::bind( &InteractiveMarkerInterface::updateFinger, this, _1, "lhand"));
00755 }
00756 }
00757
00758 }else{
00759
00760 for(int i=0; i<rhand_mesh_.size(); i++){
00761 ps.header.frame_id = rhand_mesh_[i].link_name;
00762 ps.pose.orientation = rhand_mesh_[i].orientation;
00763 visualization_msgs::InteractiveMarker handIm =
00764 im_helpers::makeMeshMarker( rhand_mesh_[i].link_name, rhand_mesh_[i].mesh_file, ps, scale_factor);
00765 makeIMVisible(handIm);
00766 server_->insert(handIm);
00767 }
00768 }
00769 }
00770
00771
00772 void InteractiveMarkerInterface::initControlMarkers(void){
00773
00774 if(control_state_.head_on_ && control_state_.init_head_goal_){
00775 control_state_.init_head_goal_ = false;
00776 head_goal_pose_.header.stamp = ros::Time(0);
00777
00778 visualization_msgs::InteractiveMarker HeadGoalIm =
00779 im_helpers::makeHeadGoalMarker( "head_point_goal", head_goal_pose_, 0.1);
00780 makeIMVisible(HeadGoalIm);
00781 server_->insert(HeadGoalIm,
00782 boost::bind( &InteractiveMarkerInterface::updateHeadGoal, this, _1));
00783 menu_head_target_.apply(*server_,"head_point_goal");
00784 }
00785 if(!control_state_.head_on_){
00786 server_->erase("head_point_goal");
00787 }
00788
00789
00790 if(control_state_.base_on_ ){
00791 geometry_msgs::PoseStamped ps;
00792 ps.pose.orientation.w = 1;
00793 ps.header.frame_id = move_base_frame;
00794 ps.header.stamp = ros::Time(0);
00795 visualization_msgs::InteractiveMarker baseIm =
00796 InteractiveMarkerInterface::makeBaseMarker( "base_control", ps, 0.75, false);
00797 makeIMVisible(baseIm);
00798 server_->insert(baseIm,
00799 boost::bind( &InteractiveMarkerInterface::updateBase, this, _1 ));
00800
00801 menu_base_.apply(*server_,"base_control");
00802 }else{
00803 server_->erase("base_control");
00804 }
00805
00806
00807 if(use_finger_marker_ && control_state_.r_finger_on_){
00808 geometry_msgs::PoseStamped ps;
00809 ps.header.stamp = ros::Time(0);
00810 ps.header.frame_id = "/right_f0_base";
00811
00812 server_->insert(makeFingerControlMarker("right_finger", ps),
00813 boost::bind( &InteractiveMarkerInterface::updateFinger, this, _1, "rhand"));
00814 menu_finger_r_.apply(*server_,"right_finger");
00815 }else{
00816 server_->erase("right_finger");
00817 }
00818
00819 if(use_finger_marker_ && control_state_.l_finger_on_){
00820 geometry_msgs::PoseStamped ps;
00821 ps.header.stamp = ros::Time(0);
00822 ps.header.frame_id = "/left_f0_base";
00823
00824 server_->insert(makeFingerControlMarker("left_finger", ps),
00825 boost::bind( &InteractiveMarkerInterface::updateFinger, this, _1, "lhand"));
00826 menu_finger_l_.apply(*server_,"left_finger");
00827 }else{
00828 server_->erase("left_finger");
00829 }
00830
00831 server_->applyChanges();
00832 }
00833
00834
00835 visualization_msgs::InteractiveMarker InteractiveMarkerInterface::makeBaseMarker( const char *name, const geometry_msgs::PoseStamped &stamped, float scale, bool fixed)
00836 {
00837 visualization_msgs::InteractiveMarker mk;
00838 mk.header = stamped.header;
00839 mk.name = name;
00840 mk.scale = scale;
00841 mk.pose = stamped.pose;
00842
00843 visualization_msgs::InteractiveMarkerControl control;
00844
00845 control.orientation.w = 1;
00846 control.orientation.x = 1;
00847 control.orientation.y = 0;
00848 control.orientation.z = 0;
00849
00850 control.name = "move_x";
00851 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00852 mk.controls.push_back(control);
00853
00854 control.orientation.w = 1;
00855 control.orientation.x = 0;
00856 control.orientation.y = 1;
00857 control.orientation.z = 0;
00858 control.name = "rotate_z";
00859 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::ROTATE_AXIS;
00860 mk.controls.push_back(control);
00861
00862 control.orientation.w = 1;
00863 control.orientation.x = 0;
00864 control.orientation.y = 0;
00865 control.orientation.z = 1;
00866 control.name = "move_y";
00867 control.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_AXIS;
00868 mk.controls.push_back(control);
00869 return mk;
00870
00871 }
00872
00873
00874
00875 void InteractiveMarkerInterface::initHandler(void){
00876
00877
00878 bool use_menu;
00879 pnh_.param("force_mode_menu", use_menu, false );
00880 if(use_menu){
00881 menu_handler.insert("ForceMode",boost::bind( &InteractiveMarkerInterface::changeForceModeCb, this, _1));
00882 }
00883
00884 pnh_.param("move_menu", use_menu, false );
00885 if(use_menu){
00886 pnh_.param("move_safety_menu", use_menu, false );
00887 if(use_menu){
00888 interactive_markers::MenuHandler::EntryHandle sub_menu_move_;
00889 sub_menu_move_ = menu_handler.insert( "Move" );
00890 menu_handler.insert( sub_menu_move_,"Plan",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::PLAN));
00891 menu_handler.insert( sub_menu_move_,"Execute",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::EXECUTE));
00892 menu_handler.insert( sub_menu_move_,"Plan And Execute",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::PLAN_EXECUTE));
00893 menu_handler.insert( sub_menu_move_,"Cancel", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::CANCEL_PLAN));
00894 }else{
00895 menu_handler.insert("Move",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MOVE));
00896 }
00897 }
00898
00899 pnh_.param("change_using_ik_menu", use_menu, false );
00900 if(use_menu){
00901 interactive_markers::MenuHandler::EntryHandle sub_menu_move_;
00902 sub_menu_move_ = menu_handler.insert( "Whether To Use IK" );
00903 start_ik_menu_ = menu_handler.insert( sub_menu_move_,"Start IK",boost::bind( &InteractiveMarkerInterface::usingIKCb, this, _1));
00904 menu_handler.setCheckState( start_ik_menu_, interactive_markers::MenuHandler::UNCHECKED );
00905
00906 stop_ik_menu_ = menu_handler.insert( sub_menu_move_,"Stop IK",boost::bind( &InteractiveMarkerInterface::usingIKCb, this, _1));
00907 menu_handler.setCheckState( stop_ik_menu_, interactive_markers::MenuHandler::CHECKED );
00908 }
00909
00910
00911
00912 interactive_markers::MenuHandler::EntryHandle sub_menu_handle_touch_it;
00913 sub_menu_handle_touch_it = menu_handler.insert( "Touch It" );
00914
00915
00916 menu_handler.insert( sub_menu_handle_touch_it, "Execute", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::TOUCHIT_EXEC));
00917 menu_handler.insert( sub_menu_handle_touch_it, "Cancel", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::TOUCHIT_CANCEL));
00918
00919 interactive_markers::MenuHandler::EntryHandle sub_menu_handle_look_hand;
00920 sub_menu_handle_touch_it = menu_handler.insert( "Look hand" );
00921
00922 menu_handler.insert( sub_menu_handle_touch_it, "rarm", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::LOOK_RARM));
00923 menu_handler.insert( sub_menu_handle_touch_it, "larm", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::LOOK_LARM));
00924
00925 pnh_.param("force_move_menu", use_menu, false );
00926 if(use_menu){
00927 menu_handler.insert("Force Move", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::FORCE_MOVE));
00928 }
00929
00930 pnh_.param("pick_menu", use_menu, false );
00931 if(use_menu){
00932 menu_handler.insert("Pick", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::PICK));
00933 }
00934
00935 pnh_.param("grasp_menu", use_menu, false );
00936 if(use_menu){
00937 menu_handler.insert("Grasp", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::START_GRASP));
00938 }
00939
00940 pnh_.param("harf_grasp_menu", use_menu, false );
00941 if(use_menu){
00942 menu_handler.insert("Harf Grasp", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::HARF_GRASP));
00943 }
00944
00945
00946 pnh_.param("stop_grasp_menu", use_menu, false );
00947 if(use_menu){
00948 menu_handler.insert("Stop Grasp", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::STOP_GRASP));
00949 }
00950
00951 pnh_.param("set_origin_menu", use_menu, false );
00952 if(use_menu){
00953
00954 menu_handler.insert("Set Origin To Hand", boost::bind( &InteractiveMarkerInterface::setOriginCb, this, _1, true));
00955
00956 menu_handler.insert("Set Origin", boost::bind( &InteractiveMarkerInterface::setOriginCb, this, _1, false));
00957 }
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976 pnh_.param("reset_marker_pos_menu", use_menu, false );
00977 if(use_menu){
00978 menu_handler.insert("Reset Marker Position", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::RESET_COORDS));
00979 }
00980
00981 pnh_.param("manipulation_mode_menu", use_menu, false );
00982 if(use_menu){
00983 menu_handler.insert("Manipulation Mode", boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MANIP_MODE));
00984 }
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006 pnh_.param("select_arm_menu", use_menu, false );
01007 if(use_menu){
01008 sub_menu_handle = menu_handler.insert( "SelectArm" );
01009 h_mode_last = menu_handler.insert( sub_menu_handle, "Right Arm", boost::bind( &InteractiveMarkerInterface::modeCb,this, _1 ));
01010 menu_handler.setCheckState( h_mode_last, interactive_markers::MenuHandler::CHECKED );
01011 h_mode_rightarm = h_mode_last;
01012 h_mode_last = menu_handler.insert( sub_menu_handle, "Left Arm", boost::bind( &InteractiveMarkerInterface::modeCb,this, _1 ));
01013 menu_handler.setCheckState( h_mode_last, interactive_markers::MenuHandler::UNCHECKED );
01014 h_mode_last = menu_handler.insert( sub_menu_handle, "Both Arms", boost::bind( &InteractiveMarkerInterface::modeCb,this, _1 ));
01015 menu_handler.setCheckState( h_mode_last, interactive_markers::MenuHandler::UNCHECKED );
01016 h_mode_last = h_mode_rightarm;
01017 }
01018
01019 pnh_.param("ik_mode_menu", use_menu, false );
01020 if(use_menu){
01021 sub_menu_handle_ik = menu_handler.insert( "IK mode" );
01022
01023 rotation_t_menu_ = menu_handler.insert( sub_menu_handle_ik, "6D (Position + Rotation)", boost::bind( &InteractiveMarkerInterface::ikmodeCb,this, _1 ));
01024 menu_handler.setCheckState( rotation_t_menu_ , interactive_markers::MenuHandler::UNCHECKED );
01025
01026 rotation_nil_menu_ = menu_handler.insert( sub_menu_handle_ik, "3D (Position)", boost::bind( &InteractiveMarkerInterface::ikmodeCb,this, _1 ));
01027 menu_handler.setCheckState( rotation_t_menu_, interactive_markers::MenuHandler::CHECKED );
01028
01029 }
01030
01031 pnh_.param("use_torso_menu", use_menu, false );
01032 if(use_menu){
01033 use_torso_menu_ = menu_handler.insert( "Links To Use" );
01034
01035 use_torso_nil_menu_ = menu_handler.insert( use_torso_menu_, "Arm", boost::bind( &InteractiveMarkerInterface::useTorsoCb,this, _1 ));
01036 menu_handler.setCheckState( use_torso_nil_menu_, interactive_markers::MenuHandler::CHECKED );
01037 use_torso_t_menu_ = menu_handler.insert( use_torso_menu_, "Arm and Torso", boost::bind( &InteractiveMarkerInterface::useTorsoCb,this, _1 ));
01038 menu_handler.setCheckState( use_torso_t_menu_, interactive_markers::MenuHandler::UNCHECKED );
01039 use_fullbody_menu_ = menu_handler.insert( use_torso_menu_, "Fullbody", boost::bind( &InteractiveMarkerInterface::useTorsoCb,this, _1 ));
01040 menu_handler.setCheckState( use_fullbody_menu_, interactive_markers::MenuHandler::UNCHECKED );
01041
01042 }
01043
01044
01045
01046 interactive_markers::MenuHandler::EntryHandle sub_menu_handle_im_size;
01047 sub_menu_handle_im_size = menu_handler.insert( "IMsize" );
01048 menu_handler.insert( sub_menu_handle_im_size, "Large", boost::bind( &InteractiveMarkerInterface::IMSizeLargeCb, this, _1));
01049 menu_handler.insert( sub_menu_handle_im_size, "Middle", boost::bind( &InteractiveMarkerInterface::IMSizeMiddleCb, this, _1));
01050 menu_handler.insert( sub_menu_handle_im_size, "Small", boost::bind( &InteractiveMarkerInterface::IMSizeSmallCb, this, _1));
01051
01052 pnh_.param("publish_marker_menu", use_menu, false );
01053 if(use_menu){
01054
01055 menu_handler.insert("Publish Marker",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::PUBLISH_MARKER));
01056
01057 }
01058
01059
01060
01061
01062
01063 menu_handler1.insert("ForceMode",boost::bind( &InteractiveMarkerInterface::changeForceModeCb1, this, _1));
01064
01065
01066 menu_handler2.insert("ForceMode",boost::bind( &InteractiveMarkerInterface::changeForceModeCb2, this, _1));
01067 menu_handler2.insert("Move",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MOVE));
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102 head_target_handle_ = menu_head_.insert( "Target Point",
01103 boost::bind( &InteractiveMarkerInterface::targetPointMenuCB, this, _1 ) );
01104 menu_head_.setCheckState(head_target_handle_, interactive_markers::MenuHandler::UNCHECKED);
01105
01106 head_auto_look_handle_ = menu_head_.insert( "Look Automatically", boost::bind( &InteractiveMarkerInterface::lookAutomaticallyMenuCB,
01107 this, _1 ) );
01108 menu_head_.setCheckState(head_auto_look_handle_, interactive_markers::MenuHandler::CHECKED);
01109
01110 menu_head_target_.insert( "Look At",
01111 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1, jsk_interactive_marker::MarkerPose::HEAD_MARKER));
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128 pnh_.param("use_base_marker", use_menu, false );
01129 control_state_.base_on_ = use_menu;
01130
01131 menu_base_.insert("Base Move",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MOVE, jsk_interactive_marker::MarkerMenu::BASE_MARKER));
01132 menu_base_.insert("Reset Marker Position",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::RESET_COORDS, jsk_interactive_marker::MarkerMenu::BASE_MARKER));
01133
01134
01135 pnh_.param("use_finger_marker", use_finger_marker_, false );
01136
01137 menu_finger_r_.insert("Move Finger",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MOVE, jsk_interactive_marker::MarkerMenu::RFINGER_MARKER));
01138 menu_finger_r_.insert("Reset Marker",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::RESET_COORDS, jsk_interactive_marker::MarkerMenu::RFINGER_MARKER));
01139
01140 menu_finger_l_.insert("Move Finger",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::MOVE, jsk_interactive_marker::MarkerMenu::LFINGER_MARKER));
01141 menu_finger_l_.insert("Reset Marker",boost::bind( &InteractiveMarkerInterface::pub_marker_menuCb, this, _1, jsk_interactive_marker::MarkerMenu::RESET_COORDS, jsk_interactive_marker::MarkerMenu::LFINGER_MARKER));
01142
01143 }
01144
01145 void InteractiveMarkerInterface::addHandMarker(visualization_msgs::InteractiveMarkerControl &imc,std::vector < MeshProperty > mesh_vec, double mk_size){
01146 if(mesh_vec.size() > 0){
01147 for(int i=0; i<mesh_vec.size(); i++){
01148 visualization_msgs::Marker handMarker;
01149 handMarker.type = visualization_msgs::Marker::MESH_RESOURCE;
01150 handMarker.mesh_resource = mesh_vec[i].mesh_file;
01151 handMarker.scale.x = 1.0;
01152 handMarker.scale.y = 1.0;
01153 handMarker.scale.z = 1.0;
01154
01155 handMarker.pose.position = mesh_vec[i].position;
01156 handMarker.pose.orientation = mesh_vec[i].orientation;
01157
01158
01159 handMarker.color.r = 1.0;
01160 handMarker.color.g = 1.0;
01161 handMarker.color.b = 0.0;
01162 handMarker.color.a = 0.7;
01163
01164 imc.markers.push_back(handMarker);
01165 }
01166 }else{
01167 visualization_msgs::Marker sphereMarker;
01168 sphereMarker.type = visualization_msgs::Marker::SPHERE;
01169 double marker_scale = mk_size / 2;
01170 sphereMarker.scale.x = marker_scale;
01171 sphereMarker.scale.y = marker_scale;
01172 sphereMarker.scale.z = marker_scale;
01173
01174
01175 sphereMarker.color.r = 0.7;
01176 sphereMarker.color.g = 0.7;
01177 sphereMarker.color.b = 0.7;
01178 sphereMarker.color.a = 0.5;
01179
01180 imc.markers.push_back(sphereMarker);
01181 }
01182
01183 }
01184
01185
01186 void InteractiveMarkerInterface::makeCenterSphere(visualization_msgs::InteractiveMarker &mk, double mk_size){
01187 visualization_msgs::InteractiveMarkerControl sphereControl;
01188 sphereControl.name = "center_sphere";
01189
01190 std::vector < MeshProperty > null_mesh;
01191 if(control_state_.move_origin_state_ == ControlState::HAND_ORIGIN){
01192 if(control_state_.move_arm_ == ControlState::RARM){
01193 addHandMarker(sphereControl, rhand_mesh_, mk_size);
01194 }else if(control_state_.move_arm_ == ControlState::LARM){
01195 addHandMarker(sphereControl, lhand_mesh_, mk_size);
01196 }else{
01197 addHandMarker(sphereControl, null_mesh, mk_size);
01198 }
01199 }else{
01200 addHandMarker(sphereControl, null_mesh, mk_size);
01201 }
01202
01203 sphereControl.interaction_mode = visualization_msgs::InteractiveMarkerControl::MOVE_3D;
01204 mk.controls.push_back(sphereControl);
01205 }
01206
01207
01208
01209 void InteractiveMarkerInterface::changeMarkerMoveMode( std::string mk_name , int im_mode){
01210 switch(im_mode){
01211 case 0:
01212 changeMarkerMoveMode( mk_name, im_mode , 0.5);
01213 break;
01214 case 1:
01215 case 2:
01216 changeMarkerMoveMode( mk_name, im_mode , 0.3);
01217 break;
01218 default:
01219 changeMarkerMoveMode( mk_name, im_mode , 0.3);
01220 break;
01221 }
01222 }
01223
01224 void InteractiveMarkerInterface::changeMarkerMoveMode( std::string mk_name , int im_mode, float mk_size){
01225 geometry_msgs::PoseStamped pose;
01226 pose.header.frame_id = base_frame;
01227 pose.pose.orientation.w = 1.0;
01228 changeMarkerMoveMode( mk_name, im_mode , mk_size, pose);
01229 }
01230
01231 void InteractiveMarkerInterface::changeMarkerMoveMode( std::string mk_name , int im_mode, float mk_size, geometry_msgs::PoseStamped dist_pose){
01232 ROS_INFO("changeMarkerMoveMode marker:%s mode:%d\n",mk_name.c_str(),im_mode);
01233
01234 control_state_.marker_pose_ = dist_pose;
01235
01236 interactive_markers::MenuHandler reset_handler;
01237
01238 geometry_msgs::PoseStamped pose;
01239
01240 if ( target_frame != "" ) {
01241
01242
01243
01244
01245
01246
01247
01248
01249
01250
01251
01252
01253 }else{
01254 pose = dist_pose;
01255 }
01256
01257 visualization_msgs::InteractiveMarker mk;
01258
01259
01260 switch(im_mode){
01261 case 0:
01262 pose.header.stamp = ros::Time(0);
01263
01264 mk = make6DofControlMarker(mk_name.c_str(), pose, mk_size,
01265 true, false );
01266
01267 if(use_center_sphere_){
01268 makeCenterSphere(mk, mk_size);
01269 }
01270
01271 makeIMVisible(mk);
01272
01273 server_->insert( mk );
01274 server_->setCallback( mk.name,
01275 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
01276 menu_handler.apply(*server_,mk.name);
01277 server_->applyChanges();
01278 break;
01279 case 1:
01280 mk = im_helpers::make6DofMarker(mk_name.c_str(), pose, mk_size,
01281 true, false );
01282 mk.description = mk_name.c_str();
01283 makeIMVisible(mk);
01284 server_->insert( mk );
01285 server_->setCallback( mk.name,
01286 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
01287 menu_handler1.apply(*server_,mk.name);
01288 server_->applyChanges();
01289 break;
01290
01291 case 2:
01292 mk = im_helpers::make6DofMarker(mk_name.c_str(), pose, mk_size,
01293 true, false );
01294 mk.description = mk_name.c_str();
01295 makeIMVisible(mk);
01296
01297 server_->insert( mk );
01298 server_->setCallback( mk.name,
01299 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
01300 menu_handler2.apply(*server_,mk.name);
01301 server_->applyChanges();
01302 break;
01303 default:
01304 mk = im_helpers::make6DofMarker(mk_name.c_str(), pose, mk_size,
01305 true, false );
01306 mk.description = mk_name.c_str();
01307
01308 server_->insert( mk );
01309 server_->setCallback( mk.name,
01310 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
01311 server_->applyChanges();
01312 break;
01313 }
01314
01315 std::list<visualization_msgs::InteractiveMarker>::iterator it = imlist.begin();
01316
01317 while( it != imlist.end() )
01318 {
01319 if(it->name == mk_name.c_str()){
01320 imlist.erase(it);
01321 break;
01322 }
01323 it++;
01324 }
01325 imlist.push_back( mk );
01326 }
01327
01328 void InteractiveMarkerInterface::changeMarkerOperationModelMode( std::string mk_name ){
01329 interactive_markers::MenuHandler reset_handler;
01330 menu_handler = reset_handler;
01331 geometry_msgs::PoseStamped pose;
01332 pose.header.frame_id = base_frame;
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347 visualization_msgs::InteractiveMarker mk =
01348
01349 im_helpers::make6DofMarker(mk_name.c_str(), pose, 0.5,
01350 true, false );
01351 mk.description = mk_name.c_str();
01352 menu_handler.insert("ForceMode",boost::bind( &InteractiveMarkerInterface::changeForceModeCb, this, _1));
01353
01354 std::list<visualization_msgs::InteractiveMarker>::iterator it = imlist.begin();
01355
01356 while( it != imlist.end() )
01357 {
01358 if(it->name == mk_name.c_str()){
01359 imlist.erase(it);
01360 break;
01361 }
01362 it++;
01363 }
01364 imlist.push_back( mk );
01365 server_->insert( mk );
01366
01367 server_->setCallback( mk.name,
01368 boost::bind( &InteractiveMarkerInterface::proc_feedback, this, _1) );
01369
01370 menu_handler.apply(*server_,mk.name);
01371 server_->applyChanges();
01372 }
01373
01374
01375
01376 InteractiveMarkerInterface::InteractiveMarkerInterface () : nh_(), pnh_("~") {
01377 pnh_.param("marker_name", marker_name, std::string ( "100") );
01378 pnh_.param("server_name", server_name, std::string ("") );
01379 pnh_.param("base_frame", base_frame, std::string ("/base_link") );
01380 pnh_.param("move_base_frame", move_base_frame, std::string ("/base_link") );
01381 pnh_.param("target_frame", target_frame, std::string ("") );
01382
01383
01384 if ( server_name == "" ) {
01385 server_name = ros::this_node::getName();
01386 }
01387
01388 pub_ = pnh_.advertise<jsk_interactive_marker::MarkerPose> ("pose", 1);
01389 pub_update_ = pnh_.advertise<geometry_msgs::PoseStamped> ("pose_update", 1);
01390 pub_move_ = pnh_.advertise<jsk_interactive_marker::MarkerMenu> ("marker_menu", 1);
01391
01392 serv_set_ = pnh_.advertiseService("set_pose",
01393 &InteractiveMarkerInterface::set_cb, this);
01394 serv_markers_set_ = pnh_.advertiseService("set_markers",
01395 &InteractiveMarkerInterface::markers_set_cb, this);
01396 serv_markers_del_ = pnh_.advertiseService("del_markers",
01397 &InteractiveMarkerInterface::markers_del_cb, this);
01398 serv_reset_ = pnh_.advertiseService("reset_pose",
01399 &InteractiveMarkerInterface::reset_cb, this);
01400
01401 sub_marker_pose_ = pnh_.subscribe<geometry_msgs::PoseStamped> ("move_marker", 1, boost::bind( &InteractiveMarkerInterface::move_marker_cb, this, _1));
01402 sub_marker_menu_ = pnh_.subscribe<jsk_interactive_marker::MarkerMenu> ("select_marker_menu", 1, boost::bind( &InteractiveMarkerInterface::marker_menu_cb, this, _1));
01403
01404 sub_toggle_start_ik_ = pnh_.subscribe<std_msgs::Empty> ("toggle_start_ik", 1, boost::bind( &InteractiveMarkerInterface::toggleStartIKCb, this, _1));
01405
01406 sub_toggle_ik_mode_ = pnh_.subscribe<std_msgs::Empty> ("toggle_ik_mode", 1, boost::bind( &InteractiveMarkerInterface::toggleIKModeCb, this, _1));
01407
01408 ros::service::waitForService("set_dynamic_tf", -1);
01409 dynamic_tf_publisher_client_ = nh_.serviceClient<dynamic_tf_publisher::SetDynamicTF>("set_dynamic_tf", true);
01410
01411 server_.reset( new interactive_markers::InteractiveMarkerServer(server_name));
01412
01413 pnh_.param<std::string>("head_link_frame", head_link_frame_, "head_tilt_link");
01414 pnh_.param<std::string>("head_mesh", head_mesh_, "package://pr2_description/meshes/head_v0/head_tilt.dae");
01415
01416 pnh_.param<std::string>("hand_type", hand_type_, "GENERIC");
01417
01418 pnh_.param("use_head_marker", use_body_marker_, false );
01419 pnh_.param("use_center_sphere", use_center_sphere_, false );
01420
01421 XmlRpc::XmlRpcValue v;
01422 pnh_.param("mesh_config", v, v);
01423 loadMeshes(v);
01424
01425 head_goal_pose_.pose.position.x = 1.0;
01426 head_goal_pose_.pose.position.z = 1.0;
01427 head_goal_pose_.header.frame_id = base_frame;
01428
01429 initHandler();
01430 if(use_body_marker_){
01431 initBodyMarkers();
01432 }
01433 initControlMarkers();
01434 changeMarkerMoveMode(marker_name.c_str(),0);
01435 }
01436
01437 void InteractiveMarkerInterface::loadMeshFromYaml(XmlRpc::XmlRpcValue val, std::string name, std::vector<MeshProperty>& mesh){
01438 for(int i=0; i< val[name].size(); i++){
01439 XmlRpc::XmlRpcValue nval = val[name][i];
01440 MeshProperty m;
01441 m.link_name = (std::string)nval["link"];
01442 m.mesh_file = (std::string)nval["mesh"];
01443
01444 if(nval.hasMember("position")){
01445 XmlRpc::XmlRpcValue position = nval["position"];
01446 m.position.x = (double)position["x"];
01447 m.position.y = (double)position["y"];
01448 m.position.z = (double)position["z"];
01449 }else{
01450 m.position.x = 0.0;
01451 m.position.y = 0.0;
01452 m.position.z = 0.0;
01453 }
01454
01455 if(nval.hasMember("orient")){
01456 XmlRpc::XmlRpcValue orient = nval["orient"];
01457 std::cerr << "load_link: " << orient["x"] << std::endl;
01458 m.orientation.x = (double)orient["x"];
01459 m.orientation.y = (double)orient["y"];
01460 m.orientation.z = (double)orient["z"];
01461 m.orientation.w = (double)orient["w"];
01462 }else{
01463 m.orientation.x = 0.0;
01464 m.orientation.y = 0.0;
01465 m.orientation.z = 0.0;
01466 m.orientation.w = 1.0;
01467 }
01468 mesh.push_back(m);
01469 std::cerr << "load_link: " << nval["link"] << std::endl;
01470 }
01471 }
01472
01473 void InteractiveMarkerInterface::loadMeshes(XmlRpc::XmlRpcValue val){
01474 loadMeshFromYaml(val, "r_hand", rhand_mesh_);
01475 loadMeshFromYaml(val, "l_hand", lhand_mesh_);
01476 }
01477
01478 bool InteractiveMarkerInterface::markers_set_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
01479 jsk_interactive_marker::MarkerSetPose::Response &res ) {
01480 bool setalready = false;
01481
01482 std::list<visualization_msgs::InteractiveMarker>::iterator it = imlist.begin();
01483 while( it != imlist.end() )
01484 {
01485 if( it->name == req.marker_name){
01486 setalready = true;
01487 break;
01488 }
01489 it++;
01490 }
01491
01492 if(setalready){
01493 server_->setPose(req.marker_name, req.pose.pose, req.pose.header);
01494 server_->applyChanges();
01495 return true;
01496 }else{
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508 return true;
01509 }
01510 }
01511
01512 bool InteractiveMarkerInterface::markers_del_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
01513 jsk_interactive_marker::MarkerSetPose::Response &res ) {
01514
01515 server_->erase(req.marker_name);
01516 server_->applyChanges();
01517 std::list<visualization_msgs::InteractiveMarker>::iterator it = imlist.begin();
01518 while( it != imlist.end() )
01519 {
01520 if( it->name == req.marker_name){
01521 imlist.erase(it);
01522 break;
01523 }
01524 it++;
01525 }
01526
01527 return true;
01528
01529 }
01530
01531 void InteractiveMarkerInterface::move_marker_cb ( const geometry_msgs::PoseStampedConstPtr &msg){
01532 pub_marker_tf(msg->header, msg->pose);
01533
01534 pub_marker_pose( msg->header, msg->pose, marker_name, jsk_interactive_marker::MarkerPose::GENERAL);
01535
01536 server_->setPose(marker_name, msg->pose, msg->header);
01537 server_->applyChanges();
01538 }
01539
01540
01541 bool InteractiveMarkerInterface::set_cb ( jsk_interactive_marker::MarkerSetPose::Request &req,
01542 jsk_interactive_marker::MarkerSetPose::Response &res ) {
01543
01544 if ( req.markers.size() > 0 ) {
01545 visualization_msgs::InteractiveMarker mk;
01546 if ( server_->get(req.marker_name, mk) ) {
01547 visualization_msgs::InteractiveMarkerControl mkc;
01548 mkc.name = "additional_marker";
01549 mkc.always_visible = true;
01550 mkc.markers = req.markers;
01551
01552 for ( std::vector<visualization_msgs::InteractiveMarkerControl>::iterator it
01553 = mk.controls.begin();
01554 it != mk.controls.end(); it++ ) {
01555 if ( it->name == mkc.name ){
01556 mk.controls.erase( it );
01557 break;
01558 }
01559 }
01560 mk.controls.push_back( mkc );
01561 }
01562 }
01563 std::string mName = req.marker_name;
01564 if(mName == ""){
01565 mName = marker_name;
01566 }
01567 pub_marker_tf(req.pose.header, req.pose.pose);
01568
01569 server_->setPose(mName, req.pose.pose, req.pose.header);
01570 server_->applyChanges();
01571 pub_update_.publish(req.pose);
01572 return true;
01573 }
01574
01575 bool InteractiveMarkerInterface::reset_cb ( jsk_interactive_marker::SetPose::Request &req,
01576 jsk_interactive_marker::SetPose::Response &res ) {
01577 geometry_msgs::PoseStamped pose;
01578 pose.header.frame_id = base_frame;
01579 if ( target_frame != "" ) {
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595 } else {
01596 server_->setPose(marker_name, pose.pose);
01597 }
01598 server_->applyChanges();
01599 return true;
01600 }
01601
01602
01603 void InteractiveMarkerInterface::makeIMVisible(visualization_msgs::InteractiveMarker &im){
01604 for(int i=0; i<im.controls.size(); i++){
01605 im.controls[i].always_visible = true;
01606 }
01607 }
01608
01609 int main(int argc, char** argv)
01610 {
01611 ros::init(argc, argv, "jsk_marker_interface");
01612 InteractiveMarkerInterface imi;
01613 ros::spin();
01614
01615 return 0;
01616 }