@@ -25,6 +25,7 @@ def __init__(self):
25
25
# global variables
26
26
self .current_joint_state = None
27
27
self .current_gripper_state = None
28
+ self .current_target_state = None
28
29
29
30
# global frames
30
31
self .GRIPPER_LINK = "gripper_link"
@@ -38,10 +39,11 @@ def __init__(self):
38
39
self .HOME_POS_MANIPULATOR_01 = [0.004601942375302315 , - 0.4218447208404541 , 1.6260197162628174 , - 0.1426602154970169 , 0.010737866163253784 ]
39
40
self .HOME_POS_MANIPULATOR_02 = [0.0 , 0.0 , 1.22 , - 1.57 , 1.57 ]
40
41
self .HOME_POS_CAMERA_01 = [0.0 , 0.698 ]
41
- self .HOME_POS_CAMERA_02 = [- 0.523 , - 0.523 ]
42
+ self .HOME_POS_CAMERA_02 = [- 0.452 , - 0.452 ]
42
43
self .IK_POSITION_TOLERANCE = 0.01
43
- self .IK_ORIENTATION_TOLERANCE = np .pi / 9
44
+ self .IK_ORIENTATION_TOLERANCE = np .pi / 7
44
45
self .MIN_CLOSING_GAP = 0.002
46
+ self .MOVEABLE_JOINTS = [0 ,4 ]
45
47
46
48
def set_camera_angles (self , angles ):
47
49
pan_msg = Float64 ()
@@ -53,25 +55,24 @@ def set_camera_angles(self, angles):
53
55
tilt_msg .data = float (angles [1 ])
54
56
rospy .loginfo ('Going to camera tilt: {} rad' .format (angles [1 ]))
55
57
self .tilt_pub .publish (tilt_msg )
56
- rospy .sleep (4 )
57
58
58
59
def set_arm_joint_angles (self , joint_target ):
59
60
joint_state = JointState ()
60
61
joint_state .position = tuple (joint_target )
61
62
rospy .loginfo ('Going to arm joint 0: {} rad' .format (joint_target [0 ]))
62
63
self .arm_pub .publish (joint_state )
63
- rospy .sleep (4 )
64
+ rospy .sleep (6 )
64
65
65
66
def get_joint_state (self , data ):
66
67
# TODO: Change this when required
67
- moveable_joints = [ 1 , 2 , 3 ]
68
+
68
69
# Add timestamp
69
70
self .history ['timestamp' ].append (time .time ())
70
71
if (len (self .history ['timestamp' ]) > 20 ):
71
72
self .history ['timestamp' ].popleft ()
72
73
73
74
# Add Joint Feedback
74
- joint_angles = np .array (data .position )[moveable_joints ]
75
+ joint_angles = np .array (data .position )[self . MOVEABLE_JOINTS ]
75
76
self .history ['joint_feedback' ].append (joint_angles )
76
77
if (len (self .history ['joint_feedback' ]) > 20 ):
77
78
self .history ['joint_feedback' ].popleft ()
@@ -137,8 +138,8 @@ def go_to_grasp_pose(self, FRAME):
137
138
O = tf .transformations .euler_from_quaternion (Q )
138
139
Q = tf .transformations .quaternion_from_euler (0 , np .pi / 2 , O [2 ])
139
140
140
- poses = [Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.20 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ])),
141
- Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.15 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ]))]
141
+ poses = [Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.15 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ])),
142
+ Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.10 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ]))]
142
143
143
144
target_joint = None
144
145
self .open_gripper ()
@@ -151,7 +152,7 @@ def go_to_grasp_pose(self, FRAME):
151
152
152
153
if target_joint :
153
154
self .set_arm_joint_angles (target_joint )
154
- rospy . sleep ( 8 )
155
+ self . current_target_state = np . array ( target_joint )[ self . MOVEABLE_JOINTS ]
155
156
else :
156
157
return False
157
158
return True
@@ -171,7 +172,7 @@ def check_grasp(self):
171
172
172
173
# Goes to the position given by FRAME and grabs the object from the top
173
174
def go_to_handover_pose (self , pose ):
174
- # print(pose)
175
+ print (pose )
175
176
try :
176
177
self .tf_listener .waitForTransform (self .BOTTOM_PLATE_LINK , pose .header .frame_id , rospy .Time .now (), rospy .Duration (5.0 ))
177
178
P , Q = self .tf_listener .lookupTransform (self .BOTTOM_PLATE_LINK , pose .header .frame_id , rospy .Time (0 ))
@@ -182,20 +183,23 @@ def go_to_handover_pose(self, pose):
182
183
O = tf .transformations .euler_from_quaternion (Q )
183
184
Q = tf .transformations .quaternion_from_euler (0 , - np .pi / 3 , O [2 ])
184
185
185
- poses = [ Pose (Point (P [0 ], P [1 ], P [2 ]- 0.45 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ]))]
186
+ poses = Pose (Point (P [0 ], P [1 ], P [2 ]- 0.45 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ]))
186
187
187
188
target_joint = None
188
- while target_joint is not None :
189
+ while target_joint is None :
189
190
if self .current_joint_state :
190
- target_joint = self .compute_ik (pose )
191
+ target_joint = self .compute_ik (poses )
191
192
else :
192
193
print ("Joint State Subscriber not working" )
193
194
return False
194
195
195
196
if target_joint :
197
+ print (target_joint )
196
198
self .set_arm_joint_angles (target_joint )
197
- rospy . sleep ( 8 )
199
+ self . current_target_state = np . array ( target_joint )[ self . MOVEABLE_JOINTS ]
198
200
else :
199
- self .IK_POSITION_TOLERANCE += 0.1
201
+ rospy .logwarn ("No Solution was found. Current Tolerance " + str (self .IK_POSITION_TOLERANCE ))
202
+ self .IK_POSITION_TOLERANCE += 0.05
203
+ print (target_joint )
200
204
return True
201
205
0 commit comments