def __init__( self, num_obstacles: int = 10, num_initial_pointmesses: int = 10, num_pointmesses_on_collision: int = 3, img_scale: int = 1, grayscale: bool = False, oracle_obs: bool = False, safe_sep: float = 1.0, walls: bool = False, dense_rewards: bool = False, ): self._pointer = Image.open(get_image_path("pointer.png")) self._egoimg = Image.open(get_image_path("top/blue.png")) self._hazardimg = Image.open(get_image_path("top/hazard.png")) self._goalimg = Image.open(get_image_path("top/goal.png")) self._pointmessimg = Image.open(get_image_path("top/pointmess.png")) scene = Image.open(get_image_path("top/bg.png")) img_names = ["_egoimg", "_hazardimg", "_goalimg", "_pointmessimg", "_scene"] self.num_obstacles = num_obstacles self.num_initial_pointmess = num_initial_pointmesses self.num_pointmesses_on_collision = num_pointmesses_on_collision # properties of the map self.map_buffer = 12 # properties of the dynamics self.T = 0.1 self.A = 30 self.B = 30 self.min_w = -1 self.max_w = 1 self.max_v = 30 self._safe_sep = safe_sep # configuration variables for debugging. # If true, we'll place yellow dots at the midpoints of various objects. self.place_pointers = False # [v, cos(theta), sin(theta)] vector_obs_bounds = ([0, -1, -1], [self.max_v, 1, 1]) super().__init__( img_scale, grayscale, oracle_obs, scene, img_names, vector_obs_bounds=vector_obs_bounds, ) # properties relevant to computing collisions. # RADIUS determines if a collision is happening. We'll use the sizes of the images to directly compute when they # overlap. assert self._hazardimg.size[0] == self._hazardimg.size[1] assert self._goalimg.size[0] == self._hazardimg.size[0] self._hazard_radius = self._egoimg.size[0] / 2 + self._hazardimg.size[0] / 2 self._safe_sep += self._hazard_radius assert self._pointmessimg.size[0] == self._pointmessimg.size[1] self._pointmess_radius = ( self._egoimg.size[0] / 2 + self._pointmessimg.size[0] / 2 )
def __init__( self, num_obstacles: int = 10, # TODO img_scale: int = 1, grayscale: bool = False, oracle_obs: bool = False, safe_sep: float = 1.0, extra_hazard_size: Optional[int] = None, walls: bool = False, dense_rewards: bool = False, randomize_goal: bool = False, ): """ :param extra_hazard_size: for debugging only; this renders hazards a second time with half alpha and with height and width increased by this amount. This is useful to visualize how far a safe agent has to stay away from hazards if it has a certain number of pixels of maximum detection error. :param walls: don't let the agent go off the screen; no boundary penalty :param dense_rewards: rewards for distance + angle to goal """ scene = Image.open(get_image_path("top/bg.png")) ego_img = Image.open(get_image_path("top/blue.png")) goal_img = Image.open(get_image_path("top/goal.png")) hazard_img = Image.open(get_image_path("top/hazard.png")) hazard_x_idx = [ self._obs_start_idx + 2 * i for i in range(num_obstacles) ] hazard_y_idx = [x_idx + 1 for x_idx in hazard_x_idx] objs = { "ego": (ego_img, self._ego_x_idx, self._ego_y_idx), "goal": (goal_img, self._goal_x_idx, self._goal_y_idx), "hazard": (hazard_img, hazard_x_idx, hazard_y_idx), } # load graphics scene = Image.open(get_image_path("top/bg.png")) self.map_buffer = 12 self.T = 0.1 self.A = 30 # can change v by max 3 per step self.B = 30 # should be positive; accel range is [-B, A] self.min_w = -1 self.max_w = 1 self.max_v = 30 # max 3 pixels per step self._safe_sep = safe_sep self.num_obstacles = num_obstacles self._extra_hazard_size = extra_hazard_size self._walls = walls self._dense_rewards = dense_rewards self._randomize_goal = randomize_goal self.place_pointers = False # [v, cos(theta), sin(theta)] vector_obs_bounds = ([0, -1, -1], [self.max_v, 1, 1]) super().__init__( img_scale, grayscale, oracle_obs, scene, objs, vector_obs_bounds=vector_obs_bounds, ) # _radius determines if a collision is happening. We'll use the sizes of the # images to directly compute when they overlap. assert hazard_img.size[0] == hazard_img.size[1] # not true for ego img, but width is larger, so radius is still okay # assert self._egoimg.size[0] == self._egoimg.size[1] assert goal_img.size[0] == hazard_img.size[0] self._radius = ego_img.size[0] / ( 2 * img_scale) + hazard_img.size[0] / (2 * img_scale) self._safe_sep += self._radius self._max_goal_dist = sqrt(self._width**2 + self._height**2)
def __init__( self, continuous_action_space: bool = True, A: int = 5, B: int = 5, T: float = 0.5, safe_sep: float = 1.0, img_scale: int = 1, grayscale: bool = False, oracle_obs: bool = False, walls: bool = False, dense_rewards: bool = False, ): """ :param continuous_action_space: if True the agent's action space is [-B, A]; otherwise, it's {-B, A}. """ assert A > 0 and B > 0 and T > 0 scene = Image.open(get_image_path("lateral/bg.png")) ego_img = Image.open(get_image_path("lateral/blue.png")) leader_img = Image.open(get_image_path("lateral/red.png")) self._y_coord = 3 / 5 * scene.height / img_scale + 37 / img_scale objs = { "ego": (ego_img, self._ego_x_idx, self._y_coord), "leader": (leader_img, self._leader_x_idx, self._y_coord), } self.continuous_action_space = continuous_action_space self.A = A self.B = B self.T = T self._safe_sep = safe_sep self._buffer_space = 1 self.show_pointers = False # [relative velocity] vector_obs_bounds = ([-100], [100] ) # TODO: these bounds aren't enforced super().__init__( img_scale, grayscale, oracle_obs, scene, objs, vector_obs_bounds=vector_obs_bounds, ) # graphics self._init_state = np.array( [ self._width / 4, # car position 0, # the relative velocity of the two cars. 3 * self._width / 4, # leader position ], dtype=np.float32, ) self._safe_sep += (ego_img.width + leader_img.width) / (2 * img_scale) # the reward-optimal distance back from the leader self._optimal_dist = self._safe_sep + ego_img.width / img_scale
def __init__( self, num_obstacles: int = 10, num_initial_pointmesses: int = 10, num_pointmesses_on_collision: int = 3, img_scale: int = 1, grayscale: bool = False, oracle_obs: bool = False, safe_sep: float = 1.0, walls: bool = False, dense_rewards: bool = False, ): scene = Image.open(get_image_path("top/bg.png")) ego_img = Image.open(get_image_path("top/blue.png")) goal_img = Image.open(get_image_path("top/goal.png")) hazard_img = Image.open(get_image_path("top/hazard.png")) pm_img = Image.open(get_image_path("top/pointmess.png")) hazard_x_idx = [ self._obs_start_idx + 2 * i for i in range(num_obstacles) ] hazard_y_idx = [x_idx + 1 for x_idx in hazard_x_idx] n_pm_total = (num_initial_pointmesses + num_pointmesses_on_collision * num_obstacles) pm_x_idx = [ self._obs_start_idx + num_obstacles * 2 + 2 * i for i in range(n_pm_total) ] pm_y_idx = [x_idx + 1 for x_idx in pm_x_idx] objs = { "ego": (ego_img, self._ego_x_idx, self._ego_y_idx), "goal": (goal_img, self._goal_x_idx, self._goal_y_idx), "hazard": (hazard_img, hazard_x_idx, hazard_y_idx), "pointmess": (pm_img, pm_x_idx, pm_y_idx), } self.num_obstacles = num_obstacles self.num_initial_pointmess = num_initial_pointmesses self.num_pointmesses_on_collision = num_pointmesses_on_collision # properties of the map self.map_buffer = 12 # properties of the dynamics self.T = 0.1 self.A = 30 self.B = 30 self.min_w = -1 self.max_w = 1 self.max_v = 30 self._safe_sep = safe_sep # configuration variables for debugging. # If true, we'll place yellow dots at the midpoints of various objects. self.place_pointers = False # [v, cos(theta), sin(theta)] vector_obs_bounds = ([0, -1, -1], [self.max_v, 1, 1]) super().__init__( img_scale, grayscale, oracle_obs, scene, objs, vector_obs_bounds=vector_obs_bounds, ) # properties relevant to computing collisions. # RADIUS determines if a collision is happening. We'll use the sizes of the images to directly compute when they # overlap. assert hazard_img.size[0] == hazard_img.size[1] assert goal_img.size[0] == hazard_img.size[0] assert pm_img.size[0] == pm_img.size[1] self._hazard_radius = (ego_img.size[0] + hazard_img.size[0]) / (2 * img_scale) self._safe_sep += self._hazard_radius self._pointmess_radius = (ego_img.size[0] + pm_img.size[0]) / (2 * img_scale)
def __init__( self, continuous_action_space: bool = True, A: int = 5, B: int = 5, T: float = 0.5, safe_sep: float = 1.0, img_scale: int = 1, grayscale: bool = False, oracle_obs: bool = False, walls: bool = False, dense_rewards: bool = False, ): """ :param continuous_action_space: if True the agent's action space is [-B, A]; otherwise, it's {-B, A}. """ assert A > 0 and B > 0 and T > 0 scene = Image.open(get_image_path("lateral/bg.png")) self._cimg = Image.open(get_image_path("lateral/blue.png")) self._limg = Image.open(get_image_path("lateral/red.png")) self._pointer = Image.open(get_image_path("pointer.png")) img_names = ["_cimg", "_limg", "_scene"] self.continuous_action_space = continuous_action_space self.A = A self.B = B self.T = T self._safe_sep = safe_sep self._buffer_space = 1 self.show_pointers = False # [relative velocity] vector_obs_bounds = ([-100], [100]) # TODO: these bounds aren't enforced super().__init__( img_scale, grayscale, oracle_obs, scene, img_names, vector_obs_bounds=vector_obs_bounds, ) # graphics self._y_coord = int(3 * self._height / 5 + 37 / img_scale) self._init_state = np.array( [ self._width / 4, # car position 0, # the relative velocity of the two cars. 3 * self._width / 4, # leader position ], dtype=np.float32, ) self._safe_sep += self._cimg.width / 2 + self._limg.width / 2 # distance between follower and leader that leads to a crash self._crash_dist = ( self._cimg.width / 2 + self._limg.width / 2 + self._buffer_space ) # the reward-optimal distance back from the leader self._optimal_dist = self._crash_dist + self._cimg.width