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

Class Bring

dm_control/suite/manipulator.py:161–288  ·  view source on GitHub ↗

A Bring `Task`: bring the prop to the target.

Source from the content-addressed store, hash-verified

159
160
161class Bring(base.Task):
162 """A Bring `Task`: bring the prop to the target."""
163
164 def __init__(self, use_peg, insert, fully_observable, random=None):
165 """Initialize an instance of the `Bring` task.
166
167 Args:
168 use_peg: A `bool`, whether to replace the ball prop with the peg prop.
169 insert: A `bool`, whether to insert the prop in a receptacle.
170 fully_observable: A `bool`, whether the observation should contain the
171 position and velocity of the object being manipulated and the target
172 location.
173 random: Optional, either a `numpy.random.RandomState` instance, an
174 integer seed for creating a new `RandomState`, or None to select a seed
175 automatically (default).
176 """
177 self._use_peg = use_peg
178 self._target = 'target_peg' if use_peg else 'target_ball'
179 self._object = 'peg' if self._use_peg else 'ball'
180 self._object_joints = ['_'.join([self._object, dim]) for dim in 'xzy']
181 self._receptacle = 'slot' if self._use_peg else 'cup'
182 self._insert = insert
183 self._fully_observable = fully_observable
184 super().__init__(random=random)
185
186 def initialize_episode(self, physics):
187 """Sets the state of the environment at the start of each episode."""
188 # Local aliases
189 choice = self.random.choice
190 uniform = self.random.uniform
191 model = physics.named.model
192 data = physics.named.data
193
194 # Find a collision-free random initial configuration.
195 penetrating = True
196 while penetrating:
197
198 # Randomise angles of arm joints.
199 is_limited = model.jnt_limited[_ARM_JOINTS].astype(bool)
200 joint_range = model.jnt_range[_ARM_JOINTS]
201 lower_limits = np.where(is_limited, joint_range[:, 0], -np.pi)
202 upper_limits = np.where(is_limited, joint_range[:, 1], np.pi)
203 angles = uniform(lower_limits, upper_limits)
204 data.qpos[_ARM_JOINTS] = angles
205
206 # Symmetrize hand.
207 data.qpos['finger'] = data.qpos['thumb']
208
209 # Randomise target location.
210 target_x = uniform(-.4, .4)
211 target_z = uniform(.1, .4)
212 if self._insert:
213 target_angle = uniform(-np.pi/3, np.pi/3)
214 model.body_pos[self._receptacle, ['x', 'z']] = target_x, target_z
215 model.body_quat[self._receptacle, ['qw', 'qy']] = [
216 np.cos(target_angle/2), np.sin(target_angle/2)]
217 else:
218 target_angle = uniform(-np.pi, np.pi)

Callers 4

bring_ballFunction · 0.85
bring_pegFunction · 0.85
insert_ballFunction · 0.85
insert_pegFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…