@@ -25,6 +25,7 @@ def __init__(self):
2525 # global variables
2626 self .current_joint_state = None
2727 self .current_gripper_state = None
28+ self .current_target_state = None
2829
2930 # global frames
3031 self .GRIPPER_LINK = "gripper_link"
@@ -38,10 +39,11 @@ def __init__(self):
3839 self .HOME_POS_MANIPULATOR_01 = [0.004601942375302315 , - 0.4218447208404541 , 1.6260197162628174 , - 0.1426602154970169 , 0.010737866163253784 ]
3940 self .HOME_POS_MANIPULATOR_02 = [0.0 , 0.0 , 1.22 , - 1.57 , 1.57 ]
4041 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 ]
4243 self .IK_POSITION_TOLERANCE = 0.01
43- self .IK_ORIENTATION_TOLERANCE = np .pi / 9
44+ self .IK_ORIENTATION_TOLERANCE = np .pi / 7
4445 self .MIN_CLOSING_GAP = 0.002
46+ self .MOVEABLE_JOINTS = [0 ,4 ]
4547
4648 def set_camera_angles (self , angles ):
4749 pan_msg = Float64 ()
@@ -53,25 +55,24 @@ def set_camera_angles(self, angles):
5355 tilt_msg .data = float (angles [1 ])
5456 rospy .loginfo ('Going to camera tilt: {} rad' .format (angles [1 ]))
5557 self .tilt_pub .publish (tilt_msg )
56- rospy .sleep (4 )
5758
5859 def set_arm_joint_angles (self , joint_target ):
5960 joint_state = JointState ()
6061 joint_state .position = tuple (joint_target )
6162 rospy .loginfo ('Going to arm joint 0: {} rad' .format (joint_target [0 ]))
6263 self .arm_pub .publish (joint_state )
63- rospy .sleep (4 )
64+ rospy .sleep (6 )
6465
6566 def get_joint_state (self , data ):
6667 # TODO: Change this when required
67- moveable_joints = [ 1 , 2 , 3 ]
68+
6869 # Add timestamp
6970 self .history ['timestamp' ].append (time .time ())
7071 if (len (self .history ['timestamp' ]) > 20 ):
7172 self .history ['timestamp' ].popleft ()
7273
7374 # Add Joint Feedback
74- joint_angles = np .array (data .position )[moveable_joints ]
75+ joint_angles = np .array (data .position )[self . MOVEABLE_JOINTS ]
7576 self .history ['joint_feedback' ].append (joint_angles )
7677 if (len (self .history ['joint_feedback' ]) > 20 ):
7778 self .history ['joint_feedback' ].popleft ()
@@ -137,8 +138,8 @@ def go_to_grasp_pose(self, FRAME):
137138 O = tf .transformations .euler_from_quaternion (Q )
138139 Q = tf .transformations .quaternion_from_euler (0 , np .pi / 2 , O [2 ])
139140
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 ]))]
142143
143144 target_joint = None
144145 self .open_gripper ()
@@ -151,7 +152,7 @@ def go_to_grasp_pose(self, FRAME):
151152
152153 if target_joint :
153154 self .set_arm_joint_angles (target_joint )
154- rospy . sleep ( 8 )
155+ self . current_target_state = np . array ( target_joint )[ self . MOVEABLE_JOINTS ]
155156 else :
156157 return False
157158 return True
@@ -171,7 +172,7 @@ def check_grasp(self):
171172
172173 # Goes to the position given by FRAME and grabs the object from the top
173174 def go_to_handover_pose (self , pose ):
174- # print(pose)
175+ print (pose )
175176 try :
176177 self .tf_listener .waitForTransform (self .BOTTOM_PLATE_LINK , pose .header .frame_id , rospy .Time .now (), rospy .Duration (5.0 ))
177178 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):
182183 O = tf .transformations .euler_from_quaternion (Q )
183184 Q = tf .transformations .quaternion_from_euler (0 , - np .pi / 3 , O [2 ])
184185
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 ]))
186187
187188 target_joint = None
188- while target_joint is not None :
189+ while target_joint is None :
189190 if self .current_joint_state :
190- target_joint = self .compute_ik (pose )
191+ target_joint = self .compute_ik (poses )
191192 else :
192193 print ("Joint State Subscriber not working" )
193194 return False
194195
195196 if target_joint :
197+ print (target_joint )
196198 self .set_arm_joint_angles (target_joint )
197- rospy . sleep ( 8 )
199+ self . current_target_state = np . array ( target_joint )[ self . MOVEABLE_JOINTS ]
198200 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 )
200204 return True
201205
0 commit comments