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: highway_env.road.road.Road, position: Union[numpy.ndarray, Sequence[float]], heading: float = 0, speed: float = 0)[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.

COLLISIONS_ENABLED = True

Enable collision detection between vehicles

LENGTH = 5.0

Vehicle length [m]

WIDTH = 2.0

Vehicle width [m]

DEFAULT_SPEEDS = [23, 25]

Range for random initial speeds [m/s]

MAX_SPEED = 40.0

Maximum reachable speed [m/s]

__init__(road: highway_env.road.road.Road, position: Union[numpy.ndarray, Sequence[float]], heading: float = 0, speed: float = 0)[source]

Initialize self. See help(type(self)) for accurate signature.

classmethod make_on_lane(road: highway_env.road.road.Road, lane_index: Tuple[str, str, int], longitudinal: float, speed: float = 0) → highway_env.vehicle.kinematics.Vehicle[source]

Create a vehicle on a given lane at a longitudinal position.

Parameters
  • road – the road where the vehicle is driving

  • lane_index – index of the lane where the vehicle is located

  • longitudinal – longitudinal position along the lane

  • speed – initial speed in [m/s]

Returns

A vehicle with at the specified position

classmethod create_random(road: highway_env.road.road.Road, speed: float = None, spacing: float = 1) → highway_env.vehicle.kinematics.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

  • 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: highway_env.vehicle.kinematics.Vehicle) → highway_env.vehicle.kinematics.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: Union[dict, str] = 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]

clip_actions() → None[source]
on_state_update() → None[source]
lane_distance_to(vehicle: highway_env.vehicle.kinematics.Vehicle, lane: highway_env.road.lane.AbstractLane = None) → float[source]

Compute the signed distance to another vehicle along a lane.

Parameters
  • vehicle – the other vehicle

  • lane – a lane

Returns

the distance to the other vehicle [m]

check_collision(other: Union[Vehicle, RoadObject]) → None[source]

Check for collision with another vehicle.

Parameters

other – the other vehicle or object

_is_colliding(other)[source]
property direction
property velocity
property destination
property destination_direction
property on_road

Is the vehicle on its current lane, or off-road ?

front_distance_to(other: highway_env.vehicle.kinematics.Vehicle) → float[source]
__module__ = 'highway_env.vehicle.kinematics'
to_dict(origin_vehicle: Optional[highway_env.vehicle.kinematics.Vehicle] = None, observe_intentions: bool = True) → dict[source]
dump() → None[source]

Update the internal log of the vehicle

The log contains: - its kinematics; - some metrics relative to its neighbour vehicles.

get_log() → pandas.core.frame.DataFrame[source]

Cast the internal log as a DataFrame.

Returns

the DataFrame of the Vehicle’s log.

__str__()[source]

Return str(self).

__repr__()[source]

Return repr(self).