-
Notifications
You must be signed in to change notification settings - Fork 5
/
eval_agent.py
83 lines (68 loc) · 2.31 KB
/
eval_agent.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
73
74
75
76
77
78
79
80
81
82
83
"""
Evaluation Agent.
"""
import time
import numpy as np
from device.robot.flexiv import FlexivRobot
from utils.transformation import xyz_rot_transform
from device.gripper.dahuan import DahuanModbusGripper
from device.camera.realsense import RealSenseRGBDCamera
class Agent:
"""
Evaluation agent with Flexiv arm, Dahuan gripper and Intel RealSense RGB-D camera.
Follow the implementation here to create your own real-world evaluation agent.
"""
def __init__(
self,
robot_ip,
pc_ip,
gripper_port,
camera_serial,
**kwargs
):
self.camera_serial = camera_serial
print("Init robot, gripper, and camera.")
self.robot = FlexivRobot(robot_ip_address = robot_ip, pc_ip_address = pc_ip)
self.robot.send_tcp_pose(self.ready_pose)
time.sleep(1.5)
self.gripper = DahuanModbusGripper(port = gripper_port)
self.gripper.set_force(30)
self.gripper.set_width(0)
time.sleep(0.5)
self.camera = RealSenseRGBDCamera(serial = camera_serial)
for _ in range(30):
self.camera.get_rgbd_image()
print("Initialization Finished.")
@property
def intrinsics(self):
return np.array([
[922.37457275, 0, 637.55419922, 0],
[0, 922.46069336, 368.37557983, 0],
[0, 0, 1, 0]
])
@property
def ready_pose(self):
return np.array([0.5, 0.0, 0.17, 0.0, 0.0, 1.0, 0.0])
@property
def ready_rot_6d(self):
return np.array([-1, 0, 0, 0, 1, 0])
def get_observation(self):
colors, depths = self.camera.get_rgbd_image()
return colors, depths
def set_tcp_pose(self, pose, rotation_rep, rotation_rep_convention = None, blocking = False):
tcp_pose = xyz_rot_transform(
pose,
from_rep = rotation_rep,
to_rep = "quaternion",
from_convention = rotation_rep_convention
)
self.robot.send_tcp_pose(tcp_pose)
if blocking:
time.sleep(0.1)
def set_gripper_width(self, width, blocking = False):
width = int(np.clip(width / 0.095 * 1000., 0, 1000))
self.gripper.set_width(width)
if blocking:
time.sleep(0.5)
def stop(self):
self.robot.stop()