Environment
The environment is an obstacle avoidance task. Please see chapter 4 of the thesis for more details.
- class src.envs.obstacle_avoidance.Agent(x, y, radius, perspective, step_size)[source]
The agent representation
- Parameters:
x (float) – x-coordinate starting position
y (float) – y-coordinate starting position
radius (float) – Radius of the agent
perspective (float) – Starting perspective
step_size (float) – moving distance with each step
- geometric_representation()[source]
Returns the shapely geometry representation of the agent
- Returns:
shapely geometry object
- class src.envs.obstacle_avoidance.Obstacle(coordinates: list, step_size)[source]
The obstacle representation
- Parameters:
coordinates (list) – Polygon coordinates for the shape of the obstacle
step_size (float) – moving distance with each step
- add_waypoint(waypoint)[source]
Adds a new waypoint to which the obstacle moves
- Parameters:
waypoint (list) – waypoint coordinates
- collision_area(radius)[source]
Returns the area which would lead to a collision when the agent enters it
- Parameters:
radius – The radius of the agent
- Returns:
shapely geometry object
- class src.envs.obstacle_avoidance.ObstacleAvoidance(env_config, render_mode: Optional[str] = None)[source]
The obstacle avoidance environment
- Parameters:
env_config (dict) – Setup of the environment
render_mode (str) – Select how to visualize the environment. Options are human, rgb_array, and jupyter
- angle_to_target()[source]
Calculates the angle between the agent and the goal
- Returns:
angle_to_target (float)
- detect_collision()[source]
Checks if the agent violated any of the restrictions
- Returns:
violation (bool)
- distance_to_target()[source]
Calculates the distance between the agent and the goal
- Returns:
distance_to_target (float)
- get_allowed_actions()[source]
Iterates through the obstacles and calculates the intervals which are allowed and do not lead to a collision
- Returns:
Allowed action space
- Return type:
allowed_actions (list)
- get_restrictions_for_polygon(polygon_coordinates)[source]
Calculates the restriction angles for the agent and a single polygon
- Parameters:
polygon_coordinates (list) – List of polygon corner points that define the shape of the obstacle
- Returns:
List of intervals which would lead to a collision. For example [[-10, 30]]
- Return type:
restrictions (list)
- get_reward()[source]
Calculates the reward based on collisions, improvement and the distance to the goal
- Returns:
reward (float)
- load_map(structure: dict)[source]
Loads the current level of the map.
- Parameters:
structure (dict) – Setup of the environment
- metadata = {'render_fps': 4, 'render_modes': ['human', 'rgb_array', 'jupyter'], 'video.frames_per_second': 4}
- render(render_mode: Optional[str] = 'rgb_array', draw_trajectory: bool = False, draw_information=True)[source]
Renders the environment
- Parameters:
render_mode (str) –
draw_trajectory (bool) – Whether past steps should be indicated on the map
draw_information (bool) – Whether to show information about the reward, target distance, and allowed actions
- obstacle_avoidance.generate_obstacles(height: float, num_obstacles: int, position_covariance: Optional[list] = None, mean_size_obstacle: float = 1.0, sigma_size_obstacle: float = 0.2, range_size_obstacle: float = 0.5, num_waypoints: int = 0, distance_waypoints: float = 2.0, sigma_distance: float = 1.0, step_size: float = 0.3, seed: Optional[int] = None, obstacles: Optional[dict] = None, forbidden_circles: Optional[list] = None, max_iterations: int = 10000, uniform: bool = False)
Algorithm to generate environment setups
- Parameters:
width (float) – Width of the map
height (float) – Height of the map
num_obstacles (int) – Number of obstacles
position_covariance (list) – Covariance matrix
mean_size_obstacle (float) – Mean size of an obstacle
sigma_size_obstacle (float) – Standard deviation of the obstacle size
range_size_obstacle (float) – Defines the minimum and maximum allowed obstacle sizes
num_waypoints (int) – Number of waypoints for each obstacle
distance_waypoints (float) – Mean distance of the straight path
sigma_distance (float) – Standard deviation of the waypoints’ distance
step_size (float) – Step size of the obstacles
seed (int) – Seed to make generations reproducible
obstacles (dict) – Already existing obstacles in the environment
forbidden_circles (list) – List of circles in which no obstacle or waypoint should be placed
max_iterations (int) – Maximum generation trials before the next setup is taken
uniform (bool) – Whether to sample uniformly instead of a normal distribution
- Returns:
obstacle setup which can be used in an environment configuration
- Return type:
setup (dict)