MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / initialize_episode

Method initialize_episode

dm_control/suite/stacker.py:139–178  ·  view source on GitHub ↗

Sets the state of the environment at the start of each episode.

(self, physics)

Source from the content-addressed store, hash-verified

137 super().__init__(random=random)
138
139 def initialize_episode(self, physics):
140 """Sets the state of the environment at the start of each episode."""
141 # Local aliases
142 randint = self.random.randint
143 uniform = self.random.uniform
144 model = physics.named.model
145 data = physics.named.data
146
147 # Find a collision-free random initial configuration.
148 penetrating = True
149 while penetrating:
150
151 # Randomise angles of arm joints.
152 is_limited = model.jnt_limited[_ARM_JOINTS].astype(bool)
153 joint_range = model.jnt_range[_ARM_JOINTS]
154 lower_limits = np.where(is_limited, joint_range[:, 0], -np.pi)
155 upper_limits = np.where(is_limited, joint_range[:, 1], np.pi)
156 angles = uniform(lower_limits, upper_limits)
157 data.qpos[_ARM_JOINTS] = angles
158
159 # Symmetrize hand.
160 data.qpos['finger'] = data.qpos['thumb']
161
162 # Randomise target location.
163 target_height = 2*randint(self._n_boxes) + 1
164 box_size = model.geom_size['target', 0]
165 model.body_pos['target', 'z'] = box_size * target_height
166 model.body_pos['target', 'x'] = uniform(-.37, .37)
167
168 # Randomise box locations.
169 for name in self._box_names:
170 data.qpos[name + '_x'] = uniform(.1, .3)
171 data.qpos[name + '_z'] = uniform(0, .7)
172 data.qpos[name + '_y'] = uniform(0, 2*np.pi)
173
174 # Check for collisions.
175 physics.after_reset()
176 penetrating = physics.data.ncon > 0
177
178 super().initialize_episode(physics)
179
180 def get_observation(self, physics):
181 """Returns either features or only sensors (to be used with pixels)."""

Callers

nothing calls this directly

Calls 1

after_resetMethod · 0.45

Tested by

no test coverage detected