Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import roslib
00035 roslib.load_manifest('pr2_delivery')
00036
00037 import rospy
00038
00039 from trajectory_msgs.msg import *
00040 from actionlib_msgs.msg import *
00041 from pr2_controllers_msgs.msg import *
00042 from pr2_gripper_sensor_msgs.msg import *
00043 import actionlib
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 class Robot:
00054 def __init__(self):
00055 self.joint_names = ["shoulder_pan",
00056 "shoulder_lift",
00057 "upper_arm_roll",
00058 "elbow_flex",
00059 "forearm_roll",
00060 "wrist_flex",
00061 "wrist_roll" ]
00062
00063
00064 self.left_joint_client = actionlib.SimpleActionClient('l_arm_controller/joint_trajectory_action', JointTrajectoryAction)
00065 self.right_joint_client = actionlib.SimpleActionClient('r_arm_controller/joint_trajectory_action', JointTrajectoryAction)
00066 self.right_gripper_client = actionlib.SimpleActionClient('r_gripper_sensor_controller/gripper_action', Pr2GripperCommandAction)
00067 self.right_contact_client = actionlib.SimpleActionClient('r_gripper_sensor_controller/find_contact', PR2GripperFindContactAction)
00068 self.right_force_client = actionlib.SimpleActionClient('r_gripper_sensor_controller/force_servo', PR2GripperForceServoAction)
00069
00070
00071 for client in [self.left_joint_client,
00072 self.right_joint_client,
00073 self.right_gripper_client,
00074 self.right_contact_client,
00075 self.right_force_client]:
00076 if not client.wait_for_server(rospy.Duration(30)):
00077 rospy.logerr("Robot.py: '%s' action server did not come up within timelimit" % client.action_client.ns)
00078
00079 def move_arm_to(self, side, joint_values, duration):
00080 """side is 'l' or 'r'.
00081 joint_values is an array of 7 joint values."""
00082 goal = JointTrajectoryGoal()
00083 goal.trajectory.joint_names = [side+"_"+name+"_joint" for name in self.joint_names]
00084 goal.trajectory.points = []
00085 goal.trajectory.points.append(JointTrajectoryPoint( positions = joint_values,
00086 velocities = [],
00087 accelerations = [],
00088 time_from_start = rospy.Duration(duration)))
00089 goal.trajectory.header.stamp = rospy.get_rostime() + rospy.Duration(0.01)
00090 client = {'l': self.left_joint_client, 'r': self.right_joint_client}[side]
00091 return client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00092
00093 def open_right_gripper(self)
00094 goal = Pr2GripperCommandGoal()
00095 goal.command.position = 0.08
00096 goal.command.max_effort = -1
00097 return self.right_gripper_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00098
00099 def grab_with_right_gripper(self):
00100 """Close gripper until we sense contact on both fingers."""
00101 goal = PR2GripperFindContactGoal()
00102 goal.command.contact_conditions = goal.command.BOTH
00103 goal.command.zero_fingertip_sensors = True
00104 return self.right_contact_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00105
00106 def hold_with_right_gripper(self, hold_force = 10.0):
00107 """Hold somethign with a constant force (in Newtons) in the gripper"""
00108 goal = PR2GripperForceServoGoal()
00109 goal.command.fingertip_force = hold_force
00110 return self.right_force_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00111
00112 def right_grip(self, position, max_effort = -1):
00113 goal = Pr2GripperCommandGoal()
00114 goal.command.position = position
00115 goal.command.max_effort = max_effort
00116 return self.right_gripper_client.send_goal_and_wait(goal, rospy.Duration(30.0), rospy.Duration(5.0))
00117
00118
00119 int main(int argc, char** argv){
00120 ros::init(argc, argv, "simple_gripper");
00121
00122 Gripper gripper;
00123
00124 gripper.open();
00125 sleep(2.0);
00126
00127 gripper.findTwoContacts();
00128 gripper.hold(10.0); // hold with 10 N of force
00129
00130 return 0;
00131 }