door_swinger.cpp
Go to the documentation of this file.
00001 #include "door_swinger.h"
00002 // arm movement
00003 #include <ee_cart_imped_action/ee_cart_imped_arm.hh>
00004 #include <ee_cart_imped_msgs/EECartImpedGoal.h>
00005 
00006 #include <cmath>  //for fabs
00007 // arm movement
00008 
00009 DoorSwinger::DoorSwinger(char left_right): 
00010     serviceServer(n.advertiseService("swing_door", &DoorSwinger::swing_door, this)),
00011     controller_name_("/l_arm_cart_imped_controller")
00012 {
00013   std::string client_name = "/l_gripper_controller/gripper_action";
00014   if(left_right == 'r') client_name[1] = left_right;
00015   if(left_right == 'r') controller_name_[1] = left_right;
00016 
00017   gripperClient = new gripActClient(client_name, true); 
00018   //wait for the gripper action server to come up
00019   ROS_INFO("door_swinger/swing_door service ready");
00020 }
00021 
00022 DoorSwinger::~DoorSwinger(){
00023   delete gripperClient;
00024 }
00025 
00026 void DoorSwinger::use_gripper(float position, float effort) // Do not limit effort with negative value
00027 {
00028     while(!gripperClient->waitForServer(ros::Duration(5.0)) && ros::ok())
00029         ROS_INFO("Should use gripper, but I am waiting for the gripper action server to come up");
00030 
00031     pr2_controllers_msgs::Pr2GripperCommandGoal goal;
00032     goal.command.position = position;
00033     goal.command.max_effort = effort;  
00034 
00035     gripperClient->sendGoal(goal);
00036 }
00037 bool DoorSwinger::wait_for_gripper(){ // Do not limit effort with negative value
00038     gripperClient->waitForResult();
00039 
00040     if(gripperClient->getState() == actionlib::SimpleClientGoalState::SUCCEEDED){
00041         ROS_INFO("Successfully used gripper!");
00042         return true;
00043     } else {
00044         ROS_ERROR("Failed to use gripper"); 
00045         return false;
00046     }
00047 }
00048 
00049 void DoorSwinger::home_position()
00050 {
00051     EECartImpedArm arm_r(controller_name_);
00052     ee_cart_imped_msgs::EECartImpedGoal homePos;//,traj_l;
00053 
00054     tf::Quaternion r(tf::Vector3(1,0,0), -M_PI/2.0);//gripper rotation
00055     EECartImpedArm::addTrajectoryPoint(homePos, 0.65, -0.00,0.20, r.getX(), r.getY(), r.getZ(), r.getW(),
00056                                        500, 500, 500, 30, 30, 30, //torques
00057                                        false, false, false, false, false,false,//stiff (not torqe)
00058                                        2, "/torso_lift_link");//cumulative time
00059     arm_r.startTrajectory(homePos);
00060 }
00061 
00062 void DoorSwinger::withdraw(float meters)
00063 {
00064     // tf stuff
00065     tf::StampedTransform gripper_transform;
00066     //wait for transformation of gripper
00067     ros::Time now = ros::Time::now();
00068     while(!tflistener.waitForTransform("/torso_lift_link", "/r_gripper_tool_frame",now, ros::Duration(6.0/30.0))){
00069       ROS_WARN("No tranform from /torso_lift_link to /r_gripper_tool_frame available");
00070       now = ros::Time::now();
00071     }
00072     tflistener.lookupTransform("/torso_lift_link", "/r_gripper_tool_frame", now, gripper_transform);
00073     tf::Vector3 gripperBackward(-meters, 0,0); 
00074     gripperBackward = gripper_transform * gripperBackward;
00075 
00076     float px,py,pz,rx,ry,rz,rw;
00077     px = gripperBackward.getX();
00078     py = gripperBackward.getY();
00079     pz = gripperBackward.getZ();
00080 
00081     rx = gripper_transform.getRotation().getX();
00082     ry = gripper_transform.getRotation().getY();
00083     rz = gripper_transform.getRotation().getZ();
00084     rw = gripper_transform.getRotation().getW();
00085 
00086     ee_cart_imped_msgs::EECartImpedGoal withdrawTraj;//,traj_l;
00087     EECartImpedArm arm_r(controller_name_);
00088     EECartImpedArm::addTrajectoryPoint(withdrawTraj, px,py,pz, rx, ry, rz, rw,
00089                                        1000, 1000, 1000, 1, 1, 1, //torques
00090                                        false, false, false, false, false,false,//stiff (not torqe)
00091                                        1.5, "/torso_lift_link");//cumulative time
00092     arm_r.startTrajectory(withdrawTraj);
00093 }
00094 
00095 bool DoorSwinger::swing_door(std_srvs::Empty::Request&, std_srvs::Empty::Response&)
00096 {
00097     ee_cart_imped_msgs::EECartImpedGoal door;
00098 
00099     //ROS_INFO("closing gripper");
00100     //use_gripper(0.00, -1.0 );
00101     //home_position();
00102     // go to pregrasp
00103     tf::Quaternion r(tf::Vector3(0,1,0), -M_PI/2.0);//gripper rotation
00104     /*
00105     EECartImpedArm::addTrajectoryPoint(door, 0.15, +0.2, -0.1,r.getX(), r.getY(), r.getZ(), r.getW(),
00106                                        200, 200, 200,//forces
00107                                        30, 30, 30, //torques
00108                                        false, false, false,//stiff (not force)
00109                                        false, false,false,//stiff (not torqe)
00110                                        3, "/checkerboard_0"); //cumulative time
00111                                        */
00112     // go to middle of door
00113     EECartImpedArm::addTrajectoryPoint(door, 0.00, 0.0, 0.15, 0,0,0,1,
00114                                        1000, 1000, 300,//forces
00115                                        30, 30, 30, //torques
00116                                        false, false, false,//stiff (not force)
00117                                        false, false,false,//stiff (not torqe)
00118                                        3, "/torso_lift_link");//cumulative time
00119 
00120     // touch
00121     EECartImpedArm::addTrajectoryPoint(door, 0.10, 0.0, 0.0, 0,0,0,1,
00122                                        100, 100, 30,//forces
00123                                        30, 30, 30, //torques
00124                                        false, false, false,//stiff (not force)
00125                                        false, false,false,//stiff (not torqe)
00126                                        8, "/l_gripper_l_finger_tip_link");//cumulative time
00127 
00128     // push
00129     EECartImpedArm::addTrajectoryPoint(door, 0.20, 0.0, 0.0, 0,0,0,1,
00130                                        1000, 1000, 1000,//forces
00131                                        30, 30, 30, //torques
00132                                        false, false, false,//stiff (not force)
00133                                        false, false,false,//stiff (not torqe)
00134                                        9, "/l_gripper_l_finger_tip_link");//cumulative time
00135 
00136     /*
00137     EECartImpedArm::addTrajectoryPoint(door, 0.15, +0.2, 0.28, r.getX(), r.getY(), r.getZ(), r.getW(),
00138                                        1000, 1000, 1000,//forces
00139                                        30, 30, 30, //torques
00140                                        false, false, false,//stiff (not force)
00141                                        false, false,false,//stiff (not torqe)
00142                                        6, "/checkerboard_0");//cumulative time
00143    */
00144     /* go back to pregrasp
00145     EECartImpedArm::addTrajectoryPoint(door, 0.05, -0.3, -0.1,r.getX(), r.getY(), r.getZ(), r.getW(),
00146                                        100, 100, 100,//forces
00147                                        30, 30, 30, //torques
00148                                        false, false, false,//stiff (not force)
00149                                        false, false,false,//stiff (not torqe)
00150                                        9, "/checkerboard_0"); //cumulative time
00151     */
00152     //home
00153 
00154     EECartImpedArm arm_r(controller_name_);
00155     EECartImpedClient* traj_client = arm_r.startTrajectory(door);
00156     actionlib::SimpleClientGoalState state = traj_client->getState();
00157     // The door might still be open, so don't signal failure
00158     //if (state != actionlib::SimpleClientGoalState::SUCCEEDED)
00159       //return false;
00160     wait_for_gripper();
00161 
00162     //withdraw(.2);//10 cm
00163     //home_position();
00164     return true;
00165 }
00166 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


door_manipulation_tools
Author(s): Felix Endres
autogenerated on Wed Dec 26 2012 16:02:19