Kinematics#

The vehicles kinematics are represented in the Vehicle class by the Kinematic Bicycle Model [PAltcheDAndreaN17].

\[\begin{split} \dot{x}&=v\cos(\psi+\beta) \\ \dot{y}&=v\sin(\psi+\beta) \\ \dot{v}&=a \\ \dot{\psi}&=\frac{v}{l}\sin\beta \\ \beta&=\tan^{-1}(1/2\tan\delta), \\ \end{split}\]

where

  • \((x, y)\) is the vehicle position;

  • \(v\) its forward speed;

  • \(\psi\) its heading;

  • \(a\) is the acceleration command;

  • \(\beta\) is the slip angle at the center of gravity;

  • \(\delta\) is the front wheel angle used as a steering command.

These calculations appear in the step() method.

API#

class highway_env.vehicle.kinematics.Vehicle(road: Road, position: ndarray | Sequence[float], heading: float = 0, speed: float = 0, predition_type: str = 'constant_steering')[source]#

A moving vehicle on a road, and its kinematics.

The vehicle is represented by a dynamical system: a modified bicycle model. It’s state is propagated depending on its steering and acceleration actions.

Parameters:
  • road – the road instance where the object is placed in

  • position – cartesian position of object in the surface

  • heading – the angle from positive direction of horizontal axis

  • speed – cartesian speed of object in the surface

LENGTH: float = 5.0#

Vehicle length [m]

WIDTH: float = 2.0#

Vehicle width [m]

DEFAULT_INITIAL_SPEEDS = [23, 25]#

Range for random initial speeds [m/s]

MAX_SPEED = 40.0#

Maximum reachable speed [m/s]

MIN_SPEED = -40.0#

Minimum reachable speed [m/s]

HISTORY_SIZE = 30#

Length of the vehicle state history, for trajectory display

classmethod create_random(road: Road, speed: float | None = None, lane_from: str | None = None, lane_to: str | None = None, lane_id: int | None = None, spacing: float = 1) Vehicle[source]#

Create a random vehicle on the road.

The lane and /or speed are chosen randomly, while longitudinal position is chosen behind the last vehicle in the road with density based on the number of lanes.

Parameters:
  • road – the road where the vehicle is driving

  • speed – initial speed in [m/s]. If None, will be chosen randomly

  • lane_from – start node of the lane to spawn in

  • lane_to – end node of the lane to spawn in

  • lane_id – id of the lane to spawn in

  • spacing – ratio of spacing to the front vehicle, 1 being the default

Returns:

A vehicle with random position and/or speed

classmethod create_from(vehicle: Vehicle) Vehicle[source]#

Create a new vehicle from an existing one.

Only the vehicle dynamics are copied, other properties are default.

Parameters:

vehicle – a vehicle

Returns:

a new vehicle at the same dynamical state

act(action: dict | str | None = None) None[source]#

Store an action to be repeated.

Parameters:

action – the input action

step(dt: float) None[source]#

Propagate the vehicle state given its actions.

Integrate a modified bicycle model with a 1st-order response on the steering wheel dynamics. If the vehicle is crashed, the actions are overridden with erratic steering and braking until complete stop. The vehicle’s current lane is updated.

Parameters:

dt – timestep of integration of the model [s]