-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfranka.py
More file actions
198 lines (174 loc) · 6.83 KB
/
Copy pathfranka.py
File metadata and controls
198 lines (174 loc) · 6.83 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import logging
import numpy as np
from rcs._core.common import BaseCameraConfig, RobotPlatform
from rcs._core.sim import SimConfig
from rcs.envs.base import ControlMode, RelativeTo
from rcs.envs.configs import EmptyWorldFR3Duo
from rcs.envs.storage_wrapper import StorageWrapper
from rcs.envs.tasks import PickTaskConfig
from rcs.operator.gello import GelloConfig, GelloOperator
from rcs.operator.interface import TeleopLoop
from rcs.operator.quest import QuestConfig, QuestOperator
from simpub.sim.mj_publisher import MujocoPublisher
import rcs
logger = logging.getLogger(__name__)
ROBOT2IP = {
"right": "192.168.102.1",
"left": "192.168.101.1",
}
ROBOT2ID = {
"left": "1",
"right": "0",
}
ROBOT_INSTANCE = RobotPlatform.SIMULATION
# use `udevadm info -a -n /dev/ttyUSB0 | grep serial`
# to find out the serial numbers
ROBOTIQ_SERIAL = {
"left": "DAAQMPDC",
"right": "DAAQMJHX",
}
RECORD_FPS = 30
# set camera dict to none disable cameras
CAMERA_DICT = {
"right_wrist": "230422272017",
"left_wrist": "230422271040",
# "side": "243522070385",
# "bird_eye": "243522070364",
}
# CAMERA_DICT = None
ZED_CAMERA_DICT = {
"head": "19928076",
}
# ZED_CAMERA_DICT = None
MQ3_ADDR = "10.42.0.1"
INCLUDE_DEPTH = False
# DIGIT_DICT = {
# "digit_right_left": "D21182",
# "digit_right_right": "D21193"
# }
DIGIT_DICT = None
DATASET_PATH = "test_iris"
INSTRUCTION = "pick up cube"
RECORD_FPS = 30
robot2world = {
"right": rcs.common.Pose(
translation=np.array([0, 0, 0]), rpy_vector=np.array([0.89360858, -0.17453293, 0.46425758])
),
"left": rcs.common.Pose(
translation=np.array([0, 0, 0]), rpy_vector=np.array([-0.89360858, -0.17453293, -0.46425758])
),
}
config: QuestConfig | GelloConfig
config = QuestConfig(
mq3_addr=MQ3_ADDR,
simulation=ROBOT_INSTANCE == RobotPlatform.SIMULATION,
switched_left_right=False,
display_cameras=False,
)
# config = GelloConfig(
# arms={
# "right": GelloArmConfig(com_port="/dev/serial/by-id/usb-ROBOTIS_OpenRB-150_E505008B503059384C2E3120FF07332D-if00"),
# "left": GelloArmConfig(com_port="/dev/serial/by-id/usb-ROBOTIS_OpenRB-150_ABA78B05503059384C2E3120FF062F26-if00"),
# },
# simulation=ROBOT_INSTANCE == RobotPlatform.SIMULATION,
# )
def get_env():
if ROBOT_INSTANCE == RobotPlatform.HARDWARE:
from rcs_fr3.configs import FrankaDuoEnv
from rcs_fr3.creators import HardwareCameraCreatorConfig
env_creator = FrankaDuoEnv()
env_creator.left_ip = ROBOT2IP["left"]
env_creator.right_ip = ROBOT2IP["right"]
hw_cfg = env_creator.config()
camera_cfgs: dict[str, HardwareCameraCreatorConfig] = {}
if CAMERA_DICT is not None:
camera_cfgs["realsense"] = HardwareCameraCreatorConfig(
camera_type_id="realsense",
camera_cfgs={
name: BaseCameraConfig(
identifier=identifier,
resolution_width=1280,
resolution_height=720,
frame_rate=30,
)
for name, identifier in CAMERA_DICT.items()
},
)
if ZED_CAMERA_DICT is not None:
camera_cfgs["zed"] = HardwareCameraCreatorConfig(
camera_type_id="zed",
camera_cfgs={
name: BaseCameraConfig(
identifier=identifier,
resolution_width=1280,
resolution_height=720,
frame_rate=30,
)
for name, identifier in ZED_CAMERA_DICT.items()
},
kwargs={
"enable_depth": INCLUDE_DEPTH,
"enable_imu": False,
"include_right": True,
},
)
if DIGIT_DICT is not None:
camera_cfgs["digit"] = HardwareCameraCreatorConfig(
camera_type_id="digit",
camera_cfgs={
name: BaseCameraConfig(
identifier=identifier,
resolution_width=320,
resolution_height=240,
frame_rate=30,
)
for name, identifier in DIGIT_DICT.items()
},
)
hw_cfg.camera_cfgs = camera_cfgs or None
hw_cfg.control_mode = config.operator_class.control_mode[0]
hw_cfg.wrapper_cfg.include_depth = INCLUDE_DEPTH
hw_cfg.wrapper_cfg.binary_gripper = False
# hw_cfg.wrapper_cfg.binary_gripper = True
hw_cfg.max_relative_movement = (
0.5 if config.operator_class.control_mode[0] == ControlMode.JOINTS else (0.5, np.deg2rad(90))
)
hw_cfg.relative_to = config.operator_class.control_mode[1]
hw_cfg.robot_to_shared_base_frame = robot2world
hw_cfg.robot_cfgs["left"].ignore_realtime = True
hw_cfg.robot_cfgs["right"].ignore_realtime = True
hw_cfg.robot_cfgs["left"].speed_factor = 0.3
hw_cfg.robot_cfgs["right"].speed_factor = 0.3
hw_cfg.gripper_cfgs["left"].serial_number = ROBOTIQ_SERIAL["left"] # type: ignore
hw_cfg.gripper_cfgs["right"].serial_number = ROBOTIQ_SERIAL["right"] # type: ignore
env_rel = env_creator.create_env(hw_cfg)
operator = GelloOperator(config) if isinstance(config, GelloConfig) else QuestOperator(config)
else:
# FR3
scene = EmptyWorldFR3Duo()
sim_cfg_data = scene.config()
sim_cfg_data.sim_cfg = SimConfig(
async_control=True, realtime=True, frequency=RECORD_FPS, max_convergence_steps=500
)
sim_cfg_data.relative_to = RelativeTo.CONFIGURED_ORIGIN
sim_cfg_data.wrapper_cfg.include_depth = INCLUDE_DEPTH
if sim_cfg_data.root_frame_objects is None:
sim_cfg_data.root_frame_objects = {}
# cfg.root_frame_objects["green_cube"] = (rcs.OBJECT_PATHS["green_cube"], Pose(translation=[0.5, 0, 0.5], quaternion=[0, 0, 0, 1]))
sim_cfg_data.task_cfg = PickTaskConfig(robot_name="right")
env_rel = scene.create_env(sim_cfg_data)
sim = env_rel.get_wrapper_attr("sim")
MujocoPublisher(sim.model, sim.data, MQ3_ADDR, visible_geoms_groups=list(range(1, 3)))
operator = GelloOperator(config, sim) if isinstance(config, GelloConfig) else QuestOperator(config, sim)
env_rel = StorageWrapper(
env_rel, DATASET_PATH, INSTRUCTION, batch_size=32, max_rows_per_group=100, max_rows_per_file=1000
)
return env_rel, operator
def main():
env_rel, operator = get_env()
env_rel.reset()
tele = TeleopLoop(env_rel, operator, env_frequency=RECORD_FPS, robot_platform=ROBOT_INSTANCE)
with env_rel, tele: # type: ignore
tele.environment_step_loop()
if __name__ == "__main__":
main()