-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm.py
72 lines (54 loc) · 2.19 KB
/
arm.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
71
72
import math
from interbotix_xs_modules.xs_robot.arm import InterbotixManipulatorXS
from interbotix_common_modules.common_robot.robot import robot_shutdown, robot_startup
# The robot object is what you use to control the robot
class Robot:
def __init__(self):
self.robot = InterbotixManipulatorXS("px100", "arm", "gripper")
robot_startup()
current_states = self.robot.core.robot_get_joint_states()
self.positions = {
'waist': math.degrees(current_states.position[0]),
'shoulder': math.degrees(current_states.position[1]),
'elbow': math.degrees(current_states.position[2]),
'wrist_angle': math.degrees(current_states.position[3])
}
def get_joint_position(self, joint):
return self.positions[joint]
def set_joint_position(self, joint, angle):
if joint == 'waist':
if angle > 180 or angle < -180:
print('Invalid Waist Angle')
return
elif joint == 'shoulder':
if angle > 107 or angle < -111:
print('Invalid shoulder Angle')
return
elif joint == 'elbow':
if angle > 92 or angle < -121:
print('Invalid elbow Angle')
return
elif joint == 'wrist_angle':
if angle > 123 or angle < -100:
print('Invalid Wrist Angle')
return
else:
print('Invalid parameters. Cannot move')
return
self.robot.arm.set_single_joint_position(joint, math.radians(angle))
self.positions[joint] = angle
def set_xyz(self, xyz):
self.robot.arm.set_ee_pose_components(x=xyz[0], y=xyz[1], z=xyz[2])
def get_xyz(self):
arm_positions = self.robot.arm.get_ee_pose()
return arm_positions[0][3], arm_positions[1][3], arm_positions[2][3]
def grasp(self):
self.robot.gripper.grasp()
def release(self):
self.robot.gripper.release()
def go_home(self):
self.robot.arm.go_to_home_pose()
def go_sleep(self):
self.robot.arm.go_to_sleep_pose()
def end(self):
robot_shutdown()