00001 #include "door_swinger.h"
00002
00003 #include <ee_cart_imped_action/ee_cart_imped_arm.hh>
00004 #include <ee_cart_imped_msgs/EECartImpedGoal.h>
00005
00006 #include <cmath>
00007
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
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)
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(){
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;
00053
00054 tf::Quaternion r(tf::Vector3(1,0,0), -M_PI/2.0);
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,
00057 false, false, false, false, false,false,
00058 2, "/torso_lift_link");
00059 arm_r.startTrajectory(homePos);
00060 }
00061
00062 void DoorSwinger::withdraw(float meters)
00063 {
00064
00065 tf::StampedTransform gripper_transform;
00066
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;
00087 EECartImpedArm arm_r(controller_name_);
00088 EECartImpedArm::addTrajectoryPoint(withdrawTraj, px,py,pz, rx, ry, rz, rw,
00089 1000, 1000, 1000, 1, 1, 1,
00090 false, false, false, false, false,false,
00091 1.5, "/torso_lift_link");
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
00100
00101
00102
00103 tf::Quaternion r(tf::Vector3(0,1,0), -M_PI/2.0);
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 EECartImpedArm::addTrajectoryPoint(door, 0.00, 0.0, 0.15, 0,0,0,1,
00114 1000, 1000, 300,
00115 30, 30, 30,
00116 false, false, false,
00117 false, false,false,
00118 3, "/torso_lift_link");
00119
00120
00121 EECartImpedArm::addTrajectoryPoint(door, 0.10, 0.0, 0.0, 0,0,0,1,
00122 100, 100, 30,
00123 30, 30, 30,
00124 false, false, false,
00125 false, false,false,
00126 8, "/l_gripper_l_finger_tip_link");
00127
00128
00129 EECartImpedArm::addTrajectoryPoint(door, 0.20, 0.0, 0.0, 0,0,0,1,
00130 1000, 1000, 1000,
00131 30, 30, 30,
00132 false, false, false,
00133 false, false,false,
00134 9, "/l_gripper_l_finger_tip_link");
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 EECartImpedArm arm_r(controller_name_);
00155 EECartImpedClient* traj_client = arm_r.startTrajectory(door);
00156 actionlib::SimpleClientGoalState state = traj_client->getState();
00157
00158
00159
00160 wait_for_gripper();
00161
00162
00163
00164 return true;
00165 }
00166