ast_toolbox.simulators.example_av_simulator package

Toy AV simulator and an example AST simulator wrapper

class ast_toolbox.simulators.example_av_simulator.ToyAVSimulator(num_peds=1, dt=0.1, alpha=0.85, beta=0.005, v_des=11.17, delta=4.0, t_headway=1.5, a_max=3.0, s_min=4.0, d_cmf=2.0, d_max=9.0, min_dist_x=2.5, min_dist_y=1.4, car_init_x=-35.0, car_init_y=0.0)[source]

Bases: object

A toy simulator of a scenario of an AV approaching a crosswalk where some pedestrians are crossing.

The vehicle runs a modified version of the Intelligent Driver Model [1]. The vehicle treats the closest pedestrian in the road as a car to follow. If no pedestrians are in the road, it attempts to maintain the desired speed. Noisy observations of the pedestrian are smoothed through an alpha-beta filter [2].

A collision results if any pedestrian’s x-distance and y-distance to the ego vehicle are less than the respective min_dist_x and min_dist_y.

The origin is centered in the middle of the east/west lane and the north/south crosswalk. The positive x proceeds east down the lane, the positive y proceeds north across the crosswalk.

Parameters:
  • num_peds (int) – The number of pedestrians crossing the street.
  • dt (float) – The length (in seconds) of each timestep.
  • alpha (float) – The alpha parameter in the tracker’s alpha-beta filter [2].
  • beta (float) – The beta parameter in the tracker’s alpha-beta filter [2].
  • v_des (float) – The desired velocity, in meters per second, for the ego vehicle to maintain
  • delta (float) – The delta parameter in the IDM algorithm [1].
  • t_headway (float) – The headway parameter in the IDM algorithm [1].
  • a_max (float) – The maximum acceleration parameter in the IDM algorithm [1].
  • s_min (float) – The minimum follow distance parameter in the IDM algorithm [1].
  • d_cmf (float) – The maximum comfortable deceleration parameter in the IDM algorithm [1].
  • d_max (float) – The maximum deceleration parameter in the IDM algorithm [1].
  • min_dist_x (float) – The minimum x-distance between the ego vehicle and a pedestrian.
  • min_dist_y (float) – The minimum y-distance between the ego vehicle and a pedestrian.
  • car_init_x (float) – The initial x-position of the ego vehicle.
  • car_init_y (float) – The initial y-position of the ego vehicle.

References

[1](1, 2, 3, 4, 5, 6, 7) Treiber, Martin, Ansgar Hennecke, and Dirk Helbing. “Congested traffic states in empirical observations and microscopic simulations.” Physical review E 62.2 (2000): 1805. https://journals.aps.org/pre/abstract/10.1103/PhysRevE.62.1805
[2](1, 2, 3) Rogers, Steven R. “Alpha-beta filter with correlated measurement noise.” IEEE Transactions on Aerospace and Electronic Systems 4 (1987): 592-594. https://ieeexplore.ieee.org/abstract/document/4104388
collision_detected()[source]

Returns whether the current state is in the goal set.

Checks to see if any pedestrian’s position violates both the min_dist_x and min_dist_y constraints.

Returns:bool – True if current state is in goal set.
get_ground_truth()[source]

Clones the ground truth simulator state.

Returns:dict – A dictionary of simulator state variables.
log()[source]

Perform any logging steps.

move_car(car, accel)[source]

Update the ego vehicle’s state.

Parameters:
  • car (array_like) – The ego vehicle’s state: [x-velocity, y-velocity, x-position, y-position].
  • accel (float) – The ago vehicle’s acceleration.
Returns:

array_like – An updated version of the ego vehicle’s state.

observe()[source]

Get the ground truth state of the pedestrian relative to the ego vehicle.

reset(s_0)[source]

Resets the state of the environment, returning an initial observation.

Parameters:s_0 (array_like) – The initial conditions to reset the simulator to.
Returns:array_like – An observation from the timestep, determined by the settings and the observation_return helper function.
run_simulation(actions, s_0, simulation_horizon)[source]

Run a full simulation given the AST solver’s actions and initial conditions.

Parameters:
  • actions (list[array_like]) – A sequential list of actions taken by the AST Solver which deterministically control the simulation.
  • s_0 (array_like) – An array specifying the initial conditions to set the simulator to.
  • simulation_horizon (int) – The maximum number of steps a simulation rollout is allowed to run.
Returns:

  • terminal_index (int) – The index of the action that resulted in a state in the goal set E. If no state is found terminal_index should be returned as -1.
  • array_like – An array of relevant simulator info, which can then be used for analysis or diagnostics.

sensors(peds, noise)[source]

Get a noisy observation of the pedestrians’ locations and velocities.

Parameters:
  • peds (array_like) – Positions and velocities of the pedestrians.
  • noise (array_like) – Noise to add to the positions and velocities of the pedestrians.
Returns:

array_like – Noisy observation of the pedestrians’ locations and velocities.

set_ground_truth(in_simulator_state)[source]

Sets the simulator state variables.

Parameters:in_simulator_state (dict) – A dictionary of simulator state variables.
step_simulation(action)[source]

Handle anything that needs to take place at each step, such as a simulation update or write to file.

Parameters:action (array_like) – A 1-D array of actions taken by the AST Solver which deterministically control a single step forward in the simulation.
Returns:array_like – An observation from the timestep, determined by the settings and the observation_return helper function.
tracker(estimate_old, measurements)[source]

An alpha-beta filter to smooth noisy observations into an estimate of pedestrian state.

Parameters:
  • estimate_old (array_like) – The smoothed state estimate from the previous timestep.
  • measurements (array_like) – The noisy observation of pedestrian state from the current timestep.
Returns:

array_like – The smoothed state estimate of pedestrian state from the current timestep.

update_car(obs, v_car)[source]

Calculate the ego vehicle’s acceleration.

Parameters:
  • obs (array_like) – Smoothed estimate of pedestrian state from the tracker.
  • v_car (float) – Current velocity of the ego vehicle.
Returns:

float – The acceleration of the ego vehicle.

update_peds()[source]

Update the pedestrian’s state.

class ast_toolbox.simulators.example_av_simulator.ExampleAVSimulator(num_peds=1, simulator_args=None, **kwargs)[source]

Bases: ast_toolbox.simulators.ast_simulator.ASTSimulator

Example simulator wrapper for a scenario of an AV approaching a crosswalk where some pedestrians are crossing.

Wraps ast_toolbox.simulators.example_av_simulator.ToyAVSimulator

Parameters:
  • num_peds (int) – Number of pedestrians crossing the street.
  • simulator_args (dict) – Dictionary of keyword arguments to be passed to the wrapped simulator.
  • kwargs – Keyword arguments passed to the super class.
clone_state()[source]

Clone the simulator state for later resetting.

This function is used in conjunction with restore_state for Go-Explore and Backwards Algorithm to do their deterministic resets.

Returns:array_like – An array of all the simulation state variables.
closed_loop_step(action)[source]

User implemented function to step the simulation forward in time when closed-loop control is active.

This function should step the simulator forward a single timestep based on the given action. It will only be called when open_loop is False. This function should always return self.observation_return().

Parameters:action (array_like) – A 1-D array of actions taken by the AST Solver which deterministically control a single step forward in the simulation.
Returns:array_like – An observation from the timestep, determined by the settings and the observation_return helper function.
get_first_action()[source]

An initialization method used in Go-Explore.

Returns:array_like – A 1-D array of the same dimension as the action space, all zeros.
get_reward_info()[source]

Returns any info needed by the reward function to calculate the current reward.

is_goal()[source]

Returns whether the current state is in the goal set. :returns: bool – True if current state is in goal set.

log()[source]

Perform any logging steps.

reset(s_0)[source]

Resets the state of the environment, returning an initial observation.

User implementations should always call the super class implementation. This function should always return self.observation_return().

Parameters:s_0 (array_like) – The initial conditions to reset the simulator to.
Returns:array_like – An observation from the timestep, determined by the settings and the observation_return helper function.
restore_state(in_simulator_state)[source]

Reset the simulation deterministically to a previously cloned state.

This function is used in conjunction with clone_state for Go-Explore and Backwards Algorithm to do their deterministic resets.

Parameters:in_simulator_state (array_like) – An array of all the simulation state variables.
simulate(actions, s_0)[source]

Run a full simulation given the AST solver’s actions and initial conditions.

simulate takes in the AST solver’s actions and the initial conditions. It should return two values: a terminal index and an array of relevant simulation information.

Parameters:
  • actions (list[array_like]) – A sequential list of actions taken by the AST Solver which deterministically control the simulation.
  • s_0 (array_like) – An array specifying the initial conditions to set the simulator to.
Returns:

  • terminal_index (int) – The index of the action that resulted in a state in the goal set E. If no state is found terminal_index should be returned as -1.
  • array_like – An array of relevant simulator info, which can then be used for analysis or diagnostics.