Skip to content

Commit 23e39a1

Browse files
committed
Added state for object grasped
1 parent 5404d7f commit 23e39a1

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

scripts/ik_control.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from std_msgs.msg import Float64
1313
from std_msgs.msg import Empty
1414
from trac_ik_python.trac_ik import IK
15-
# import camera_forward_kinematics
15+
# import camera_forward_kinematics
1616
import tf
1717
import PRM
1818

@@ -29,6 +29,7 @@
2929
IK_POSITION_TOLERANCE = 0.01
3030
IK_ORIENTATION_TOLERANCE = np.pi/9
3131
current_joint_state = None
32+
MIN_CLOSING_GAP = 0.002
3233

3334

3435
def home_arm(pub):
@@ -56,8 +57,10 @@ def set_arm_joint(pub, joint_target):
5657

5758
def get_joint_state(data):
5859
global current_joint_state
60+
global current_gripper_state
5961
# 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]
6164

6265
def open_gripper(pub):
6366
empty_msg = Empty()
@@ -106,14 +109,14 @@ def compute_ik(ik_solver, target_pose, current_joint):
106109
def main():
107110
rospy.init_node('IK_Control', anonymous=True)
108111
global current_joint_state
109-
112+
110113
rad_from_deg = np.pi/180.
111114
deg_from_rad = 180./np.pi
112115

113116
ik_solver = IK(ARM_BASE_LINK, GRIPPER_LINK)
114117
# ck = camera_forward_kinematics.camerakinematics()
115118

116-
# Describing the publisher subscribers
119+
# Describing the publisher subscribers
117120
rospy.Subscriber('/joint_states', JointState, get_joint_state)
118121

119122
arm_pub = rospy.Publisher(ROSTOPIC_SET_ARM_JOINT, JointState, queue_size=1)
@@ -129,7 +132,7 @@ def main():
129132
#home_joint = [0.0, 0.0, 1.22, -0.142, 0.0]
130133
set_arm_joint(arm_pub, home_joint)
131134
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)
133136

134137
rospy.sleep(10)
135138

@@ -143,11 +146,11 @@ def main():
143146
break
144147
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException) as e:
145148
print(e)
146-
149+
147150
O = tf.transformations.euler_from_quaternion(Q)
148151
Q = tf.transformations.quaternion_from_euler(0, np.pi/2, O[2])
149152
Q1 = tf.transformations.quaternion_from_euler(0, np.pi/2, O[2]+np.pi/2)
150-
153+
151154
poses = [Pose(Point(P[0], P[1], P[2]+0.20), Quaternion(Q[0], Q[1], Q[2], Q[3])),
152155
Pose(Point(P[0], P[1], P[2]+0.15), Quaternion(Q[0], Q[1], Q[2], Q[3])),
153156
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():
187190
if itr == 0 or itr == 3:
188191
open_gripper(gripper_open_pub)
189192
rospy.sleep(4)
190-
if itr == 1:
193+
if itr == 1:
191194
close_gripper(gripper_close_pub)
192195
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"
193199
rospy.sleep(4)
194200
itr += 1
195201

@@ -225,4 +231,4 @@ def main():
225231

226232
# q = tf.transformations.quaternion_from_euler(0, 90, 0)
227233
# 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

Comments
 (0)