Skip to content

Commit 3ad2aef

Browse files
authored
Add legacy mode for BehaviorRobot proprioception that matches proprioception format in baselines. (#799)
1 parent 32242dd commit 3ad2aef

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

igibson/configs/behavior_robot_vr_behavior_task.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ robot:
1818
# For the VR use case, we use the higher set of joint speed/position limits, and a different gripper action space.
1919
show_visual_head: False
2020
higher_limits: True
21+
legacy_proprioception: True
2122
controller_config:
2223
gripper_right_hand:
2324
name: JointController

igibson/robots/behavior_robot.py

+49
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
base_name="body",
109109
grasping_mode="assisted",
110110
higher_limits=False,
111+
legacy_proprioception=False,
111112
**kwargs,
112113
):
113114
"""
@@ -133,6 +134,8 @@ def __init__(
133134
:param higher_limits: bool, indicating whether the limbs' velocity and position limits should be set
134135
in the extended mode which allows for the instant responsiveness required for VR. Defaults to True.
135136
learning-based agents should set this parameter to False for a more realistic capability set.
137+
:param legacy_proprioception: Use the proprioception dimensions and dict keys that the BehaviorRobot had at
138+
the BEHAVIOR challenge, rather than the ones automatically generated by underlying robot classes.
136139
:param **kwargs: see ManipulationRobot, LocomotionRobot, ActiveCameraRobot
137140
"""
138141
assert reset_joint_pos is None, "BehaviorRobot doesn't support hand-specified reset_joint_pos"
@@ -144,6 +147,7 @@ def __init__(
144147
self.use_ghost_hands = use_ghost_hands
145148
self.normal_color = normal_color
146149
self.show_visual_head = show_visual_head
150+
self._legacy_proprioception = legacy_proprioception
147151

148152
self._position_limit_coefficient = 1 if higher_limits else LOWER_LIMITS_POSITION_COEFFICIENT
149153
self._velocity_limit_coefficient = 1 if higher_limits else LOWER_LIMITS_VELOCITY_COEFFICIENT
@@ -290,6 +294,51 @@ def set_position_orientation(self, pos, orn):
290294

291295
clear_cached_states(self)
292296

297+
@property
298+
def default_proprio_obs(self):
299+
if self._legacy_proprioception:
300+
return [
301+
"left_hand_position_local",
302+
"left_hand_orientation_local",
303+
"right_hand_position_local",
304+
"right_hand_orientation_local",
305+
"eye_position_local",
306+
"eye_orientation_local",
307+
"left_hand_trigger_fraction",
308+
"left_hand_is_grasping",
309+
"right_hand_trigger_fraction",
310+
"right_hand_is_grasping",
311+
]
312+
313+
# Otherwise just return the default observations
314+
return super().default_proprio_obs
315+
316+
def _get_proprioception_dict(self):
317+
if self._legacy_proprioception:
318+
# In the legacy proprioception mode, we use some custom labels and fields.
319+
state = {}
320+
321+
# Get all the part poses first.
322+
for part_name, part in self._parts.items():
323+
if part_name == "body":
324+
continue
325+
part_pos, part_orn = part.get_local_position_orientation()
326+
state[f"{part_name}_position_local"] = part_pos
327+
state[f"{part_name}_orientation_local"] = p.getEulerFromQuaternion(part_orn)
328+
329+
# Get grasping information.
330+
for arm in self.arm_names:
331+
finger_pos = self.joint_positions[self.gripper_control_idx[arm]]
332+
min_pos = self.joint_lower_limits[self.gripper_control_idx[arm]]
333+
max_pos = self.joint_upper_limits[self.gripper_control_idx[arm]]
334+
trigger_fraction = np.max((finger_pos - min_pos) / (max_pos - min_pos))
335+
state[f"{arm}_trigger_fraction"] = [np.clip(trigger_fraction, 0, 1)]
336+
state[f"{arm}_is_grasping"] = [self.is_grasping(arm=arm)]
337+
338+
return state
339+
340+
return super()._get_proprioception_dict()
341+
293342
def set_poses(self, poses):
294343
assert len(poses) == len(self._parts), "Number of poses (%d) does not match number of parts (%d)" % (
295344
len(poses),

tests/test_robot.py

+12
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,15 @@ def test_behavior_robot_stability():
313313
)
314314
_, angle = p.getAxisAngleFromQuaternion(rel_orn)
315315
assert angle < np.deg2rad(5), "Part orientation moved relative to robot."
316+
317+
318+
def test_behavior_robot_legacy_proprioception():
319+
s = Simulator(physics_timestep=1 / 30, render_timestep=1 / 30, mode="headless")
320+
scene = EmptyScene()
321+
s.import_scene(scene)
322+
323+
robot = REGISTERED_ROBOTS["BehaviorRobot"](legacy_proprioception=True)
324+
s.import_object(robot)
325+
326+
proprio_length = robot.get_proprioception().shape
327+
assert proprio_length == (22,), f"Proprioception shape should be 22. Instead, it is {proprio_length}"

0 commit comments

Comments
 (0)