ensemble.component package

Submodules

ensemble.component.dynamics module

Dynamics Model

This module contains a set of models to explain the truck dynamics. The way in which dynamics are regularly described are:

\[x_{k+1} = f(x_k)\]
class ensemble.component.dynamics.PlatoonDynamics[source]

Bases: object

Potential class for handling vector state for platoons

class ensemble.component.dynamics.RegularDynamics(vehid: int, x: float, v: float, a: float)[source]

Bases: ensemble.metaclass.dynamics.AbsDynamics

property T

Current time step

a: ctypes.c_double
interAxes: ctypes.c_double = c_double(0.75)
length: ctypes.c_double = c_double(5.92)
library: str = '/home/docs/checkouts/readthedocs.org/user_builds/ensemble-docs/checkouts/latest/ensemble/libs/linux/truckDynamics.so'
mass: ctypes.c_double = c_double(26450.0)
v: ctypes.c_double
vehid: ctypes.c_int
width: ctypes.c_double = c_double(2.49)
x: ctypes.c_double
class ensemble.component.dynamics.SampleDynamics[source]

Bases: ensemble.metaclass.dynamics.AbsDynamics

property T

Current time step

class ensemble.component.dynamics.TruckDynamics(vehid: int, x: float, v: float, a: float)[source]

Bases: ensemble.metaclass.dynamics.AbsDynamics

External truck model

property T

Current time step

__call__(state: numpy.ndarray, control: numpy.ndarray) numpy.ndarray[source]

Computes the dynamics passing through the truck

Parameters
  • state (np.ndarray) – Truck state @k (position, speed)

  • control (np.ndarray) –

Returns

Return type

np.ndarray

a: ctypes.c_double
getAcceleration(external_acc: float) numpy.ndarray[source]

Computes truck acceleration

Parameters

external_acc (float) – CACC/ACC commanded control

Returns

Truck acceleration for state computation.

Return type

np.ndarray

interAxes: ctypes.c_double = c_double(0.75)
length: ctypes.c_double = c_double(5.92)
library: str = '/home/docs/checkouts/readthedocs.org/user_builds/ensemble-docs/checkouts/latest/ensemble/libs/linux/truckDynamics.so'
load_library(path_library)[source]

Loads the truck library into the class

mass: ctypes.c_double = c_double(26450.0)
v: ctypes.c_double
vehid: ctypes.c_int
width: ctypes.c_double = c_double(2.49)
x: ctypes.c_double
ensemble.component.dynamics.dynamic_2nd_ego(state: numpy.ndarray, control: numpy.ndarray) numpy.ndarray[source]

Update vehicle state in 2nd order dynamics

Parameters
  • state (np.ndarray) – 2d-array @ k [position;speed]

  • control (np.ndarray) – 1d-array [control]

Returns

[3d-array] @ k+1 [position;speed]

Return type

np.ndarray

ensemble.component.dynamics.dynamic_3rd_ego(state: numpy.ndarray, control: numpy.ndarray) numpy.ndarray[source]

Update vehicle state in 3rd order dynamics

Parameters
  • state (np.ndarray) – 3d-array @ k [position;speed;acceleration]

  • control (np.ndarray) – 1d-array [control]

Returns

[3d-array] @ k+1 [position;speed;acceleration]

Return type

np.ndarray

ensemble.component.platoon_vehicle module

Platoon Vehicle

This module contains information on a vehicle platoon.

The platoon vehicle model acts as an instance to trace individual vehicle data and modify vehicle behavior according to given dynamics.

class ensemble.component.platoon_vehicle.PlatoonVehicle(request: ensemble.metaclass.stream.DataQuery, **kwargs)[source]

Bases: ensemble.component.vehicle.Vehicle

This is a vehicle class defined for storing data on a single platoon vehicle.

You need a Publisher from where the vehicle is going to take data:

Parameters

request (Publisher) – Parser or object publishing data

Returns

A Dataclass with vehicle parameters

Return type

vehicle (PlatoonVehicle)

Variable

Description

abscissa

Current coordinate on y axis

acceleration

Current acceleration

distance

Current distance traveled on link

elevation

Current elevation

lane

Current lane

link

Current road vehicle is traveling

ordinate

Current coordinate x axis

speed

Current speed

vehid

Vehicle id

vehtype

Vehicle class

ego_position

Position of the ego vehicle

platoon_length

Length of the platoon

desired_platoon_speed

Desired platoon speed

maximum_speed

Maximum speed of ego vehicle

maximum_acceleration

Maximum acceleration ego vehicle

maximum_deceleration

Maximum decceleration ego vehicle

state

Truck platoon status

intruder

Presence of an intruder

split_request

Request to split

Example

This is one example on how to register a new vehicle

>>> req = SimulatorRequest()
>>> veh = Vehicle(req)
>>> req.dispatch() # This will update vehicle data

When having multiple vehicles please indicate the vehid before launching the dispatch method. This is because the vehicle object is looks for a vehicle id within the data.

Example

This is one example on how to register two vehicles

>>> req = SimulatorRequest()
>>> veh1 = Vehicle(req, vehid=0)
>>> veh2 = Vehicle(req, vehid=1)
>>> req.dispatch() # This will update vehicle data on both vehicles
cancel_join_request()[source]
confirm_platoon()[source]
desired_platoon_speed: float = 20
distance_to_leader()[source]
ego_position: int = 1
evolve(control: float)[source]

Compute evolution in time of the truck dynamics

Parameters

control (float) – [description]

gap_distance_error()[source]
intruder: bool = False
join_request()[source]
joinable()[source]
leave_platoon(platoonvehicle)[source]
maximum_acceleration: float = 2.0
maximum_deceleration: float = -2.0
maximum_speed: float = 25
platoon_length: int = 1
platoon_split()[source]
rejoin_platoon()[source]
relative_speed()[source]
split_request: bool = False
state: str = 'STANDALONE'

ensemble.component.platoonvehicleinfo module

class ensemble.component.platoonvehicleinfo.PlatoonVehicle(leader_PCM_capable=True, follower_PCM_capable=True, leader_split_request=False, follower_split_request=False, ego_distance_gap_to_leader=0, leader_id=1, follower_id=- 1, leader_speed=4.0, leader_length=5.0, gap_distance_error=0, ego_split_request=False, ego_standalone_time_gap=1, front_target_state='standalone', rear_target_state='standalone', leader_rear_target_state='standalone', follower_front_target_state='standalone', ego_speed=4.0, ego_position=0, leader_position=0, desired_gap=1, standalone_gap=1, platoon_id=1, platoon_length=1, front_id=2, intruder=False, ego_platoon_position=1, leader_platoon_position=2, maximum_platoon_length=7, platoon_desired_speed=50, platoon_desired_time_gap=2, max_connection_distance=100)[source]

Bases: ensemble.component.platoonvehicleinfo.Vehicle

This class is to store functionality of a platoon vehicle

cancel_join_request()[source]
confirm_platoon()[source]
gap_distance_to_leader()[source]
join_request()[source]
joinable()[source]
leave_platoon()[source]
platoon_split()[source]
rejoin_platoon()[source]
relative_speed()[source]
class ensemble.component.platoonvehicleinfo.Vehicle(abscissa=0, acceleration=0, distance=0, vehid=1, ordinate=0, link=1, vehtype=100, speed=0, lane=1, elevation=0)[source]

Bases: object

Vehicle object defining properties and methods required to store and compute predictions according to a vehicle model.

Since Pythagoras, we know that \(a^2 + b^2 = c^2\).

Parameters
  • abscissa (float) – x coordinate [m],

  • acceleration (float) – Acceleration [m/s2],

  • distance (float) – Distance [m],

  • vehid (int) – Unique vehicle identifier,

  • ordinate (float) – y coorindate [m],

  • link (str) – Link name,

  • vehtype (str) – Vehicle type,

  • speed (float) – speed [m/s],

  • lane (int) – lane (from right to left),

  • elevation (float) – elevation [m],

  • dynamic (VehicleDynamic) – Vehicle dynamics (check )

  • itinerary (list) – list of ordered links in the network [list],

is_platoon_vehicle()[source]

ensemble.component.vehicle module

Vehicle Model

This module implements a vehicle model.

Vehicle model acts as an instance to trace individual vehicle data and modify vehicle behavior according to given dynamics

class ensemble.component.vehicle.Vehicle(request: ensemble.metaclass.stream.DataQuery, dynamics: ensemble.metaclass.dynamics.AbsDynamics = SampleDynamics(), **kwargs)[source]

Bases: ensemble.logic.subscriber.Subscriber

Vehicle class defined for storing data on a single vehicle:

You need a Publisher from where the vehicle is going to take data:

Parameters

request (Publisher) – Parser or object publishing data

Retunrns:

vehicle (Vehicle): A Dataclass with vehicle parameters

Variable

Description

abscissa

Current coordinate on y axis

acceleration

Current acceleration

distance

Current distance traveled on link

elevation

Current elevation

lane

Current lane

link

Current road vehicle is traveling

ordinate

Current coordinate x axis

speed

Current speed

vehid

Vehicle id

vehtype

Vehicle class

Example

This is one example on how to register a new vehicle

>>> req = SimulatorRequest()
>>> veh = Vehicle(req)
>>> req.dispatch() # This will update vehicle data

When having multiple vehicles please indicate the vehid before launching the dispatch method. This is because the vehicle object is looks for a vehicle id within the data.

Example

This is one example on how to register two vehicles

>>> req = SimulatorRequest()
>>> veh1 = Vehicle(req, vehid=0)
>>> veh2 = Vehicle(req, vehid=1)
>>> req.dispatch() # This will update vehicle data on both vehicles
property a

Return vehicle acceleration

abscissa: float = 0.0
acceleration: float = 0.0
counter = count(0)
property distance
driven: bool = False
elevation: float = 0.0
followid: int = 0
lane: int = 1
leadid: int = 0
ordinate: float = 0.0
speed: float = 25.0
property state: numpy.ndarray

Returns current state of the vehicle

Returns

[3d-array] @ k+1 [distance;speed;acceleration]

Return type

np.ndarray

property ttd

Total travel distance by a single vehicle

update()[source]

Updates data from publisher

update_no_request(**kwargs)[source]

Update vehicle data from specific keyword arguments

property v

Return vehicle speed

vehid: int = 0
vehtype: str = ''
property x

Return vehicle travelled ditance

ensemble.component.vehiclelist module

Vehicle List

This module implements a vehicle list model.

Vehicle list is a collection implementation that acts as an instance to trace individual vehicle data of several vehicles.

class ensemble.component.vehiclelist.VehicleList(request)[source]

Bases: ensemble.logic.frozen_set.SortedFrozenSet, ensemble.logic.publisher.Publisher

Class defining a set of vehicles. This class is based on a sorted frozen set and supports multiple operations in between sets. You can define a list based on a simluator request and the list will update automatically via a single method.

Parameters

request (Publisher) – Publisher of information

Example

Define a list of vehicles to trace the requests ::
>>> simrequest = SimulatorRequest()
>>> simrequest.query = one_vehicle_xml
>>> vl = VehicleList(simrequest)
>>> simrequest.query = second_vehicle_xml
>>> vl.update_list() # This updates manually

Example

Define a list of vehicles to be used manually::
>>> simrequest = SimulatorRequest()
>>> vl = VehicleList(simrequest)
>>> v1 = Vehicle(simrequest, vehid=1)
>>> v2 = Vehicle(simrequest, vehid=2)
>>> vl.update_list(optional=[v1,v2]) # Adds vehicles to the list

The list could be eventually updated as an observer but for simplicity reasons it is kept like this.

__iter__()[source]

Protocol sorting data by largest distance on link

property abscissa: pandas.core.series.Series

Returns all vehicle’s abscissa

property acceleration: pandas.core.series.Series

Returns all vehicle’s accelerations

property distance: pandas.core.series.Series

Returns all vehicle’s accelerations

distance_filter(ego: ensemble.component.vehicle.Vehicle, type: str = 'downstream', property='distance', radius: float = 100)[source]

Returns all vehicles’ downstream or

get_follower(ego: ensemble.component.vehicle.Vehicle, distance: float = 100) ensemble.component.vehicle.Vehicle[source]

Returns ego vehicle immediate follower

get_leader(ego: ensemble.component.vehicle.Vehicle, distance: float = 100) ensemble.component.vehicle.Vehicle[source]

Returns ego vehicle immediate leader

Special iterator for vehicle list by considering link ordering

property lane: pandas.core.series.Series

Returns all vehicle’s lane

property leadid: pandas.core.series.Series

Returns all leader vehicle’s vehid

Returns all vehicle’s link

property ordinate: pandas.core.series.Series

Returns all vehicle’s ordinate

pandas_print(columns: Iterable = []) pandas.core.frame.DataFrame[source]

Transforms vehicle list into a pandas for rendering purposes

Returns

Returns a table with pandas data.

Return type

df (DataFrame)

pretty_print(columns: list = []) str[source]

Summary of info

release(veh: Union[ensemble.component.vehicle.Vehicle, ensemble.component.platoon_vehicle.PlatoonVehicle])[source]

Moves a vehicle to a free list so that it is not considered in the

Parameters

r (VehType) – Vehicle object

property speed: pandas.core.series.Series

Returns all vehicle’s accelerations

update_followers()[source]

Updates all vehicles followers

update_leaders()[source]

Updates all vehicles leaders

update_list(extra: Iterable[ensemble.component.vehicle.Vehicle] = [])[source]

Update vehicle data according to an update in the request.

property vehid: pandas.core.series.Series

Returns all vehicle’s vehid

Module contents