-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplz.py
70 lines (54 loc) · 2.6 KB
/
plz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import intera_interface
import rospy
import copy
from geometry_msgs.msg import Pose, Point, Quaternion
g_limb = None
g_orientation_hand_down = None
g_position_neutral = None
def init():
global g_limb, g_orientation_hand_down, g_position_neutral
rospy.init_node('cairo_sawyer_ik_example')
g_limb = intera_interface.Limb('right')
# This quaternion will have the hand face straight down (ideal for picking tasks)
g_orientation_hand_down = Quaternion()
g_orientation_hand_down.x = 0.704238785359
g_orientation_hand_down.y =0.709956638597
g_orientation_hand_down.z = -0.00229009932359
g_orientation_hand_down.w = 0.00201493272073
# This is the default neutral position for the robot's hand (no guarantee this will move the joints to neutral though)
g_position_neutral = Point()
g_position_neutral.x = 0.449559195663
g_position_neutral.y = 0.16070379419
g_position_neutral.z = 0.212938808947
def main():
global g_limb, g_position_neutral, g_orientation_hand_down
init()
# Move the arm to its neutral position
g_limb.move_to_neutral()
rospy.loginfo("Old Hand Pose:\n %s" % str(g_limb._tip_states.states[0].pose))
rospy.loginfo("Old Joint Angles:\n %s" % str(g_limb.joint_angles()))
# Create a new pose (Position and Orientation) to solve for
target_pose = Pose()
target_pose.position = copy.deepcopy(g_position_neutral)
target_pose.orientation = copy.deepcopy(g_orientation_hand_down)
#MOVE THE ARM
target_pose.position.x += 0.2 # Add 20cm to the x axis position of the hand
target_pose.position.y += 0.2
# Call the IK service to solve for joint angles for the desired pose
target_joint_angles = g_limb.ik_request(target_pose, "right_hand")
# The IK Service returns false if it can't find a joint configuration
if target_joint_angles is False:
rospy.logerr("Couldn't solve for position %s" % str(target_pose))
return
# Set the robot speed (takes a value between 0 and 1)
g_limb.set_joint_position_speed(0.3)
# Send the robot arm to the joint angles in target_joint_angles, wait up to 2 seconds to finish
g_limb.move_to_joint_positions(target_joint_angles, timeout=2)
# Find the new coordinates of the hand and the angles the motors are currently at
new_hand_pose = copy.deepcopy(g_limb._tip_states.states[0].pose)
new_angles = g_limb.joint_angles()
rospy.loginfo("New Hand Pose:\n %s" % str(new_hand_pose))
rospy.loginfo("Target Joint Angles:\n %s" % str(target_joint_angles))
rospy.loginfo("New Joint Angles:\n %s" % str(new_angles))
if __name__ == "__main__":
main()