opencda.core.common package

Submodules

opencda.core.common.cav_world module

class opencda.core.common.cav_world.CavWorld(apply_ml=False)

Bases: object

A customized world object to save all CDA vehicle information and shared ML models. During co-simulation, it is also used to save the sumo-carla id mapping.

Parameters:

apply_ml (bool) – Whether apply ml/dl models in this simulation, please make sure you have install torch/sklearn before setting this to True.

vehicle_id_set

A set that stores vehicle IDs.

Type:

set

_vehicle_manager_dict

A dictionary that stores vehicle managers.

Type:

dict

_platooning_dict

A dictionary that stores platooning managers.

Type:

dict

_rsu_manager_dict

A dictionary that stores RSU managers.

Type:

dict

ml_manager

The machine learning manager class.

Type:

opencda object.

destroy()
get_platoon_dict()

Return existing platoons.

get_vehicle_managers()

Return vehicle manager dictionary.

locate_vehicle_manager(loc)

Locate the vehicle manager based on the given location.

Parameters:

loc (carla.Location) – Vehicle location.

Returns:

target_vm – The vehicle manager at the give location.

Return type:

opencda object

update_platooning(platooning_manger)

Add created platooning.

Parameters:

platooning_manger (opencda object) – The platooning manager class.

update_rsu_manager(rsu_manager)

Add rsu manager.

Parameters:

rsu_manager (opencda object) – The RSU manager class.

update_sumo_vehicles(sumo2carla_ids)

Update the sumo carla mapping dict. This is only called when cosimulation is conducted.

Parameters:

sumo2carla_ids (dict) – Key is sumo id and value is carla id.

update_vehicle_manager(vehicle_manager)

Update created CAV manager to the world.

Parameters:

vehicle_manager (opencda object) – The vehicle manager class.

opencda.core.common.data_dumper module

opencda.core.common.misc module

Module with auxiliary functions.

opencda.core.common.misc.cal_distance_angle(target_location, current_location, orientation)

Calculate the vehicle current relative distance to target location.

Parameters:
  • target_location (carla.Location) – The target location.

  • current_location (carla.Location) – The current location .

  • orientation (carla.Rotation) – Orientation of the reference object.

Returns:

  • distance (float) – The measured distance from current location to target location.

  • d_angle (float)) – The measured rotation (angle) froM current location to target location.

opencda.core.common.misc.compute_distance(location_1, location_2)

Euclidean distance between 3D points.

Parameters:
  • location_1 (carla.Location) – Start point of the measurement.

  • location_2 (carla.Location) – End point of the measurement.

opencda.core.common.misc.distance_vehicle(waypoint, vehicle_transform)

Returns the 2D distance from a waypoint to a vehicle

Parameters:
  • waypoint (carla.Waypoint) – Actual waypoint.

  • vehicle_transform (carla.transform) – Transform of the target vehicle.

opencda.core.common.misc.draw_trajetory_points(world, waypoints, z=0.25, color=<carla.libcarla.Color object>, lt=5, size=0.1, arrow_size=0.1)

Draw a list of trajectory points

Parameters:
  • size (float) – Time step between updating visualized waypoint.

  • lt (int) – Number of waypoints being visualized.

  • color (carla.Color) – The trajectory color.

  • world (carla.world) – The simulation world.

  • waypoints (list) – The waypoints of the current plan.

  • z (float) – The height of the visualized waypoint.

opencda.core.common.misc.draw_waypoints(world, waypoints, z=0.5)

Draw a list of waypoints at a certain height given in z.

Parameters:
  • world (carla.world) – The simulation world.

  • waypoints (list) – List or iterable container with the waypoints to draw.

  • z (float) – Height in meters.

opencda.core.common.misc.get_acc(vehicle, meters=False)

Compute acceleration of a vehicle.

Parameters:
  • meters (bool) – Whether to use m/s^2 (True) or km/h^2 (False).

  • vehicle (carla.vehicle) – The vehicle for which speed is calculated.

Returns:

acceleration – The vehicle speed.

Return type:

float

opencda.core.common.misc.get_speed(vehicle, meters=False)

Compute speed of a vehicle in Km/h.

Parameters:
  • meters (bool) – Whether to use m/s (True) or km/h (False).

  • vehicle (carla.vehicle) – The vehicle for which speed is calculated.

Returns:

speed – The vehicle speed.

Return type:

float

opencda.core.common.misc.get_speed_sumo(sumo2carla_ids, carla_id)

Get the speed of the vehicles controlled by sumo.

Parameters:
  • sumo2carla_ids (dict) – Sumo-carla mapping dictionary.

  • carla_id (int) – Carla actor id.

Returns:

speed – The speed retrieved from the sumo server, -1 if the carla_id not found.

Return type:

float

opencda.core.common.misc.positive(num)

Return the given number if positive, else 0

opencda.core.common.misc.vector(location_1, location_2)

Returns the unit vector from location_1 to location_2.

Parameters:
  • location_1 (carla.location) – Start location of the vector.

  • location_2 (carla.location) – End location of the vector.

opencda.core.common.v2x_manager module

Communication manager for cooperation

class opencda.core.common.v2x_manager.V2XManager(cav_world, config_yaml, vid)

Bases: object

V2X Manager for platooning, cooperative perception and so on.

Parameters:
  • cav_world (opencda object) – CAV world.

  • config_yaml (dict) – The configuration dictionary of the v2x module.

  • vid (str) – The corresponding vehicle manager’s uuid.

_recieved_buffer

A buffer for receive data.

Type:

dict

cav_nearby

The dictionary that contains the cavs in the communication range.

Type:

dict

platooning_plugin

The platooning plugin for communication during platooning.

Type:

opencda object

ego_pos

Ego position.

Type:

carla.transform

ego_spd

Ego speed(km/h).

Type:

float

add_platoon_blacklist(pmid)

Add an existing platoon to current blacklist.

Parameters:

pmid (int) – The target platoon manager ID.

get_ego_pos()

Add noise and lag to the current ego position and send to other CAVs. This is for simulate noise and lagging during communication.

Returns:

processed_ego_pos – The ego position after adding noise and lagging.

Return type:

carla.Transform

get_ego_speed()

Add noise and lag to the current ego speed.

Returns:

processed_ego_speed – The ego speed after adding noise and lagging.

Return type:

float

get_platoon_front_rear()

Get the ego vehicle’s front and rear cav in the platoon

Returns:

  • front_vehicle (opencda object) – Front vehicle of the ego vehicle in the platoon.

  • rear_vehicle (opencda object) – Rear vehicle of the ego vehicle in the platoon.

get_platoon_manager()

Retrieve the platoon manager the cav belongs to and the corresponding id.

Returns:

  • platoon_object (opencda object) – The PlatoonManager object.

  • in_id (int) – The ego vehicle’s in team id.

get_platoon_status()

Retrieve the FSM status for platooning application

Returns:

status – The vehicle’s current platoon status.

Return type:

enum

in_platoon()

Check whether the vehicle is inside the platoon.

Returns:

flag – Whether this vehicle is inside a platoon.

Return type:

bool

match_platoon()

A naive way to find the best position to join a platoon.

search()

Search the CAVs nearby.

set_platoon(in_id, platooning_object=None, platooning_id=None, leader=False)

Set platooning status

Parameters:
  • platooning_object (platoon object)) – Platooning world that contains all platoon information.

  • platooning_id (int) – Platoon id the cav belongs to.

  • in_id (int) – The position in the platoon, etc. 0 represents leader and 1 represents the second position.

  • leader (boolean) – Indicate whether this cav is a leader in platoon.

set_platoon_front(vm)

Set the frontal vehicle to another vehicle

Parameters:

vm (opencda object) – The target vehicle manager.

set_platoon_rear(vm)

Set the rear vehicle to another vehicle

Parameters:

vm (opencda object) – The target vehicle manager.

set_platoon_status(status)

Set the cav to a different fsm status.

Parameters:

status (str) – fsm status.

update_info(ego_pos, ego_spd)

Update all communication plugins with current localization info.

opencda.core.common.vehicle_manager module

Module contents