2D Collision Avoidance

Ver. 1.1.0 (2025-07-17)

This module provides a 2D environment for collision avoidance of a trajectory planning with dynamic goals. The DynamicTrajectoryPlanner environment simulates a 2D space where an agent must navigate towards dynamically moving goals while avoiding static obstacles.

The agent, equipped with sensors providing information only on initial to goal trajectories, operates within a continuous action space to move and adjust its path.

In this module, rewards are not defined but we give some important components for developing the reward function including actual distance of the trajectory and number of collisions that can be used to penalise for any collisions.

This environment is dynamic, with goals potentially changing over time, which makes it ideal for training reinforcement learning agents for tasks like autonomous robot navigation, drone flight in urban areas, and autonomous vehicle path planning, which emphasize trajectory optimization and collision avoidance in real-world-like settings.

class mlpro.rl.pool.envs.collisionavoidance_2D.DynamicTrajectoryPlanner(p_visualize: bool = True, p_logging=True, p_num_point: int = 5, p_cycle_limit: int = 100, p_xlimit: list = [-4, 4], p_ylimit: list = [-4, 4], p_action_boundaries: list = [-0.02, 0.02], p_dt: float = 0.01, p_resolution: float = 0.01, p_multi_goals: list = [[3, 3], [2, 2], [1, 3], [3, 1]], p_start_pos: list = [-3, -3], p_obstacles: list = [[-1, -1], [1, -1], [1, 1], [-1, 1]])

Bases: Environment

This is the main class of Dynamic Trajectory Planner environment that inherits Environment class from MLPro.

Parameters:
  • p_visualize (bool, optional) – Boolean switch for visualisation. Default = False.

  • p_logging (Log, optional) – Logging functionalities. Default = Log.C_LOG_ALL.

  • p_num_point (int, optional) – Number of nodes within the trajectory, including start and finish nodes. Default = 5.

  • p_cycle_limit (int, optional) – Cycle limit before the environment ends. Default = 100.

  • p_xlimit (list, optional) – Limit of x-axis of the environment frame. Default = [-4,4].

  • p_ylimit (list, optional) – Limit of y-axis of the environment frame. Default = [-4,4].

  • p_action_boundaries (list, optional) – Action boundaries. Default = [-0.02,0.02].

  • p_dt (float, optional) – Plot pause duration. Default = 0.01.

  • p_resolution (float, optional) – Plot resolution. Default = 0.01.

  • p_multi_goals (list, optional) – Set a list of possible goals (target nodes) positions. Default = [[3,3],[2,2],[1,3],[3,1]].

  • p_start_pos (list, optional) – Starting node position. Default = [-3,-3].

  • p_obstacles (list, optional) – Obstacles positions. Default = [[-1,-1],[1,-1],[1,1],[-1,1]].

C_NAME = 'Trajectory Planner'
C_CYCLE_LIMIT = 0
static setup_spaces()

Static template method to set up and return state and action space of environment.

Returns:

  • state_space (MSpace) – State space object

  • action_space (MSpace) – Action space object

_setup_spaces()
_add_obstacle(p_obstacle)
_draw_obstacle()
_draw_start_goal()
_draw_traj()
_clear_traj()
_calc_init_traj(p_num_point)
_collide_check_point_list()
_collide_check_point(p_traject)
_collide_check_line()
_get_obs()
_calc_distance()
_compute_reward(p_state_old: State, p_state_new: State) Reward

Custom reward method. See method compute_reward() for further details.

_compute_success(p_state: State) bool

Custom method for assessment for success. Implement this method if no external function is used. See method compute_success() for further details.

_compute_broken(p_state: State) bool

Custom method for assessment for breakdown. Implement this method if no external function is used. See method compute_broken() for further details.

_reset(p_seed=None) None

Custom method to reset the system to an initial/defined state. Use method _set_status() to set the state.

Parameters:

p_seed (int) – Seed parameter for an internal random generator

init_plot(p_figure=None)

Initializes the plot functionalities of the class.

Parameters:
  • p_figure (Matplotlib.figure.Figure, optional) – Optional MatPlotLib host figure, where the plot shall be embedded. The default is None.

  • p_plot_settings (PlotSettings) – Optional plot settings. If None, the default view is plotted (see attribute C_PLOT_DEFAULT_VIEW).

update_plot()

Updates the plot.

Parameters:

**p_kwargs – Implementation-specific plot data and/or parameters.

_simulate_reaction(p_state: State, p_action: Action) State

Custom method for a simulated state transition. Implement this method if no external state transition function is used. See method simulate_reaction() for further details.