-
Notifications
You must be signed in to change notification settings - Fork 1
/
eval_agent.py
84 lines (69 loc) · 2.44 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
84
"""
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.gripper.robotiq import Robotiq2FGripper
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 = Robotiq2FGripper(port = gripper_port)
# self.gripper.set_force(30)
self.gripper.close_gripper()
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([[915.384521484375, 0, 633.3715209960938, 0],
[0, 914.9421997070312, 354.1505432128906, 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):
print(width, end=" ")
width = int(np.clip((1.0 - width / 0.085) * 255., 0, 255))
print(width)
self.gripper.action(width)
if blocking:
time.sleep(0.5)
def stop(self):
self.robot.stop()