wam_actions.cpp
Go to the documentation of this file.
00001 #include "wam_actions.h"
00002 
00003 /* wam_actions node code */
00004 
00005 WamActions::WamActions() {
00006   //init class attributes if necessary
00007   transform_grasping_point.setOrigin(tf::Vector3(0.5, 0.0, 0.5));
00008   transform_grasping_point.setRotation(tf::Quaternion(0, 0, 0, -sqrt(2)/2));
00009   destination_counter = 0;
00010 
00011   //string for port names
00012   //TODO renaming from launch does not work, fix it
00013   wam0_ = ros::names::append(ros::this_node::getName(), "wam0"); 
00014   wam0_ = "/wam_fk/wam0"; 
00015 
00016   // [init publishers]
00017   
00018   // [init subscribers]
00019   
00020   // [init services]
00021   this->wam_action_server = this->node_handle_.advertiseService("/wam_actions/wam_action", &WamActions::wam_actionCallback, this);
00022   
00023   // [init clients]
00024   obj_filter_client = this->node_handle_.serviceClient<iri_wam_common_msgs::compute_obj_grasp_pose>("/wam_actions/obj_filter");
00025   barrett_hand_cmd_client = this->node_handle_.serviceClient<iri_wam_common_msgs::bhand_cmd>("/wam_actions/bhand_cmd");
00026   pose_move_client = this->node_handle_.serviceClient<iri_wam_common_msgs::pose_move>("/wam_actions/pose_move");
00027 
00028   // [init action servers]
00029   
00030   // [init action clients]
00031 }
00032 
00033 void WamActions::mainLoop(void)
00034 {
00035   //lock access to driver if necessary
00036   //this->driver_.lock();
00037 
00038   // [fill msg Header if necessary]
00039 //  tf_broadcaster_mutex.enter();
00040 //  tf_br.sendTransform(tf::StampedTransform(transform_grasping_point, ros::Time::now(), "openni_depth_optical_frame", "graspingPoint"));
00041 //  tf_broadcaster_mutex.exit();
00042 
00043   // [fill msg structures]
00044   
00045   // [fill srv structure and make request to the server]
00046   
00047   // [fill action structure and make request to the action server]
00048 
00049   // [publish messages]
00050 
00051   //unlock access to driver if previously blocked
00052   //this->driver_.unlock();
00053 }
00054 
00055 /*  [subscriber callbacks] */
00056 
00057 /*  [service callbacks] */
00058 bool WamActions::wam_actionCallback(iri_wam_common_msgs::wamaction::Request &req, iri_wam_common_msgs::wamaction::Response &res) 
00059 { 
00060     double x=0.5,y,z;
00061     double x2=0.5,y2,z2;
00062     int zone = ANYZONE;
00063     int zone2 = ANYZONE;
00064     geometry_msgs::Pose grasping_pose;
00065 
00066     ROS_DEBUG("Received action %d at zone %d with grasp %d\n",req.action,req.zone,req.hand); 
00067     switch(req.zone){
00068         case ANYZONEMSG:
00069             zone = ANYZONE;
00070             zone2 = ANYZONE;
00071             break;
00072         case AZONEMSG:
00073             zone = AZONE;
00074             zone2 = BZONE;
00075             break;
00076         case BZONEMSG:
00077             zone = BZONE;
00078             zone2 = AZONE;
00079             break;
00080         default:
00081             ROS_ERROR("Unrecognized zone request");
00082             zone = ANYZONE;
00083             zone2 = ANYZONE;
00084             break;
00085     }
00086 
00087     switch(req.hand){
00088         case STRAIGHT:
00089             barrett_hand_cmd_srv.request.bhandcmd = "GM 1500"; 
00090             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00091             { 
00092               ROS_DEBUG("bh %s success %d", barrett_hand_cmd_srv.request.bhandcmd.c_str(), barrett_hand_cmd_srv.response.success); 
00093             } else { 
00094               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00095               return false;
00096             }
00097             barrett_hand_cmd_srv.request.bhandcmd = "SO"; 
00098             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00099             { 
00100               ROS_DEBUG("bh %s success %d", barrett_hand_cmd_srv.request.bhandcmd.c_str(), barrett_hand_cmd_srv.response.success); 
00101             } else { 
00102               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00103               return false;
00104             }
00105             break;
00106         case ISOMETRIC:
00107             ROS_INFO("ISOTAKE");
00108             barrett_hand_cmd_srv.request.bhandcmd = "SM 1000"; 
00109             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) { 
00110               ROS_DEBUG("bh %s success %d", barrett_hand_cmd_srv.request.bhandcmd.c_str(), barrett_hand_cmd_srv.response.success); 
00111             } else { 
00112               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00113               return false;
00114             }
00115             break;
00116         case PEG:
00117             ROS_INFO("PEG");
00118             barrett_hand_cmd_srv.request.bhandcmd = "SM 1600"; 
00119             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) { 
00120               ROS_DEBUG("bh %s success %d", barrett_hand_cmd_srv.request.bhandcmd.c_str(), barrett_hand_cmd_srv.response.success); 
00121             } else { 
00122               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00123               return false;
00124             }
00125             barrett_hand_cmd_srv.request.bhandcmd = "3M 18000"; 
00126             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00127             { 
00128               ROS_DEBUG("bh %s success %d", barrett_hand_cmd_srv.request.bhandcmd.c_str(), barrett_hand_cmd_srv.response.success); 
00129             } else { 
00130               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00131               return false;
00132             }
00133             break;
00134         default:
00135             ROS_ERROR("Unrecognized hand request");
00136             break;
00137     }
00138 
00139     switch(req.pointDescription) {
00140         case MAXWRINKLE:
00141             ROS_INFO("MAXWRINKLE");
00142             requestGraspingPoint(x,y,z,zone); 
00143             break;
00144         case MAXHEIGHT:
00145             ROS_INFO("MAXHEIGHT");
00146             requestGraspingPointMaxHeight(x,y,z,zone); 
00147             break;
00148         default:
00149             ROS_ERROR("unrecognized point desecription");
00150             break;
00151     }
00152 
00153     switch(req.action){
00154         case TAKEHIGH:
00155             ROS_INFO("TAKE");
00156             take3D(x,y,z);
00157             go_to_kinect();
00158             get_destination(zone2,x2,y2,z2);
00159             go_to(x2, y2, z2+0.2);
00160             drop(x2, y2, z2);
00161             go_to_kinect();
00162             break;
00163         case TAKELOW:
00164             ROS_INFO("TAKELOW");
00165             take3D(x,y,z-0.1);
00166             go_to_kinect();
00167             get_destination(zone2,x2,y2,z2);
00168             go_to(x2, y2, z2+0.3);
00169             drop(x2, y2, z2);
00170             go_to_kinect();
00171             break;
00172         case FOLDLOW:
00173             ROS_INFO("FOLDLOW");
00174             ROS_INFO("take %f %f %f",x,y,z);
00175             take3D(x,y,z);
00176             ROS_INFO("goto %f %f %f",x,y,z+0.2);
00177             go_to(x,y, z+0.2);
00178             if(check_box(NOX,y+0.3,NOZ) && y+0.3 < 0){
00179                 ROS_INFO("goto %f %f %f",x,y+0.3,z+0.2);
00180                 go_to(x,y+0.3, z+0.2);
00181             }else{
00182                 ROS_INFO("Outside box, going the other way");
00183                 ROS_INFO("goto %f %f %f",x,y-0.3,z+0.2);
00184                 go_to(x,y-0.3, z+0.2);
00185             }
00186             drop();
00187             go_to_kinect();
00188             break;
00189         case FOLDHIGH:
00190             ROS_INFO("FOLDHIGH");
00191             take3D(x,y,z);
00192             go_to(0.4,-0.3, 0.3);
00193             go_to(0.4,-0.3, -0.1);
00194             go_to(0.4,-0.15, -0.2);
00195             go_to(0.4,-0.3, -0.3);
00196             drop();
00197             go_to_kinect();
00198             break;
00199         case SPREAD:
00200             ROS_INFO("SPREAD");
00201             take3D(x,y,z);
00202             //retrieve point far away in the direction from the cloth center to where I am.
00203             if(zone == AZONE){
00204                 go_to(0.30, -0.4, z+0.1);
00205                 drop(0.30, -0.40, z+0.05);
00206             }else{
00207                 go_to(0.30, 0.4, z+0.1);
00208                 drop(0.30, 0.40, z+0.05);
00209             }
00210             go_to_kinect();
00211             break; 
00212         case CHANGEPILE:
00213             ROS_INFO("CHANGE PILE");
00214             take3D(x,y,z);
00215             go_to_kinect();
00216             if(zone == AZONE)
00217                 drop(0.5,0.3, 0.2); 
00218             else
00219                 drop(0.5,-0.3, 0.2);
00220             go_to_kinect();
00221             break;
00222         case FLIP:
00223             ROS_INFO("FLIP");
00224             take3D(x,y,z);
00225             go_to_kinect();
00226         
00227             grasping_pose.position.x = 0.5;
00228             grasping_pose.position.y = 0;
00229             grasping_pose.position.z = 0.2;
00230             grasping_pose.orientation.x = 0.0;
00231             grasping_pose.orientation.y = 1.0;
00232             grasping_pose.orientation.z = 0.0;
00233             grasping_pose.orientation.w = 0.0;
00234             pose_move_srv.request.pose = grasping_pose;
00235         
00236             if (pose_move_client.call(pose_move_srv)) { 
00237               ROS_DEBUG("pose_move flip success %d", pose_move_srv.response.success);
00238             } else { 
00239               ROS_ERROR("Failed to call service pose_move");
00240               return false;
00241             }
00242 
00243             grasping_pose.position.x = x-0.05;
00244             grasping_pose.position.y = y;
00245             grasping_pose.position.z = z+0.18;
00246             grasping_pose.orientation.x = 0.0;
00247             grasping_pose.orientation.y = 1.0;
00248             grasping_pose.orientation.z = 0.0;
00249             grasping_pose.orientation.w = 0.0;
00250             pose_move_srv.request.pose = grasping_pose;
00251         
00252             if(pose_move_client.call(pose_move_srv)) { 
00253               ROS_DEBUG("pose_move flip back to position success%d", pose_move_srv.response.success);
00254             } else { 
00255               ROS_ERROR("Failed to call service pose_move");
00256               return false;
00257             }
00258 
00259             barrett_hand_cmd_srv.request.bhandcmd = "GM 5000"; 
00260             if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00261             { 
00262               ROS_DEBUG("bh2 torque open success %d", barrett_hand_cmd_srv.response.success); 
00263             } else { 
00264               ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00265               return false;
00266             }
00267             go_to_kinect();
00268             break;
00269         case SHAKE:
00270             ROS_INFO("SHAKE");
00271             take3D(x,y,z);
00272             go_to(x,y,z+0.3);
00273             go_to(x,y-0.2,z+0.4);
00274             go_to(x,y+0.2,z+0.3);
00275             drop(x,y,z+0.2);
00276             go_to_kinect();
00277             break;
00278         case MOVEAWAY:
00279             ROS_INFO("MOVEAWAY");
00280             take3D(x,y,z);
00281             go_to_kinect();
00282             drop(-0.1,0.6,0.15);
00283             go_to_kinect();
00284             break;
00285         case SIDEGRASP:
00286             ROS_INFO("SIDEGRASP");
00287             take3Dside(x,y,z);
00288             go_to_kinect();
00289             get_destination(zone2,x2,y2,z2);
00290             go_to(x2, y2, z2+0.3);
00291             drop(x2, y2, z2);
00292             go_to_kinect();
00293             break;
00294         case DUMMY:
00295             ROS_INFO("DUMMY");
00296             break;
00297         default:
00298             ROS_ERROR("Invalid action id. Check wam_actions_node.h");
00299             break;
00300     }
00301     return true; 
00302 }
00303 
00304 bool WamActions::check_box(double x, double y, double z){
00305     return (x > 0.33 && x < 0.80 && y > -0.4 && y < 0.4 && z > -0.36 && z < 0.8);
00306 }
00307 
00308 bool WamActions::fit_box(double& x, double& y, double& z){
00309 
00310     if(!check_box(x,y,z)){
00311       ROS_WARN("Grasping point %f %f %f outside working box [0.33, 0.8] [-0.35, 0.4] [-0.37, 0.8] fitting to box",x,y,z);
00312       if(x<=0.33) x = 0.33;
00313       else if(x>=0.8) x = 0.8;
00314       if(y<=-0.4) y = -0.4;
00315       else if(y>=0.4) y = 0.4;
00316       if(z<=-0.36) z = -0.36;
00317       else if(z>=0.8) z = 0.8;
00318       ROS_WARN("fit with %f %f %f",x,y,z);
00319     }
00320     //TODO check if difference is too high instead of autorize move all the time
00321     return true;
00322 }
00323 
00324 /*  [action callbacks] */
00325 
00326 /*  [action requests] */
00327 bool WamActions::go_to(double x, double y, double z){
00328 
00329     geometry_msgs::Pose grasping_pose;
00330     if(!fit_box(x,y,z))
00331         return false;
00332 
00333     grasping_pose.position.x = x-0.05;
00334     grasping_pose.position.y = y;
00335     grasping_pose.position.z = z+0.18;
00336     grasping_pose.orientation.x = 1.0;
00337     grasping_pose.orientation.y = 0.0;
00338     grasping_pose.orientation.z = 0.0;
00339     grasping_pose.orientation.w = 0.0;
00340     pose_move_srv.request.pose = grasping_pose;
00341 
00342     if (pose_move_client.call(pose_move_srv)) { 
00343       ROS_DEBUG("pose_move go_to %f %f %f success %d",x,y,z, pose_move_srv.response.success);
00344       return true;
00345     } else { 
00346       ROS_ERROR("Failed to call service pose_move");
00347       return false;
00348     }
00349     return true;
00350 }
00351 
00352 bool WamActions::go_to_kinect(){
00353 
00354     geometry_msgs::Pose grasping_pose;
00355 
00356     grasping_pose.position.x = 0.5;
00357     grasping_pose.position.y = 0;
00358     grasping_pose.position.z = 0.5;
00359     grasping_pose.orientation.x = 1.0;
00360     grasping_pose.orientation.y = 0.0;
00361     grasping_pose.orientation.z = 0.0;
00362     grasping_pose.orientation.w = 0.0;
00363     pose_move_srv.request.pose = grasping_pose;
00364 
00365     if (pose_move_client.call(pose_move_srv)) { 
00366       ROS_DEBUG("pose_move kinect %f %f %f success %d",0.5,0.0,0.5, pose_move_srv.response.success);
00367       return true;
00368     } else { 
00369       ROS_ERROR("Failed to call service pose_move");
00370       return false;
00371     }
00372 }
00373 
00374 bool WamActions::requestGraspingPoint(double &x, double &y, double &z, int zone, int filterID){
00375 
00376     geometry_msgs::PoseStamped pose_msg;
00377     tf::StampedTransform transform_aux;
00378     //Call obj_filter node
00379     obj_filter_srv.request.zone = zone; 
00380     if(obj_filter_client.call(obj_filter_srv)) 
00381     { 
00382       ROS_DEBUG("Grasping point %f %f %f wrinkleness %f", obj_filter_srv.response.graspPose.pose.position.x,obj_filter_srv.response.graspPose.pose.position.y,obj_filter_srv.response.graspPose.pose.position.z, obj_filter_srv.response.wrinkleness); 
00383       pose_msg = obj_filter_srv.response.graspPose;
00384     } else { 
00385       ROS_ERROR("Failed to call service obj_filter"); 
00386       ROS_ERROR("defaulting");
00387       //default position for debugging the structure
00388       pose_msg.pose.position.x = 0.5;
00389       pose_msg.pose.position.y = 0.0;
00390       pose_msg.pose.position.z = 0.0;
00391       pose_msg.pose.orientation.x = 1;
00392       pose_msg.pose.orientation.y = 0;
00393       pose_msg.pose.orientation.z = 0;
00394       pose_msg.pose.orientation.w = 0;
00395       return false;
00396     }
00397 
00398     transform_grasping_point.setOrigin(tf::Vector3(pose_msg.pose.position.x, pose_msg.pose.position.y, pose_msg.pose.position.z));
00399     transform_grasping_point.setRotation(tf::Quaternion( pose_msg.pose.orientation.x, pose_msg.pose.orientation.y,
00400                                                    pose_msg.pose.orientation.z, pose_msg.pose.orientation.w));
00401 
00402     //ensure tf is published before tf lookup
00403     //tf_br.sendTransform(tf::StampedTransform(transform_grasping_point, ros::Time::now(), "openni_depth_optical_frame", "graspingPoint"));
00404 
00405     ROS_DEBUG("t_aux %f %f %f   %f %f %f %f",transform_grasping_point.getOrigin().x(),transform_grasping_point.getOrigin().y(),transform_grasping_point.getOrigin().z(),transform_grasping_point.getRotation().getAxis().x(),transform_grasping_point.getRotation().getAxis().y(),transform_grasping_point.getRotation().getAxis().z(),transform_grasping_point.getRotation().getAxis().w());
00406 
00407     //maybe wait for a while so the tf updates the data?
00408     sleep(2); 
00409     //retrieve target pose from tf tree
00410     try{
00411       tf_grasp.lookupTransform(wam0_, "/graspingPoint", ros::Time(0), transform_aux);
00412     } catch (tf::TransformException ex) {
00413       ROS_ERROR("%s",ex.what());
00414       return false;
00415     }
00416 
00417     //execute action 
00418     x = transform_aux.getOrigin().x();
00419     y = transform_aux.getOrigin().y(); 
00420     z = transform_aux.getOrigin().z();
00421     ROS_DEBUG("Received 3D position %f %f %f\n",x,y,z);
00422     return true;
00423 
00424 }
00425 
00426 bool WamActions::requestGraspingPointMaxHeight(double &x, double &y, double &z, int zone, int filterID){
00427 
00428     geometry_msgs::PoseStamped pose_msg;
00429     tf::StampedTransform transform_aux;
00430     //Call obj_filter node
00431     obj_filter_srv.request.zone = zone; 
00432     if(obj_filter_client.call(obj_filter_srv)) { 
00433       pose_msg = obj_filter_srv.response.graspPose;
00434     } else { 
00435       ROS_ERROR("Failed to call service obj_filter"); 
00436       ROS_ERROR("defaulting");
00437       //default position for debugging the structure
00438       pose_msg.pose.position.x = 0.5;
00439       pose_msg.pose.position.y = 0.0;
00440       pose_msg.pose.position.z = 0.0;
00441       pose_msg.pose.orientation.x = 1;
00442       pose_msg.pose.orientation.y = 0;
00443       pose_msg.pose.orientation.z = 0;
00444       pose_msg.pose.orientation.w = 0;
00445       return false;
00446     }
00447 
00448     transform_grasping_point.setOrigin(tf::Vector3(pose_msg.pose.position.x, pose_msg.pose.position.y, pose_msg.pose.position.z));
00449     transform_grasping_point.setRotation(tf::Quaternion( pose_msg.pose.orientation.x, pose_msg.pose.orientation.y,
00450                                                    pose_msg.pose.orientation.z, pose_msg.pose.orientation.w));
00451 
00452     //ensure tf is published before tf lookup
00453     //tf_br.sendTransform(tf::StampedTransform(transform_grasping_point, ros::Time::now(), "openni_depth_optical_frame", "graspingPoint"));
00454 
00455     ROS_DEBUG("t_aux %f %f %f   %f %f %f %f",transform_grasping_point.getOrigin().x(),transform_grasping_point.getOrigin().y(),transform_grasping_point.getOrigin().z(),transform_grasping_point.getRotation().getAxis().x(),transform_grasping_point.getRotation().getAxis().y(),transform_grasping_point.getRotation().getAxis().z(),transform_grasping_point.getRotation().getAxis().w());
00456 
00457     //maybe wait for a while so the tf updates the data?
00458     sleep(2); 
00459 
00460     //retrieve target pose from tf tree
00461     try {
00462       tf_grasp.lookupTransform(wam0_, "/graspingPoint", ros::Time(0), transform_aux);
00463     } catch (tf::TransformException ex) {
00464       ROS_ERROR("%s",ex.what());
00465       return false;
00466     }
00467 
00468     //execute action 
00469     x = transform_aux.getOrigin().x();
00470     y = transform_aux.getOrigin().y(); 
00471     z = transform_aux.getOrigin().z();
00472     ROS_DEBUG("Received 3D position %f %f %f\n",x,y,z);
00473     return true;
00474 
00475 }
00476 
00477 bool WamActions::take3Dside(double x, double y,double z){
00478     
00479     if(!fit_box(x,y,z))
00480         return false;
00481     //execute move 
00482     geometry_msgs::Pose grasping_pose;
00483 
00484 //assuming hand opened and convinent for finger 3 blocked
00485 //    barrett_hand_cmd_srv.request.bhandcmd = "GTO"; 
00486 //    if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00487 //    { 
00488 //      ROS_DEBUG("bh take3d success %d", barrett_hand_cmd_srv.response.success); 
00489 //    } else { 
00490 //      ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00491 //      return false;
00492 //    }
00493 
00494     //switch to camera coordinates
00495     //transform to world coordinates
00496     grasping_pose.position.x = x-0.05;
00497     grasping_pose.position.y = y+0.07;
00498     grasping_pose.position.z = z+0.17;
00499     grasping_pose.orientation.x = 0.0;
00500     grasping_pose.orientation.y = 0.0;
00501     grasping_pose.orientation.z = 0.0;
00502     grasping_pose.orientation.w = 1.0;
00503     pose_move_srv.request.pose = grasping_pose;
00504 
00505     if (pose_move_client.call(pose_move_srv)) { 
00506       ROS_DEBUG("pose_move success %d", pose_move_srv.response.success);
00507     } else { 
00508       ROS_ERROR("Failed to call service pose_move");
00509       return false;
00510     }
00511 
00512     barrett_hand_cmd_srv.request.bhandcmd = "GM 18000"; 
00513     if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00514     { 
00515       ROS_DEBUG("bh2 success %d", barrett_hand_cmd_srv.response.success); 
00516     } else { 
00517       ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00518       return false;
00519     }
00520     return true;
00521 }
00522 
00523 bool WamActions::take3D(double x, double y,double z){
00524     
00525     if(!fit_box(x,y,z))
00526         return false;
00527     //execute move 
00528     geometry_msgs::Pose grasping_pose;
00529 
00530 //assuming hand opened and convinent for finger 3 blocked
00531 //    barrett_hand_cmd_srv.request.bhandcmd = "GTO"; 
00532 //    if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00533 //    { 
00534 //      ROS_DEBUG("bh take3d success %d", barrett_hand_cmd_srv.response.success); 
00535 //    } else { 
00536 //      ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00537 //      return false;
00538 //    }
00539 
00540     //switch to camera coordinates
00541     //transform to world coordinates
00542     grasping_pose.position.x = x-0.05;
00543     grasping_pose.position.y = y+0.07;
00544     grasping_pose.position.z = z+0.17;
00545     grasping_pose.orientation.x = sqrt(2)/2;
00546     grasping_pose.orientation.y = sqrt(2)/2;
00547     grasping_pose.orientation.z = 0.0;
00548     grasping_pose.orientation.w = 0.0;
00549     pose_move_srv.request.pose = grasping_pose;
00550 
00551     if (pose_move_client.call(pose_move_srv)) { 
00552       ROS_DEBUG("pose_move success %d", pose_move_srv.response.success);
00553     } else { 
00554       ROS_ERROR("Failed to call service pose_move");
00555       return false;
00556     }
00557 
00558     barrett_hand_cmd_srv.request.bhandcmd = "GM 18000"; 
00559     if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00560     { 
00561       ROS_DEBUG("bh2 success %d", barrett_hand_cmd_srv.response.success); 
00562     } else { 
00563       ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00564       return false;
00565     }
00566     return true;
00567 }
00568 
00569 bool WamActions::drop(){
00570     barrett_hand_cmd_srv.request.bhandcmd = "GM 5000"; 
00571     if (barrett_hand_cmd_client.call(barrett_hand_cmd_srv)) 
00572     { 
00573       ROS_DEBUG("bh_drop success %d", barrett_hand_cmd_srv.response.success); 
00574     } else { 
00575       ROS_ERROR("Failed to call service barrett_hand_cmd"); 
00576       return false;
00577     }
00578     return true;
00579 }
00580 
00581 bool WamActions::drop(double x, double y, double z){
00582 
00583     geometry_msgs::Pose droppose;
00584     //switch to camera coordinates
00585     //transform to world coordinates
00586     droppose.position.x = x-0.05;
00587     droppose.position.y = y;
00588     droppose.position.z = z+0.18;
00589     droppose.orientation.x = sqrt(2)/2;
00590     droppose.orientation.y = sqrt(2)/2;
00591     droppose.orientation.z = 0.0;
00592     droppose.orientation.w = 0.0;
00593     pose_move_srv.request.pose = droppose;
00594     if (pose_move_client.call(pose_move_srv)) { 
00595       ROS_DEBUG("pose_move success %d", pose_move_srv.response.success);
00596     } else { 
00597       ROS_ERROR("Failed to call service pose_move");
00598       return false;
00599     }
00600     drop();
00601 
00602     return true; 
00603 
00604 }
00605 
00606 bool WamActions::fold(){
00607 
00608   return false;
00609 }
00610 
00611 bool WamActions::flip(){
00612 
00613   return false;
00614 }
00615 
00616 void WamActions::get_destination(int destination_zone,  double& x, double& y, double& z){
00617     if(destination_zone == AZONE){
00618         this->destination_counter++;
00619         this->destination_counter = this->destination_counter%6;
00620         switch(destination_counter){
00621             case 0:
00622                 x = 0.65;
00623                 y = -0.27;
00624                 z = 0.0; 
00625                 break;
00626             case 1:
00627                 x = 0.70;
00628                 y = -0.27;
00629                 z = 0.0; 
00630                 break;
00631             case 2:
00632                 x = 0.70;
00633                 y = -0.35;
00634                 z = 0.0; 
00635                 break;
00636             case 3:
00637                 x = 0.65;
00638                 y = -0.35;
00639                 z = 0.0; 
00640                 break;
00641             case 4:
00642                 x = 0.60;
00643                 y = -0.35;
00644                 z = 0.0; 
00645                 break;
00646             case 5:
00647                 x = 0.60;
00648                 y = -0.27;
00649                 z = 0.0; 
00650                 break;
00651             default:
00652                 x = 0.65;
00653                 y = -0.27;
00654                 z = 0.0; 
00655                 break;
00656         }
00657     }else if(destination_zone == BZONE){
00658         destination_counter++;
00659         destination_counter = destination_counter%6;
00660         switch(destination_counter){
00661             case 0:
00662                 x = 0.70;
00663                 y = 0.3;
00664                 z = 0.0; 
00665                 break;
00666             case 1:
00667                 x = 0.75;
00668                 y = 0.3;
00669                 z = 0.0; 
00670                 break;
00671             case 2:
00672                 x = 0.75;
00673                 y = 0.4;
00674                 z = 0.0; 
00675                 break;
00676             case 3:
00677                 x = 0.70;
00678                 y = 0.4;
00679                 z = 0.0; 
00680                 break;
00681             case 4:
00682                 x = 0.65;
00683                 y = 0.4;
00684                 z = 0.0; 
00685                 break;
00686             case 5:
00687                 x = 0.65;
00688                 y = 0.3;
00689                 z = 0.0; 
00690                 break;
00691             default:
00692                 x = 0.70;
00693                 y = 0.3;
00694                 z = 0.0; 
00695                 break;
00696         }
00697     }else{
00698         //TODO check xyz zone and mirror it
00699         x = 0.65;
00700         y = -0.3;
00701         z = 0.0; 
00702     }
00703 }
00704 
00705 
00706 /* main function */
00707 int main(int argc,char *argv[])
00708 {
00709     ros::init(argc, argv, "wam_actions");
00710     WamActions wam_actions;
00711     ros::Rate loop_rate(10); 
00712     while(ros::ok()){
00713       wam_actions.mainLoop();
00714       ros::spinOnce();
00715       loop_rate.sleep(); 
00716     }
00717 }


iri_wam_actions
Author(s):
autogenerated on Fri Dec 6 2013 21:44:22