def __init__(self, anchor, **kwargs): """ Refer to Sensor Class. Args: invisible_elements: elements that the sensor does not perceive. List of Parts of SceneElements. normalize: if true, Sensor values are normalized between 0 and 1. Default: True only_front: Only return the half part of the Playground that the Sensor faces. Remove what is behind the sensor. Default: False. """ default_config = parse_configuration('agent_sensors', SensorTypes.TOPDOWN_GLOBAL) kwargs = {**default_config, **kwargs} super().__init__(anchor=anchor, **kwargs) # Assert that size is set or coming from playground. self._size = None self._center = None self._sensor_max_value = 255.
def __init__(self, config_key: Optional[Union[ElementTypes, str]] = None, **kwargs): default_config = parse_configuration('element_activable', config_key) kwargs = {**default_config, **kwargs} super().__init__(visible_shape=True, invisible_shape=True, **kwargs)
def __init__(self, anchor, **kwargs): default_config = parse_configuration('agent_sensors', self.sensor_type) kwargs = {**default_config, **kwargs} super().__init__(anchor, remove_duplicates=False, **kwargs) self._sensor_max_value = 255
def __init__(self, anchor, **kwargs): default_config = parse_configuration('agent_sensors', self.sensor_type) kwargs = {**default_config, **kwargs} super().__init__(anchor, **kwargs) self._sensor_max_value = self._max_range
def __init__( self, can_absorb: bool = False, movable: bool = True, **kwargs, ): default_config = parse_configuration('agent_parts', PartTypes.PLATFORM) kwargs = {**default_config, **kwargs} Part.__init__(self, can_absorb=can_absorb, movable=movable, **kwargs)
def __init__(self, config_key: Optional[Union[str, ElementTypes]] = None, **entity_params): default_config = parse_configuration('element_modifier', config_key) entity_params = {**default_config, **entity_params} SceneElement.__init__(self, visible_shape=False, invisible_shape=True, **entity_params)
def __init__(self, anchor, position_anchor=(0, 0), angle_offset=0, **kwargs): default_config = parse_configuration('agent_parts', PartTypes.HAND) kwargs = {**default_config, **kwargs} super().__init__(anchor, position_anchor=position_anchor, angle_offset=angle_offset, **kwargs) self.pm_visible_shape.sensor = True
def __init__(self, anchor, position_anchor, angle_offset=0, **kwargs): default_config = parse_configuration('agent_parts', PartTypes.ARM) body_part_params = {**default_config, **kwargs} # arm attached at one extremity, and other anchor point defined at other extremity width, length = body_part_params['size'] position_part = (-length / 2.0 + width / 2.0, 0) self.extremity_anchor_point = (+length / 2.0 - width / 2.0, 0) super().__init__(anchor=anchor, position_anchor=position_anchor, position_part=position_part, angle_offset=angle_offset, **body_part_params) self.motor.max_force = ARM_MAX_FORCE
def __init__( self, destination: Optional[Union[Coordinate, CoordinateSampler, SceneElement]], config_key: Optional[Union[ElementTypes, str]] = None, keep_inertia: bool = True, **entity_params, ): default_config = parse_configuration('element_teleport', config_key) entity_params = {**default_config, **entity_params} super().__init__(**entity_params) self._destination = destination self.keep_inertia = keep_inertia
def __init__(self, config_key: Optional[Union[ElementTypes, str]] = None, **kwargs): """ Base class for Invisible zones that terminate upon contact. TerminationZone entities generate a termination of the episode, and provide a reward to the agent in contact with the entity. Args: **kwargs: other params to configure entity. Refer to Entity class. Keyword Args: reward: Reward provided. """ default_config = parse_configuration('element_zone', config_key) entity_params = {**default_config, **kwargs} super().__init__(**entity_params)
def __init__( self, textures: List[Union[Texture, Dict, Tuple[int, int, int]]], mode: str = 'loop', activable_by_agent: bool = False, **kwargs, ): entity_params = parse_configuration( 'element_conditioning', config_key=ElementTypes.COLOR_CHANGING) entity_params = {**kwargs, **entity_params} self.textures = [] self._activable_by_agent = activable_by_agent super().__init__(visible_shape=True, invisible_shape=activable_by_agent, background=False, texture=(0, 0, 0), **entity_params) for texture in textures: if isinstance(texture, dict): texture = TextureGenerator.create(**texture) elif isinstance(texture, tuple): texture = ColorTexture(color=texture) assert isinstance(texture, Texture) texture.size = self._size_visible self.textures.append(texture) texture.generate() assert len(self.textures) > 1 self.state = 0 self._mode = mode self._texture_changed = False
def __init__(self, reward: float, limit: Optional[float] = None, config_key: Optional[Union[ElementTypes, str]] = None, **entity_params): """ RewardZone entities are invisible zones. Provide a reward to the agent which is inside the zone. Args: **kwargs: other params to configure entity. Refer to Entity class Keyword Args: reward: Reward provided at each timestep when agent is in the zone total_reward: Total reward that the entity can provide during an Episode """ default_config = parse_configuration('element_zone', config_key) entity_params = {**default_config, **entity_params} super().__init__(reward=reward, **entity_params) self._limit = limit self._total_reward_provided = 0
def __init__(self, anchor, only_front=False, **kwargs): """ Refer to Sensor Class. Args: anchor: body Part to which the sensor is attached. Sensor is attached to the center of the Part. invisible_elements: elements that the sensor does not perceive. List of Parts of SceneElements. normalize: if true, Sensor values are normalized between 0 and 1. Default: True only_front: Only return the half part of the Playground that the Sensor faces. Remove what is behind the sensor. Default: False. """ default_config = parse_configuration('agent_sensors', SensorTypes.TOPDOWN_LOCAL) kwargs = {**default_config, **kwargs} super().__init__(anchor=anchor, **kwargs) self.only_front = only_front self._center = (int(self._resolution / 2) - 1, int(self._resolution / 2) - 1) # Calculate range with circle mask_circle = np.zeros((self._resolution, self._resolution), dtype=bool) rr, cc = draw.disk((self._center[0], self._center[1]), (int(self._resolution / 2) - 1), shape=mask_circle.shape) mask_circle[rr, cc] = 1 # Calculate fov with poly points = [[(int(self._resolution / 2) - 1), 0], [0, 0], [0, self._resolution], [(int(self._resolution / 2) - 1), self._resolution]] if self._fov > math.pi: points = [[self._resolution, 0] ] + points + [[self._resolution, self._resolution]] r1 = self._center[0] - (int(self._resolution / 2) - 1) * np.sin(math.pi / 2 + self._fov / 2) c1 = self._center[1] + (int(self._resolution / 2) - 1) * np.cos(math.pi / 2 + self._fov / 2) r2 = self._center[0] - (int(self._resolution / 2) - 1) * np.sin(math.pi / 2 - self._fov / 2) c2 = self._center[1] + (int(self._resolution / 2) - 1) * np.cos(math.pi / 2 - self._fov / 2) points = points + [[r2, c2], self._center, [r1, c1]] mask_poly = draw.polygon2mask((self._resolution, self._resolution), np.array(points)) self.mask_total_fov = mask_circle & mask_poly self._sensor_max_value = 255 if self.only_front: self._sensor_size = int(self._resolution / 2), self._resolution, 3 else: self._sensor_size = self._resolution, self._resolution, 3