Skip to content

Commit c1aa70d

Browse files
committed
fix(env): type assertion and improved tests
- fixed type assertion location (noticed by tests) - optimized tests by removing camera in most cases
1 parent 5fc6195 commit c1aa70d

2 files changed

Lines changed: 22 additions & 22 deletions

File tree

python/rcsss/envs/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ def action(self, action: dict[str, Any]) -> dict[str, Any]:
386386
elif self.unwrapped.get_control_mode() == ControlMode.CARTESIAN_TRPY and self.trpy_key in action:
387387
assert isinstance(self._origin, common.Pose), "Invalid origin type given the control mode."
388388
assert isinstance(self.max_mov, tuple)
389-
assert isinstance(self._last_action, common.Pose)
390389
pose_space = cast(gym.spaces.Box, get_space(TRPYDictType).spaces[self.trpy_key])
391390

392391
if self.relative_to == RelativeTo.LAST_STEP or self._last_action is None:
@@ -400,6 +399,7 @@ def action(self, action: dict[str, Any]) -> dict[str, Any]:
400399
)
401400
self._last_action = clipped_pose_offset
402401
else:
402+
assert isinstance(self._last_action, common.Pose)
403403
pose_diff = (
404404
common.Pose(
405405
translation=action[self.trpy_key][:3],
@@ -430,7 +430,6 @@ def action(self, action: dict[str, Any]) -> dict[str, Any]:
430430
elif self.unwrapped.get_control_mode() == ControlMode.CARTESIAN_TQuart and self.tquart_key in action:
431431
assert isinstance(self._origin, common.Pose), "Invalid origin type given the control mode."
432432
assert isinstance(self.max_mov, tuple)
433-
assert isinstance(self._last_action, common.Pose)
434433
pose_space = cast(gym.spaces.Box, get_space(TQuartDictType).spaces[self.tquart_key])
435434

436435
if self.relative_to == RelativeTo.LAST_STEP or self._last_action is None:
@@ -444,6 +443,7 @@ def action(self, action: dict[str, Any]) -> dict[str, Any]:
444443
)
445444
self._last_action = clipped_pose_offset
446445
else:
446+
assert isinstance(self._last_action, common.Pose)
447447
pose_diff = (
448448
common.Pose(
449449
translation=action[self.tquart_key][:3],

python/tests/test_sim_envs.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ def test_non_zero_action_trpy(self, cfg):
108108
obs, _, _, _, info = env.step(non_zero_action)
109109
self.assert_no_pose_change(info, expected_obs, obs)
110110

111-
def test_relative_zero_action_trpy(self, cfg, gripper_cfg, cam_cfg):
111+
def test_relative_zero_action_trpy(self, cfg, gripper_cfg):
112112
# env creation
113113
env = fr3_sim_env(
114-
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=0.5
114+
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=None, max_relative_movement=0.5
115115
)
116116
obs_initial, _ = env.reset()
117117
# action to be performed
@@ -120,10 +120,10 @@ def test_relative_zero_action_trpy(self, cfg, gripper_cfg, cam_cfg):
120120
obs, _, _, _, info = env.step(zero_action)
121121
self.assert_no_pose_change(info, obs_initial, obs)
122122

123-
def test_relative_non_zero_action(self, cfg, gripper_cfg, cam_cfg):
123+
def test_relative_non_zero_action(self, cfg, gripper_cfg):
124124
# env creation
125125
env = fr3_sim_env(
126-
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=0.5
126+
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=None, max_relative_movement=0.5
127127
)
128128
obs_initial, _ = env.reset()
129129
# action to be performed
@@ -135,13 +135,13 @@ def test_relative_non_zero_action(self, cfg, gripper_cfg, cam_cfg):
135135
obs, _, _, _, info = env.step(non_zero_action)
136136
self.assert_no_pose_change(info, obs_initial, expected_obs)
137137

138-
def test_collision_trpy(self, cfg, gripper_cfg, cam_cfg):
138+
def test_collision_trpy(self, cfg, gripper_cfg):
139139
"""
140140
Check that an obvious collision is detected by sim
141141
"""
142142
# env creation
143143
env = fr3_sim_env(
144-
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=None
144+
ControlMode.CARTESIAN_TRPY, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=None, max_relative_movement=None
145145
)
146146
obs, _ = env.reset()
147147
# an obvious below ground collision action
@@ -152,7 +152,7 @@ def test_collision_trpy(self, cfg, gripper_cfg, cam_cfg):
152152
obs, _, _, _, info = env.step(collision_action)
153153
self.assert_collision(info)
154154

155-
def test_collision_guard_trpy(self, cfg, gripper_cfg, cam_cfg):
155+
def test_collision_guard_trpy(self, cfg, gripper_cfg):
156156
"""
157157
Check that an obvious collision is detected by the CollisionGuard
158158
"""
@@ -162,7 +162,7 @@ def test_collision_guard_trpy(self, cfg, gripper_cfg, cam_cfg):
162162
cfg,
163163
gripper_cfg=gripper_cfg,
164164
collision_guard=True,
165-
camera_set_cfg=cam_cfg,
165+
camera_set_cfg=None,
166166
max_relative_movement=None,
167167
)
168168
obs, _ = env.reset()
@@ -236,13 +236,13 @@ def test_zero_action_tquart(self, cfg):
236236
obs, _, _, _, info = env.step(zero_action)
237237
self.assert_no_pose_change(info, obs_initial, obs)
238238

239-
def test_relative_zero_action_tquart(self, cfg, gripper_cfg, cam_cfg):
239+
def test_relative_zero_action_tquart(self, cfg, gripper_cfg):
240240
# env creation
241241
env_rel = fr3_sim_env(
242242
ControlMode.CARTESIAN_TQuart,
243243
cfg,
244244
gripper_cfg=gripper_cfg,
245-
camera_set_cfg=cam_cfg,
245+
camera_set_cfg=None,
246246
max_relative_movement=0.5,
247247
)
248248
obs_initial, _ = env_rel.reset()
@@ -251,7 +251,7 @@ def test_relative_zero_action_tquart(self, cfg, gripper_cfg, cam_cfg):
251251
obs, _, _, _, info = env_rel.step(zero_rel_action)
252252
self.assert_no_pose_change(info, obs_initial, obs)
253253

254-
def test_collision_tquart(self, cfg, gripper_cfg, cam_cfg):
254+
def test_collision_tquart(self, cfg, gripper_cfg):
255255
"""
256256
Check that an obvious collision is detected by sim
257257
"""
@@ -260,7 +260,7 @@ def test_collision_tquart(self, cfg, gripper_cfg, cam_cfg):
260260
ControlMode.CARTESIAN_TQuart,
261261
cfg,
262262
gripper_cfg=gripper_cfg,
263-
camera_set_cfg=cam_cfg,
263+
camera_set_cfg=None,
264264
max_relative_movement=None,
265265
)
266266
obs, _ = env.reset()
@@ -272,7 +272,7 @@ def test_collision_tquart(self, cfg, gripper_cfg, cam_cfg):
272272
_, _, _, _, info = env.step(collision_action)
273273
self.assert_collision(info)
274274

275-
def test_collision_guard_tquart(self, cfg, gripper_cfg, cam_cfg):
275+
def test_collision_guard_tquart(self, cfg, gripper_cfg):
276276
"""
277277
Check that an obvious collision is detected by the CollisionGuard
278278
"""
@@ -282,7 +282,7 @@ def test_collision_guard_tquart(self, cfg, gripper_cfg, cam_cfg):
282282
cfg,
283283
gripper_cfg=gripper_cfg,
284284
collision_guard=True,
285-
camera_set_cfg=cam_cfg,
285+
camera_set_cfg=None,
286286
max_relative_movement=None,
287287
)
288288
obs, _ = env.reset()
@@ -346,13 +346,13 @@ def test_non_zero_action_joints(self, cfg):
346346
assert info["is_sim_converged"]
347347
assert np.allclose(obs["joints"], non_zero_action["joints"], atol=0.01, rtol=0)
348348

349-
def test_collision_joints(self, cfg, gripper_cfg, cam_cfg):
349+
def test_collision_joints(self, cfg, gripper_cfg):
350350
"""
351351
Check that an obvious collision is detected by the CollisionGuard
352352
"""
353353
# env creation
354354
env = fr3_sim_env(
355-
ControlMode.JOINTS, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=None
355+
ControlMode.JOINTS, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=None, max_relative_movement=None
356356
)
357357
env.reset()
358358
# the below action is a test_case where there is an obvious collision regardless of the gripper action
@@ -361,7 +361,7 @@ def test_collision_joints(self, cfg, gripper_cfg, cam_cfg):
361361
_, _, _, _, info = env.step(collision_act)
362362
self.assert_collision(info)
363363

364-
def test_collision_guard_joints(self, cfg, gripper_cfg, cam_cfg):
364+
def test_collision_guard_joints(self, cfg, gripper_cfg):
365365
"""
366366
Check that an obvious collision is detected by sim
367367
"""
@@ -371,7 +371,7 @@ def test_collision_guard_joints(self, cfg, gripper_cfg, cam_cfg):
371371
cfg,
372372
gripper_cfg=gripper_cfg,
373373
collision_guard=True,
374-
camera_set_cfg=cam_cfg,
374+
camera_set_cfg=None,
375375
max_relative_movement=None,
376376
)
377377
env.reset()
@@ -387,13 +387,13 @@ def test_collision_guard_joints(self, cfg, gripper_cfg, cam_cfg):
387387
# assure that the robot did not move
388388
assert np.allclose(p1, p2)
389389

390-
def test_relative_zero_action_joints(self, cfg, gripper_cfg, cam_cfg):
390+
def test_relative_zero_action_joints(self, cfg, gripper_cfg):
391391
"""
392392
Check that an obvious collision is detected by the CollisionGuard
393393
"""
394394
# env creation
395395
env = fr3_sim_env(
396-
ControlMode.JOINTS, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=cam_cfg, max_relative_movement=0.5
396+
ControlMode.JOINTS, cfg, gripper_cfg=gripper_cfg, camera_set_cfg=None, max_relative_movement=0.5
397397
)
398398
obs_initial, _ = env.reset()
399399
act = JointsDictType(joints=np.array([0, 0, 0, 0, 0, 0, 0], dtype=np.float32))

0 commit comments

Comments
 (0)