def _reach(obs_settings, use_site): """Configure and instantiate a `Reach` task. Args: obs_settings: An `observations.ObservationSettings` instance. use_site: Boolean, if True then the target will be a fixed site, otherwise it will be a moveable Duplo brick. Returns: An instance of `reach.Reach`. """ arena = arenas.Standard() arm = robots.make_arm(obs_settings=obs_settings) hand = robots.make_hand(obs_settings=obs_settings) if use_site: workspace = _SITE_WORKSPACE prop = None else: workspace = _DUPLO_WORKSPACE prop = props.Duplo(observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) task = Reach(arena=arena, arm=arm, hand=hand, prop=prop, obs_settings=obs_settings, workspace=workspace, control_timestep=constants.CONTROL_TIMESTEP) return task
def make_arm(obs_settings): """Constructs a robot arm with manipulation-specific defaults. Args: obs_settings: `observations.ObservationSettings` instance. Returns: An instance of `manipulators.base.RobotArm`. """ return kinova.JacoArm(observable_options=observations.make_options( obs_settings, observations.JACO_ARM_OBSERVABLES))
def _lift(obs_settings, prop_name): """Configure and instantiate a Lift task. Args: obs_settings: `observations.ObservationSettings` instance. prop_name: The name of the prop to be lifted. Must be either 'duplo' or 'box'. Returns: An instance of `lift.Lift`. Raises: ValueError: If `prop_name` is neither 'duplo' nor 'box'. """ arena = arenas.Standard() arm = robots.make_arm(obs_settings=obs_settings) hand = robots.make_hand(obs_settings=obs_settings) if prop_name == 'duplo': workspace = _DUPLO_WORKSPACE prop = _DuploWithVertexSites( observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) elif prop_name == 'box': workspace = _BOX_WORKSPACE # NB: The box is intentionally too large to pick up with a pinch grip. prop = _BoxWithVertexSites( size=[_BOX_SIZE] * 3, observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) prop.geom.mass = _BOX_MASS else: raise ValueError('`prop_name` must be either \'duplo\' or \'box\'.') task = Lift(arena=arena, arm=arm, hand=hand, prop=prop, workspace=workspace, obs_settings=obs_settings, control_timestep=constants.CONTROL_TIMESTEP) return task
def make_hand(obs_settings): """Constructs a robot hand with manipulation-specific defaults. Args: obs_settings: `observations.ObservationSettings` instance. Returns: An instance of `manipulators.base.RobotHand`. """ return kinova.JacoHand(use_pinch_site_as_tcp=True, observable_options=observations.make_options( obs_settings, observations.JACO_HAND_OBSERVABLES))
def _reach(obs_settings, use_site, evalenv=False): """Configure and instantiate a `Reach` task. Args: obs_settings: An `observations.ObservationSettings` instance. use_site: Boolean, if True then the target will be a fixed site, otherwise it will be a moveable Duplo brick. Returns: An instance of `reach.Reach`. """ arena = arenas.Standard() arm = robots.make_arm(obs_settings=obs_settings) hand = robots.make_hand(obs_settings=obs_settings) if use_site: workspace = _SITE_WORKSPACE prop = None else: workspace = _DUPLO_WORKSPACE prop = props.Duplo(observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) env_randomizer = EnvRandomizer() table_col_tag = random.choice(list(env_randomizer.table_tags.values())) table_env_col_tag = random.choice( list(env_randomizer.table_eval_tags.values())) sky_col_tag = random.choice(list(env_randomizer.sky_tags.values())) if evalenv: task = ReachEval(arena=arena, arm=arm, hand=hand, prop=prop, obs_settings=obs_settings, workspace=workspace, control_timestep=constants.CONTROL_TIMESTEP, table_col_tag=table_env_col_tag) else: task = Reach(arena=arena, arm=arm, hand=hand, prop=prop, obs_settings=obs_settings, workspace=workspace, control_timestep=constants.CONTROL_TIMESTEP, table_col_tag=table_col_tag, sky_col_tag=sky_col_tag) mod_id = str(table_col_tag) + str(sky_col_tag) + str( random.randint(10, 1000)) return task, mod_id
def _push(obs_settings): """Configure and instantiate a `Push` task. Args: obs_settings: An `observations.ObservationSettings` instance. Returns: An instance of `push.Push`. """ arena = arenas.Standard() arm = robots.make_arm(obs_settings=obs_settings) hand = robots.make_hand(obs_settings=obs_settings) workspace = _DUPLO_WORKSPACE prop = props.Duplo(observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) task = Push(arena=arena, arm=arm, hand=hand, prop=prop, obs_settings=obs_settings, workspace=workspace, control_timestep=constants.CONTROL_TIMESTEP) return task
def _place(obs_settings, cradle_prop_name): """Configure and instantiate a Place task. Args: obs_settings: `observations.ObservationSettings` instance. cradle_prop_name: The name of the prop onto which the Duplo brick must be placed. Must be either 'duplo' or 'cradle'. Returns: An instance of `Place`. Raises: ValueError: If `prop_name` is neither 'duplo' nor 'cradle'. """ arena = arenas.Standard() arm = robots.make_arm(obs_settings=obs_settings) hand = robots.make_hand(obs_settings=obs_settings) prop = props.Duplo(observable_options=observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES)) if cradle_prop_name == 'duplo': cradle = props.Duplo() elif cradle_prop_name == 'cradle': cradle = SphereCradle() else: raise ValueError( '`cradle_prop_name` must be either \'duplo\' or \'cradle\'.') task = Place(arena=arena, arm=arm, hand=hand, prop=prop, obs_settings=obs_settings, workspace=_WORKSPACE, control_timestep=constants.CONTROL_TIMESTEP, cradle=cradle) return task
def __init__(self, arena, arm, hand, num_bricks, obs_settings, workspace, control_timestep): if not 2 <= num_bricks <= 6: raise ValueError( '`num_bricks` must be between 2 and 6, got {}.'.format( num_bricks)) if num_bricks > 3: # The default values computed by MuJoCo's compiler are too small if there # are more than three stacked bricks, since each stacked pair generates # a large number of contacts. The values below are sufficient for up to # 6 stacked bricks. # TODO(b/78331644): It may be useful to log the size of `physics.model` # and `physics.data` after compilation to gauge the # impact of these changes on MuJoCo's memory footprint. arena.mjcf_model.size.nconmax = 400 arena.mjcf_model.size.njmax = 1200 self._arena = arena self._arm = arm self._hand = hand self._arm.attach(self._hand) self._arena.attach_offset(self._arm, offset=workspace.arm_offset) self.control_timestep = control_timestep # Add custom camera observable. self._task_observables = cameras.add_camera_observables( arena, obs_settings, cameras.FRONT_CLOSE) color_sequence = iter(_COLOR_VALUES) brick_obs_options = observations.make_options( obs_settings, observations.FREEPROP_OBSERVABLES) bricks = [] brick_frames = [] goal_hint_bricks = [] for _ in range(num_bricks): color = next(color_sequence) brick = props.Duplo(color=color, observable_options=brick_obs_options) brick_frames.append(arena.add_free_entity(brick)) bricks.append(brick) # Translucent, contactless brick with no observables. These are used to # provide a visual hint representing the goal state for each task. hint_brick = props.Duplo(color=color) _hintify(hint_brick, alpha=_HINT_ALPHA) arena.attach(hint_brick) goal_hint_bricks.append(hint_brick) self._bricks = bricks self._brick_frames = brick_frames self._goal_hint_bricks = goal_hint_bricks # Position and quaternion for the goal hint. self._goal_hint_pos = workspace.goal_hint_pos self._goal_hint_quat = workspace.goal_hint_quat self._tcp_initializer = initializers.ToolCenterPointInitializer( self._hand, self._arm, position=distributions.Uniform(*workspace.tcp_bbox), quaternion=workspaces.DOWN_QUATERNION) # Add sites for visual debugging. workspaces.add_bbox_site(body=self.root_entity.mjcf_model.worldbody, lower=workspace.tcp_bbox.lower, upper=workspace.tcp_bbox.upper, rgba=constants.GREEN, name='tcp_spawn_area') workspaces.add_bbox_site(body=self.root_entity.mjcf_model.worldbody, lower=workspace.prop_bbox.lower, upper=workspace.prop_bbox.upper, rgba=constants.BLUE, name='prop_spawn_area')