Skip to content

Commit 8f63283

Browse files
erez-tomcopybara-github
authored andcommitted
Expose egocentric sensors on other players.
PiperOrigin-RevId: 451422537 Change-Id: I289ed9d81fe37e79d29923eef443412289209582
1 parent 931ad67 commit 8f63283

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

dm_control/locomotion/soccer/observables.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def _egocentric_end_effectors_xpos(physics):
116116
return np.reshape(physics.bind(sensors).sensordata, -1)
117117
# Adds end effectors of the other agents in the player's egocentric frame.
118118
name = '{}_ego_end_effectors_pos'.format(prefix)
119+
player.walker.obs_on_other[name] = sensors
119120
player.walker.observables.add_observable(
120121
name,
121122
base_observable.Generic(_egocentric_end_effectors_xpos))
@@ -125,6 +126,7 @@ def _egocentric_end_effectors_xpos(physics):
125126
'framelinvel', name=ego_linvel_name,
126127
objtype='body', objname=other.walker.root_body,
127128
reftype='body', refname=player.walker.root_body)
129+
player.walker.obs_on_other[ego_linvel_name] = [ego_linvel_sensor]
128130
player.walker.observables.add_observable(
129131
ego_linvel_name,
130132
base_observable.MJCFFeature('sensordata', ego_linvel_sensor))
@@ -134,6 +136,7 @@ def _egocentric_end_effectors_xpos(physics):
134136
'framepos', name=ego_pos_name,
135137
objtype='body', objname=other.walker.root_body,
136138
reftype='body', refname=player.walker.root_body)
139+
player.walker.obs_on_other[ego_pos_name] = [ego_pos_sensor]
137140
player.walker.observables.add_observable(
138141
ego_pos_name,
139142
base_observable.MJCFFeature('sensordata', ego_pos_sensor))
@@ -148,6 +151,7 @@ def _egocentric_end_effectors_xpos(physics):
148151
reftype='body', refname=player.walker.root_body))
149152
def _egocentric_orientation(physics):
150153
return np.reshape(physics.bind(sensors_rot).sensordata, -1)
154+
player.walker.obs_on_other[obsname] = sensors_rot
151155
player.walker.observables.add_observable(
152156
obsname,
153157
base_observable.Generic(_egocentric_orientation))

dm_control/locomotion/walkers/legacy_base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Walker(base.Walker):
3333

3434
def _build(self, initializer=None):
3535
self._end_effectors_pos_sensors = []
36+
self._obs_on_other = {}
3637
try:
3738
self._initializers = tuple(initializer)
3839
except TypeError:
@@ -66,7 +67,8 @@ def aliveness(self, physics):
6667
"""
6768
return 0.
6869

69-
@abc.abstractproperty
70+
@property
71+
@abc.abstractmethod
7072
def ground_contact_geoms(self):
7173
"""Geoms in this walker that are expected to be in contact with the ground.
7274
@@ -101,6 +103,10 @@ def end_effector_geom_ids(self):
101103
def body_geom_ids(self):
102104
return self._body_geom_ids
103105

106+
@property
107+
def obs_on_other(self):
108+
return self._obs_on_other
109+
104110
def end_effector_contacts(self, physics):
105111
"""Collect the contacts with the end effectors.
106112
@@ -147,11 +153,13 @@ def collect_contacts(self, physics, geom_ids):
147153
contact.geom2), 0.))
148154
return contacts
149155

150-
@abc.abstractproperty
156+
@property
157+
@abc.abstractmethod
151158
def end_effectors(self):
152159
raise NotImplementedError
153160

154-
@abc.abstractproperty
161+
@property
162+
@abc.abstractmethod
155163
def egocentric_camera(self):
156164
raise NotImplementedError
157165

0 commit comments

Comments
 (0)