hex-zmq-servers 0.3.2__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ {
2
+ "net": {
3
+ "ip": "127.0.0.1",
4
+ "port": 12345,
5
+ "client_timeout_ms": 200,
6
+ "server_timeout_ms": 1000,
7
+ "server_num_workers": 4
8
+ },
9
+ "params": {
10
+ "cam_path": "/dev/video0",
11
+ "resolution": [
12
+ 640,
13
+ 480
14
+ ],
15
+ "frame_rate": 30,
16
+ "sens_ts": true
17
+ }
18
+ }
@@ -28,6 +28,7 @@
28
28
  0.31,
29
29
  1.0
30
30
  ],
31
+ "cam_type": "empty",
31
32
  "headless": false,
32
33
  "sens_ts": true
33
34
  }
@@ -28,6 +28,11 @@
28
28
  0.31,
29
29
  1.0
30
30
  ],
31
+ "cam_type": [
32
+ "empty",
33
+ "empty",
34
+ "empty"
35
+ ],
31
36
  "headless": false,
32
37
  "sens_ts": true
33
38
  }
@@ -6,37 +6,37 @@
6
6
  # link 1
7
7
  <body name="link_1" pos="0 0 0.0665">
8
8
  <inertial pos="0.008 -0.0023 0.0213" quat="0.707107 0.707107 0 0" mass="0.2154" diaginertia="0.0003 0.0003 0.0002"/>
9
- <joint name="joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
9
+ <joint name="joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
10
10
  <geom type="mesh" rgba="0.92549 0.92549 0.92549 1" mesh="arm_link_1"/>
11
11
 
12
12
  # link 2
13
13
  <body name="link_2" pos="0.02 0 0.045">
14
14
  <inertial pos="0.0001 -0.0028 0.1317" quat="0.999789 0.0205404 0 0" mass="1.3123" diaginertia="0.018 0.0177288 0.000671225"/>
15
- <joint name="joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
15
+ <joint name="joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
16
16
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_2"/>
17
17
 
18
18
  # link 3
19
19
  <body name="link_3" pos="0 0 0.264">
20
20
  <inertial pos="-0.051 0.0008 0.1447" quat="0.996909 0.0323182 -0.0688403 -0.019747" mass="1.1083" diaginertia="0.0115968 0.0112369 0.00136632"/>
21
- <joint name="joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
21
+ <joint name="joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
22
22
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_3"/>
23
23
 
24
24
  # link 4
25
25
  <body name="link_4" pos="-0.06 0 0.245">
26
26
  <inertial pos="-0.0597 -0.001 0.0572" quat="0 0.92388 0 0.382683" mass="0.5398" diaginertia="0.0011 0.001 0.0005"/>
27
- <joint name="joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
27
+ <joint name="joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
28
28
  <geom type="mesh" rgba="0.792157 0.792157 0.792157 1" mesh="arm_link_4"/>
29
29
 
30
30
  # link 5
31
31
  <body name="link_5" pos="-0.0553 0 0.070">
32
32
  <inertial pos="0.0292 0.0001 -0.0107" quat="0.707107 0 0 0.707107" mass="0.3984" diaginertia="0.0003 0.0002 0.0002"/>
33
- <joint name="joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
33
+ <joint name="joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
34
34
  <geom type="mesh" rgba="0.898039 0.917647 0.929412 1" mesh="arm_link_5"/>
35
35
 
36
36
  # gripper base link
37
37
  <body name="gripper_base_link" pos="0.0553 0 0.029" quat="0.707107 0.0 -0.707107 0.0">
38
38
  <inertial pos="-0.0139 0.0001 0.0553" quat="0.567843 0.421372 0.421372 0.567843" mass="0.7651" diaginertia="0.0021 0.00143028 0.00106972"/>
39
- <joint name="joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
39
+ <joint name="joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
40
40
  <geom type="mesh" rgba="1 1 1 1" mesh="gripper_base_link"/>
41
41
  <geom pos="0.04 0 0.12" quat="0.6830127 0.6830127 0.1830127 -0.1830127" type="mesh" rgba="0.1 0.1 0.1 1" mesh="camera_link" />
42
42
  <camera name="end_camera" pos="0.066 0 0.105" quat="0.8660254 0.0 -0.5 0.0" fovy="50"/>
@@ -34,6 +34,12 @@ MUJOCO_CONFIG = {
34
34
  "headless": False,
35
35
  "sens_ts": True,
36
36
  }
37
+ CAMERA_CONFIG = {
38
+ "empty": (False, False),
39
+ "rgb": (True, False),
40
+ "berxel": (True, True),
41
+ "realsense": (True, True),
42
+ }
37
43
 
38
44
 
39
45
  class HexMujocoArcherY6(HexMujocoBase):
@@ -50,6 +56,7 @@ class HexMujocoArcherY6(HexMujocoBase):
50
56
  self.__tau_ctrl = mujoco_config["tau_ctrl"]
51
57
  self.__mit_kp = mujoco_config["mit_kp"]
52
58
  self.__mit_kd = mujoco_config["mit_kd"]
59
+ self.__cam_type = mujoco_config["cam_type"]
53
60
  self.__headless = mujoco_config["headless"]
54
61
  self.__sens_ts = mujoco_config["sens_ts"]
55
62
  except KeyError as ke:
@@ -95,14 +102,22 @@ class HexMujocoArcherY6(HexMujocoBase):
95
102
  self.__states_trig_thresh = int(self.__sim_rate / states_rate)
96
103
 
97
104
  # camera init
98
- width, height = 640, 400
99
- fovy_rad = self.__model.cam_fovy[0] * np.pi / 180.0
100
- focal = 0.5 * height / np.tan(fovy_rad / 2.0)
101
- self._intri = np.array([focal, focal, height / 2, height / 2])
102
- self.__rgb_cam = mujoco.Renderer(self.__model, height, width)
103
- self.__depth_cam = mujoco.Renderer(self.__model, height, width)
104
- self.__depth_cam.enable_depth_rendering()
105
105
  self.__img_trig_thresh = int(self.__sim_rate / img_rate)
106
+ self.__width, self.__height = 640, 400
107
+ fovy_rad = self.__model.cam_fovy[0] * np.pi / 180.0
108
+ focal = 0.5 * self.__height / np.tan(fovy_rad / 2.0)
109
+ self._intri = np.array(
110
+ [focal, focal, self.__height / 2, self.__height / 2])
111
+ self.__use_rgb, self.__use_depth = CAMERA_CONFIG.get(
112
+ self.__cam_type, (False, False))
113
+ self.__rgb_cam, self.__depth_cam = None, None
114
+ if self.__use_rgb:
115
+ self.__rgb_cam = mujoco.Renderer(self.__model, self.__height,
116
+ self.__width)
117
+ if self.__use_depth:
118
+ self.__depth_cam = mujoco.Renderer(self.__model, self.__height,
119
+ self.__width)
120
+ self.__depth_cam.enable_depth_rendering()
106
121
 
107
122
  # viewer init
108
123
  mujoco.mj_forward(self.__model, self.__data)
@@ -138,11 +153,18 @@ class HexMujocoArcherY6(HexMujocoBase):
138
153
  last_cmds_robot_seq = -1
139
154
  rgb_count = 0
140
155
  depth_count = 0
156
+ cmds_robot = None
141
157
 
142
158
  rate = HexRate(self.__sim_rate)
143
159
  states_trig_count = 0
144
160
  img_trig_count = 0
145
-
161
+ init_ts = self.__mujoco_ts() if self.__sens_ts else hex_zmq_ts_now()
162
+ rgb_value.set((init_ts, 0,
163
+ np.zeros((self.__height, self.__width, 3),
164
+ dtype=np.uint8)))
165
+ depth_value.set((init_ts, 0,
166
+ np.zeros((self.__height, self.__width),
167
+ dtype=np.uint16)))
146
168
  while self._working.is_set() and not stop_event.is_set():
147
169
  states_trig_count += 1
148
170
  if states_trig_count >= self.__states_trig_thresh:
@@ -169,27 +191,31 @@ class HexMujocoArcherY6(HexMujocoBase):
169
191
  # cmds
170
192
  cmds_robot_pack = cmds_robot_value.get(timeout_s=-1.0)
171
193
  if cmds_robot_pack is not None:
172
- ts, seq, cmds = cmds_robot_pack
194
+ ts, seq, cmds_robot_get = cmds_robot_pack
173
195
  if seq != last_cmds_robot_seq:
174
196
  last_cmds_robot_seq = seq
175
197
  if hex_zmq_ts_delta_ms(hex_zmq_ts_now(), ts) < 200.0:
176
- self.__set_cmds(cmds)
198
+ cmds_robot = cmds_robot_get.copy()
199
+ if cmds_robot is not None:
200
+ self.__set_cmds(cmds_robot)
177
201
 
178
202
  img_trig_count += 1
179
203
  if img_trig_count >= self.__img_trig_thresh:
180
204
  img_trig_count = 0
181
205
 
182
206
  # rgb
183
- ts, rgb_img = self.__get_rgb()
184
- if rgb_img is not None:
185
- rgb_value.set((ts, rgb_count, rgb_img))
186
- rgb_count = (rgb_count + 1) % self._max_seq_num
207
+ if self.__use_rgb:
208
+ ts, rgb_img = self.__get_rgb()
209
+ if rgb_img is not None:
210
+ rgb_value.set((ts, rgb_count, rgb_img))
211
+ rgb_count = (rgb_count + 1) % self._max_seq_num
187
212
 
188
213
  # depth
189
- ts, depth_img = self.__get_depth()
190
- if depth_img is not None:
191
- depth_value.set((ts, depth_count, depth_img))
192
- depth_count = (depth_count + 1) % self._max_seq_num
214
+ if self.__use_depth:
215
+ ts, depth_img = self.__get_depth()
216
+ if depth_img is not None:
217
+ depth_value.set((ts, depth_count, depth_img))
218
+ depth_count = (depth_count + 1) % self._max_seq_num
193
219
 
194
220
  # mujoco step
195
221
  mujoco.mj_step(self.__model, self.__data)
@@ -236,7 +262,8 @@ class HexMujocoArcherY6(HexMujocoBase):
236
262
  cmd_kp = cmds[:, 3].copy()
237
263
  cmd_kd = cmds[:, 4].copy()
238
264
  else:
239
- raise ValueError(f"The shape of cmds is invalid: {cmds.shape}")
265
+ raise ValueError(
266
+ f"The shape of cmds is invalid: {cmds.shape}")
240
267
  else:
241
268
  raise ValueError(f"The shape of cmds is invalid: {cmds.shape}")
242
269
  tar_pos = self._apply_pos_limits(
@@ -282,8 +309,10 @@ class HexMujocoArcherY6(HexMujocoBase):
282
309
  if not self._working.is_set():
283
310
  return
284
311
  self._working.clear()
285
- self.__rgb_cam.close()
286
- self.__depth_cam.close()
312
+ if self.__rgb_cam is not None:
313
+ self.__rgb_cam.close()
314
+ if self.__depth_cam is not None:
315
+ self.__depth_cam.close()
287
316
  if not self.__headless:
288
317
  self.__viewer.close()
289
318
  hex_log(HEX_LOG_LEVEL["info"], "HexMujocoArcherY6 closed")
@@ -10,37 +10,37 @@
10
10
  # left link 1
11
11
  <body name="left_link_1" pos="0.0185 0.3 0.21152">
12
12
  <inertial pos="0.008 -0.0023 0.0213" quat="0.707107 0.707107 0 0" mass="0.2154" diaginertia="0.0003 0.0003 0.0002"/>
13
- <joint name="left_joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
13
+ <joint name="left_joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
14
14
  <geom type="mesh" rgba="0.92549 0.92549 0.92549 1" mesh="arm_link_1"/>
15
15
 
16
16
  # left link 2
17
17
  <body name="left_link_2" pos="0.02 0 0.045">
18
18
  <inertial pos="0.0001 -0.0028 0.1317" quat="0.999789 0.0205404 0 0" mass="1.3123" diaginertia="0.018 0.0177288 0.000671225"/>
19
- <joint name="left_joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
19
+ <joint name="left_joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
20
20
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_2"/>
21
21
 
22
22
  # left link 3
23
23
  <body name="left_link_3" pos="0 0 0.264">
24
24
  <inertial pos="-0.051 0.0008 0.1447" quat="0.996909 0.0323182 -0.0688403 -0.019747" mass="1.1083" diaginertia="0.0115968 0.0112369 0.00136632"/>
25
- <joint name="left_joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
25
+ <joint name="left_joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
26
26
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_3"/>
27
27
 
28
28
  # left link 4
29
29
  <body name="left_link_4" pos="-0.06 0 0.245">
30
30
  <inertial pos="-0.0597 -0.001 0.0572" quat="0 0.92388 0 0.382683" mass="0.5398" diaginertia="0.0011 0.001 0.0005"/>
31
- <joint name="left_joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
31
+ <joint name="left_joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
32
32
  <geom type="mesh" rgba="0.792157 0.792157 0.792157 1" mesh="arm_link_4"/>
33
33
 
34
34
  # left link 5
35
35
  <body name="left_link_5" pos="-0.0553006 0 0.07025">
36
36
  <inertial pos="0.0292 0.0001 -0.0107" quat="0.707107 0 0 0.707107" mass="0.3984" diaginertia="0.0003 0.0002 0.0002"/>
37
- <joint name="left_joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
37
+ <joint name="left_joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
38
38
  <geom type="mesh" rgba="0.898039 0.917647 0.929412 1" mesh="arm_link_5"/>
39
39
 
40
40
  # left gripper base link
41
41
  <body name="left_gripper_base_link" pos="0.0578 0 0.02895" quat="0.707107 0.0 -0.707107 0.0">
42
42
  <inertial pos="-0.0139 0.0001 0.0578" quat="0.567843 0.421372 0.421372 0.567843" mass="0.7651" diaginertia="0.0021 0.00143028 0.00106972"/>
43
- <joint name="left_joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
43
+ <joint name="left_joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
44
44
  <geom type="mesh" rgba="1 1 1 1" mesh="gripper_base_link"/>
45
45
  <geom pos="0.04 0 0.12" quat="0.6830127 0.6830127 0.1830127 -0.1830127" type="mesh" rgba="0.1 0.1 0.1 1" mesh="camera_link" />
46
46
  <camera name="left_camera" pos="0.066 0 0.105" quat="0.8660254 0.0 -0.5 0.0" fovy="50"/>
@@ -99,37 +99,37 @@
99
99
  # right link 1
100
100
  <body name="right_link_1" pos="0.0185 -0.3 0.21152">
101
101
  <inertial pos="0.008 -0.0023 0.0213" quat="0.707107 0.707107 0 0" mass="0.2154" diaginertia="0.0003 0.0003 0.0002"/>
102
- <joint name="right_joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
102
+ <joint name="right_joint_1" pos="0 0 0" axis="0 0 1" range="-2.7 2.7" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
103
103
  <geom type="mesh" rgba="0.92549 0.92549 0.92549 1" mesh="arm_link_1"/>
104
104
 
105
105
  # right link 2
106
106
  <body name="right_link_2" pos="0.02 0 0.045">
107
107
  <inertial pos="0.0001 -0.0028 0.1317" quat="0.999789 0.0205404 0 0" mass="1.3123" diaginertia="0.018 0.0177288 0.000671225"/>
108
- <joint name="right_joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
108
+ <joint name="right_joint_2" pos="0 0 0" axis="0 1 0" range="-1.57 2.09" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
109
109
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_2"/>
110
110
 
111
111
  # right link 3
112
112
  <body name="right_link_3" pos="0 0 0.264">
113
113
  <inertial pos="-0.051 0.0008 0.1447" quat="0.996909 0.0323182 -0.0688403 -0.019747" mass="1.1083" diaginertia="0.0115968 0.0112369 0.00136632"/>
114
- <joint name="right_joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
114
+ <joint name="right_joint_3" pos="0 0 0" axis="0 1 0" range="0 3.14" limited="true" armature="0.01" damping="0.1" frictionloss="0.5"/>
115
115
  <geom type="mesh" rgba="1 1 1 1" mesh="arm_link_3"/>
116
116
 
117
117
  # right link 4
118
118
  <body name="right_link_4" pos="-0.06 0 0.245">
119
119
  <inertial pos="-0.0597 -0.001 0.0572" quat="0 0.92388 0 0.382683" mass="0.5398" diaginertia="0.0011 0.001 0.0005"/>
120
- <joint name="right_joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
120
+ <joint name="right_joint_4" pos="0 0 0" axis="0 1 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
121
121
  <geom type="mesh" rgba="0.792157 0.792157 0.792157 1" mesh="arm_link_4"/>
122
122
 
123
123
  # right link 5
124
124
  <body name="right_link_5" pos="-0.0553006 0 0.07025">
125
125
  <inertial pos="0.0292 0.0001 -0.0107" quat="0.707107 0 0 0.707107" mass="0.3984" diaginertia="0.0003 0.0002 0.0002"/>
126
- <joint name="right_joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
126
+ <joint name="right_joint_5" pos="0 0 0" axis="-1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
127
127
  <geom type="mesh" rgba="0.898039 0.917647 0.929412 1" mesh="arm_link_5"/>
128
128
 
129
129
  # right gripper base link
130
130
  <body name="right_gripper_base_link" pos="0.0578 0 0.02895" quat="0.707107 0.0 -0.707107 0.0">
131
131
  <inertial pos="-0.0139 0.0001 0.0578" quat="0.567843 0.421372 0.421372 0.567843" mass="0.7651" diaginertia="0.0021 0.00143028 0.00106972"/>
132
- <joint name="right_joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.1" damping="3.0" frictionloss="1.0"/>
132
+ <joint name="right_joint_6" pos="0 0 0" axis="1 0 0" range="-1.57 1.57" limited="true" armature="0.01" damping="0.02" frictionloss="0.1"/>
133
133
  <geom type="mesh" rgba="1 1 1 1" mesh="gripper_base_link"/>
134
134
  <geom pos="0.04 0 0.12" quat="0.6830127 0.6830127 0.1830127 -0.1830127" type="mesh" rgba="0.1 0.1 0.1 1" mesh="camera_link" />
135
135
  <camera name="right_camera" pos="0.066 0 0.105" quat="0.8660254 0.0 -0.5 0.0" fovy="50"/>
@@ -31,9 +31,16 @@ MUJOCO_CONFIG = {
31
31
  "tau_ctrl": False,
32
32
  "mit_kp": [200.0, 200.0, 200.0, 75.0, 15.0, 15.0, 20.0],
33
33
  "mit_kd": [12.5, 12.5, 12.5, 6.0, 0.31, 0.31, 1.0],
34
+ "cam_type": ["empty", "empty", "empty"],
34
35
  "headless": False,
35
36
  "sens_ts": True,
36
37
  }
38
+ CAMERA_CONFIG = {
39
+ "empty": (False, False),
40
+ "rgb": (True, False),
41
+ "berxel": (True, True),
42
+ "realsense": (True, True),
43
+ }
37
44
 
38
45
 
39
46
  class HexMujocoE3Desktop(HexMujocoBase):
@@ -50,6 +57,7 @@ class HexMujocoE3Desktop(HexMujocoBase):
50
57
  self.__tau_ctrl = mujoco_config["tau_ctrl"]
51
58
  self.__mit_kp = mujoco_config["mit_kp"]
52
59
  self.__mit_kd = mujoco_config["mit_kd"]
60
+ self.__cam_type = mujoco_config["cam_type"]
53
61
  self.__headless = mujoco_config["headless"]
54
62
  self.__sens_ts = mujoco_config["sens_ts"]
55
63
  except KeyError as ke:
@@ -103,22 +111,35 @@ class HexMujocoE3Desktop(HexMujocoBase):
103
111
  self.__states_trig_thresh = int(self.__sim_rate / states_rate)
104
112
 
105
113
  # camera init
106
- width, height = 640, 400
114
+ self.__img_trig_thresh = int(self.__sim_rate / img_rate)
115
+ self.__width, self.__height = (640, 480)
107
116
  head_fovy_rad = self.__model.cam_fovy[0] * np.pi / 180.0
108
117
  left_fovy_rad = self.__model.cam_fovy[1] * np.pi / 180.0
109
118
  right_fovy_rad = self.__model.cam_fovy[2] * np.pi / 180.0
110
- head_focal = 0.5 * height / np.tan(head_fovy_rad / 2.0)
111
- left_focal = 0.5 * height / np.tan(left_fovy_rad / 2.0)
112
- right_focal = 0.5 * height / np.tan(right_fovy_rad / 2.0)
119
+ head_focal = 0.5 * self.__height / np.tan(head_fovy_rad / 2.0)
120
+ left_focal = 0.5 * self.__height / np.tan(left_fovy_rad / 2.0)
121
+ right_focal = 0.5 * self.__height / np.tan(right_fovy_rad / 2.0)
113
122
  self._intri = np.array([
114
- [head_focal, head_focal, height / 2, height / 2],
115
- [left_focal, left_focal, height / 2, height / 2],
116
- [right_focal, right_focal, height / 2, height / 2],
123
+ [head_focal, head_focal, self.__height / 2, self.__height / 2],
124
+ [left_focal, left_focal, self.__height / 2, self.__height / 2],
125
+ [right_focal, right_focal, self.__height / 2, self.__height / 2],
117
126
  ])
118
- self.__rgb_cam = mujoco.Renderer(self.__model, height, width)
119
- self.__depth_cam = mujoco.Renderer(self.__model, height, width)
120
- self.__depth_cam.enable_depth_rendering()
121
- self.__img_trig_thresh = int(self.__sim_rate / img_rate)
127
+ self.__head_rgb, self.__head_depth = CAMERA_CONFIG.get(
128
+ self.__cam_type[0], (False, False))
129
+ self.__left_rgb, self.__left_depth = CAMERA_CONFIG.get(
130
+ self.__cam_type[1], (False, False))
131
+ self.__right_rgb, self.__right_depth = CAMERA_CONFIG.get(
132
+ self.__cam_type[2], (False, False))
133
+ self.__rgb_cam, self.__depth_cam = None, None
134
+ has_rgb = self.__left_rgb or self.__right_rgb or self.__head_rgb
135
+ has_depth = self.__left_depth or self.__right_depth or self.__head_depth
136
+ if has_rgb:
137
+ self.__rgb_cam = mujoco.Renderer(self.__model, self.__height,
138
+ self.__width)
139
+ if has_depth:
140
+ self.__depth_cam = mujoco.Renderer(self.__model, self.__height,
141
+ self.__width)
142
+ self.__depth_cam.enable_depth_rendering()
122
143
 
123
144
  # viewer init
124
145
  mujoco.mj_forward(self.__model, self.__data)
@@ -166,10 +187,31 @@ class HexMujocoE3Desktop(HexMujocoBase):
166
187
  left_depth_count = 0
167
188
  right_rgb_count = 0
168
189
  right_depth_count = 0
190
+ cmds_left = None
191
+ cmds_right = None
169
192
 
170
193
  rate = HexRate(self.__sim_rate)
171
194
  states_trig_count = 0
172
195
  img_trig_count = 0
196
+ init_ts = self.__mujoco_ts() if self.__sens_ts else hex_zmq_ts_now()
197
+ head_rgb_value.set((init_ts, 0,
198
+ np.zeros((self.__height, self.__width, 3),
199
+ dtype=np.uint8)))
200
+ head_depth_value.set((init_ts, 0,
201
+ np.zeros((self.__height, self.__width),
202
+ dtype=np.uint16)))
203
+ left_rgb_value.set((init_ts, 0,
204
+ np.zeros((self.__height, self.__width, 3),
205
+ dtype=np.uint8)))
206
+ left_depth_value.set((init_ts, 0,
207
+ np.zeros((self.__height, self.__width),
208
+ dtype=np.uint16)))
209
+ right_rgb_value.set((init_ts, 0,
210
+ np.zeros((self.__height, self.__width, 3),
211
+ dtype=np.uint8)))
212
+ right_depth_value.set((init_ts, 0,
213
+ np.zeros((self.__height, self.__width),
214
+ dtype=np.uint16)))
173
215
  while self._working.is_set() and not stop_event.is_set():
174
216
  states_trig_count += 1
175
217
  if states_trig_count >= self.__states_trig_thresh:
@@ -199,62 +241,76 @@ class HexMujocoE3Desktop(HexMujocoBase):
199
241
  # cmds
200
242
  cmds_left_pack = cmds_left_value.get(timeout_s=-1.0)
201
243
  if cmds_left_pack is not None:
202
- ts, seq, cmds_left = cmds_left_pack
244
+ ts, seq, cmds_left_get = cmds_left_pack
203
245
  if seq != last_cmds_left_seq:
204
246
  last_cmds_left_seq = seq
205
247
  if hex_zmq_ts_delta_ms(hex_zmq_ts_now(), ts) < 200.0:
206
- self.__set_cmds(cmds_left, "left")
248
+ cmds_left = cmds_left_get.copy()
249
+ if cmds_left is not None:
250
+ self.__set_cmds(cmds_left, "left")
207
251
 
208
252
  cmds_right_pack = cmds_right_value.get(timeout_s=-1.0)
209
253
  if cmds_right_pack is not None:
210
- ts, seq, cmds_right = cmds_right_pack
254
+ ts, seq, cmds_right_get = cmds_right_pack
211
255
  if seq != last_cmds_right_seq:
212
256
  last_cmds_right_seq = seq
213
257
  if hex_zmq_ts_delta_ms(hex_zmq_ts_now(), ts) < 200.0:
214
- self.__set_cmds(cmds_right, "right")
258
+ cmds_right = cmds_right_get.copy()
259
+ if cmds_right is not None:
260
+ self.__set_cmds(cmds_right, "right")
215
261
 
216
262
  img_trig_count += 1
217
263
  if img_trig_count >= self.__img_trig_thresh:
218
264
  img_trig_count = 0
219
265
 
220
266
  # head rgb
221
- ts, rgb_img = self.__get_rgb("head_camera")
222
- if rgb_img is not None:
223
- head_rgb_value.set((ts, head_rgb_count, rgb_img))
224
- head_rgb_count = (head_rgb_count + 1) % self._max_seq_num
267
+ if self.__head_rgb:
268
+ ts, rgb_img = self.__get_rgb("head_camera")
269
+ if rgb_img is not None:
270
+ head_rgb_value.set((ts, head_rgb_count, rgb_img))
271
+ head_rgb_count = (head_rgb_count +
272
+ 1) % self._max_seq_num
225
273
 
226
274
  # head depth
227
- ts, depth_img = self.__get_depth("head_camera")
228
- if depth_img is not None:
229
- head_depth_value.set((ts, head_depth_count, depth_img))
230
- head_depth_count = (head_depth_count +
231
- 1) % self._max_seq_num
275
+ if self.__head_depth:
276
+ ts, depth_img = self.__get_depth("head_camera")
277
+ if depth_img is not None:
278
+ head_depth_value.set((ts, head_depth_count, depth_img))
279
+ head_depth_count = (head_depth_count +
280
+ 1) % self._max_seq_num
232
281
 
233
282
  # left rgb
234
- ts, rgb_img = self.__get_rgb("left_camera")
235
- if rgb_img is not None:
236
- left_rgb_value.set((ts, left_rgb_count, rgb_img))
237
- left_rgb_count = (left_rgb_count + 1) % self._max_seq_num
283
+ if self.__left_rgb:
284
+ ts, rgb_img = self.__get_rgb("left_camera")
285
+ if rgb_img is not None:
286
+ left_rgb_value.set((ts, left_rgb_count, rgb_img))
287
+ left_rgb_count = (left_rgb_count +
288
+ 1) % self._max_seq_num
238
289
 
239
290
  # left depth
240
- ts, depth_img = self.__get_depth("left_camera")
241
- if depth_img is not None:
242
- left_depth_value.set((ts, left_depth_count, depth_img))
243
- left_depth_count = (left_depth_count +
244
- 1) % self._max_seq_num
291
+ if self.__left_depth:
292
+ ts, depth_img = self.__get_depth("left_camera")
293
+ if depth_img is not None:
294
+ left_depth_value.set((ts, left_depth_count, depth_img))
295
+ left_depth_count = (left_depth_count +
296
+ 1) % self._max_seq_num
245
297
 
246
298
  # right rgb
247
- ts, rgb_img = self.__get_rgb("right_camera")
248
- if rgb_img is not None:
249
- right_rgb_value.set((ts, right_rgb_count, rgb_img))
250
- right_rgb_count = (right_rgb_count + 1) % self._max_seq_num
299
+ if self.__right_rgb:
300
+ ts, rgb_img = self.__get_rgb("right_camera")
301
+ if rgb_img is not None:
302
+ right_rgb_value.set((ts, right_rgb_count, rgb_img))
303
+ right_rgb_count = (right_rgb_count +
304
+ 1) % self._max_seq_num
251
305
 
252
306
  # right depth
253
- ts, depth_img = self.__get_depth("right_camera")
254
- if depth_img is not None:
255
- right_depth_value.set((ts, right_depth_count, depth_img))
256
- right_depth_count = (right_depth_count +
257
- 1) % self._max_seq_num
307
+ if self.__right_depth:
308
+ ts, depth_img = self.__get_depth("right_camera")
309
+ if depth_img is not None:
310
+ right_depth_value.set(
311
+ (ts, right_depth_count, depth_img))
312
+ right_depth_count = (right_depth_count +
313
+ 1) % self._max_seq_num
258
314
 
259
315
  # mujoco step
260
316
  mujoco.mj_step(self.__model, self.__data)
@@ -369,8 +425,10 @@ class HexMujocoE3Desktop(HexMujocoBase):
369
425
  if not self._working.is_set():
370
426
  return
371
427
  self._working.clear()
372
- self.__rgb_cam.close()
373
- self.__depth_cam.close()
428
+ if self.__rgb_cam is not None:
429
+ self.__rgb_cam.close()
430
+ if self.__depth_cam is not None:
431
+ self.__depth_cam.close()
374
432
  if not self.__headless:
375
433
  self.__viewer.close()
376
434
  hex_log(HEX_LOG_LEVEL["info"], "HexMujocoE3Desktop closed")
@@ -171,9 +171,12 @@ class HexZMQClientBase(ABC):
171
171
  self.__make_socket()
172
172
  return resp_hdr, resp_buf
173
173
 
174
- def is_working(self):
174
+ def is_working(self) -> bool:
175
175
  working_hdr, _ = self.request({"cmd": "is_working"})
176
- return working_hdr
176
+ if working_hdr is None:
177
+ return False
178
+ else:
179
+ return working_hdr["cmd"] == "is_working_ok"
177
180
 
178
181
  def __send_req(self, req_dict: dict, req_buf: np.ndarray | None = None):
179
182
  # construct send header
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hex_zmq_servers
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: HEXFELLOW ZMQ Servers
5
5
  Author-email: Dong Zhaorui <joray.dong@hexfellow.com>
6
6
  Maintainer-email: jecjune <zejun.chen@hexfellow.com>, Dong Zhaorui <joray.dong@hexfellow.com>
@@ -26,16 +26,17 @@ Requires-Dist: pyzmq>=27.0.1
26
26
  Requires-Dist: hex_device<1.4.0,>=1.3.1
27
27
  Requires-Dist: hex_robo_utils<0.3.0,>=0.2.0
28
28
  Requires-Dist: dynamixel-sdk==3.8.4
29
- Provides-Extra: camera
30
- Requires-Dist: berxel_py_wrapper>=2.0.182; extra == "camera"
31
- Requires-Dist: opencv-python>=4.2; extra == "camera"
29
+ Requires-Dist: opencv-python>=4.2
30
+ Provides-Extra: berxel
31
+ Requires-Dist: berxel_py_wrapper>=2.0.182; extra == "berxel"
32
+ Provides-Extra: realsense
33
+ Requires-Dist: pyrealsense2>=2.56.5.9235; extra == "realsense"
32
34
  Provides-Extra: mujoco
33
35
  Requires-Dist: mujoco>=3.3.3; extra == "mujoco"
34
- Requires-Dist: opencv-python>=4.2; extra == "mujoco"
35
36
  Provides-Extra: all
36
37
  Requires-Dist: berxel_py_wrapper>=2.0.182; extra == "all"
37
38
  Requires-Dist: mujoco>=3.3.3; extra == "all"
38
- Requires-Dist: opencv-python>=4.2; extra == "all"
39
+ Requires-Dist: pyrealsense2>=2.56.5.9235; extra == "all"
39
40
  Dynamic: license-file
40
41
 
41
42
  # hex_zmq_servers