12
12
from std_msgs .msg import Float64
13
13
from std_msgs .msg import Empty
14
14
from trac_ik_python .trac_ik import IK
15
- # import camera_forward_kinematics
15
+ # import camera_forward_kinematics
16
16
import tf
17
17
import PRM
18
18
29
29
IK_POSITION_TOLERANCE = 0.01
30
30
IK_ORIENTATION_TOLERANCE = np .pi / 9
31
31
current_joint_state = None
32
+ MIN_CLOSING_GAP = 0.002
32
33
33
34
34
35
def home_arm (pub ):
@@ -56,8 +57,10 @@ def set_arm_joint(pub, joint_target):
56
57
57
58
def get_joint_state (data ):
58
59
global current_joint_state
60
+ global current_gripper_state
59
61
# if len(data.position) == 9:
60
- current_joint_state = data .position [0 :5 ]
62
+ current_gripper_state = data .positions [7 :9 ]
63
+ current_joint_state = data .positions [0 :5 ]
61
64
62
65
def open_gripper (pub ):
63
66
empty_msg = Empty ()
@@ -106,14 +109,14 @@ def compute_ik(ik_solver, target_pose, current_joint):
106
109
def main ():
107
110
rospy .init_node ('IK_Control' , anonymous = True )
108
111
global current_joint_state
109
-
112
+
110
113
rad_from_deg = np .pi / 180.
111
114
deg_from_rad = 180. / np .pi
112
115
113
116
ik_solver = IK (ARM_BASE_LINK , GRIPPER_LINK )
114
117
# ck = camera_forward_kinematics.camerakinematics()
115
118
116
- # Describing the publisher subscribers
119
+ # Describing the publisher subscribers
117
120
rospy .Subscriber ('/joint_states' , JointState , get_joint_state )
118
121
119
122
arm_pub = rospy .Publisher (ROSTOPIC_SET_ARM_JOINT , JointState , queue_size = 1 )
@@ -129,7 +132,7 @@ def main():
129
132
#home_joint = [0.0, 0.0, 1.22, -0.142, 0.0]
130
133
set_arm_joint (arm_pub , home_joint )
131
134
close_gripper (gripper_close_pub )
132
- set_camera_angles (pan_pub , tilt_pub , rad_from_deg * 0. , rad_from_deg * 40.0 ) #, ck)
135
+ set_camera_angles (pan_pub , tilt_pub , rad_from_deg * 0. , rad_from_deg * 40.0 ) #, ck)
133
136
134
137
rospy .sleep (10 )
135
138
@@ -143,11 +146,11 @@ def main():
143
146
break
144
147
except (tf .LookupException , tf .ConnectivityException , tf .ExtrapolationException ) as e :
145
148
print (e )
146
-
149
+
147
150
O = tf .transformations .euler_from_quaternion (Q )
148
151
Q = tf .transformations .quaternion_from_euler (0 , np .pi / 2 , O [2 ])
149
152
Q1 = tf .transformations .quaternion_from_euler (0 , np .pi / 2 , O [2 ]+ np .pi / 2 )
150
-
153
+
151
154
poses = [Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.20 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ])),
152
155
Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.15 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ])),
153
156
Pose (Point (P [0 ], P [1 ], P [2 ]+ 0.25 ), Quaternion (Q [0 ], Q [1 ], Q [2 ], Q [3 ])),
@@ -187,9 +190,12 @@ def main():
187
190
if itr == 0 or itr == 3 :
188
191
open_gripper (gripper_open_pub )
189
192
rospy .sleep (4 )
190
- if itr == 1 :
193
+ if itr == 1 :
191
194
close_gripper (gripper_close_pub )
192
195
rospy .sleep (4 )
196
+ # Use the following condition to detect if the object is grasped or not
197
+ if (np .abs (current_gripper_state [0 ]) < MIN_CLOSING_GAP and np .abs (current_gripper_state [1 ] < MIN_CLOSING_GAP )):
198
+ state = "Not grabbed"
193
199
rospy .sleep (4 )
194
200
itr += 1
195
201
@@ -225,4 +231,4 @@ def main():
225
231
226
232
# q = tf.transformations.quaternion_from_euler(0, 90, 0)
227
233
# poses = [Pose(Point(0.3, 0.000, 0.25), Quaternion(q[0], q[1], q[2], q[3])),
228
- # Pose(Point(0.3, 0.000, 0.10), Quaternion(q[0], q[1], q[2], q[3]))]
234
+ # Pose(Point(0.3, 0.000, 0.10), Quaternion(q[0], q[1], q[2], q[3]))]
0 commit comments