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.
- 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
- ml_manager¶
The machine learning manager class.
- Type
opencda object.
- 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_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¶
Dumping sensor data.
- class opencda.core.common.data_dumper.DataDumper(perception_manager, localization_manager, vehicle_id, save_time)¶
Bases:
object
Data dumper class to save data in local disk.
- Parameters
perception_manager (opencda object) – The perception manager contains rgb camera data and lidar data.
localization_manager (opencda object) – The localization manager contains gnss and imu data.
vehicle_id (int) – The carla.Vehicle id.
save_time (str) – The timestamp at the beginning of the simulation.
- rgb_camera¶
A list of opencda.CameraSensor that containing all rgb sensor data of the managed vehicle.
- Type
list
- lidar ; opencda object
The lidar manager from perception manager.
- save_parent_folder¶
The parent folder to save all data related to a specific vehicle.
- Type
str
- count¶
Used to count how many steps have been executed. We dump data every 10 steps.
- Type
int
- run_step(perception_manager, localization_manager)¶
Dump data at running time.
- Parameters
perception_manager (opencda object) – OpenCDA perception manager.
localization_manager (opencda object) – OpenCDA localization manager.
- save_lidar_points()¶
Save 3D lidar points to disk.
- save_rgb_image()¶
Save camera rgb images to disk.
- save_yaml_file(perception_manager, localization_manager)¶
Save objects positions/spped, true ego position, predicted ego position, sensor transformations.
- Parameters
perception_manager (opencda object) – OpenCDA perception manager.
localization_manager (opencda object) – OpenCDA localization manager.
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.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)¶
Bases:
object
V2X Manager for platooning, cooperative perception and so on.
Parameters -cav_world : opencda object
CAV world.
- -config_yamldict
The configuration dictionary of the v2x module.
Attributes -_recieved_buffer : dict
A buffer for receive data.
- -platooning_pluginopencda object
The platooning plugin for communication during platooning.
- add_platoon_blacklist(pmid)¶
Add an existing platoon to current blacklist.
- Parameters
pmid (-) – The target platoon manager ID.
- get_platoon_front_rear()¶
Get the ego vehicle’s front and rear cav in the platoon
- get_platoon_manager()¶
Retrieve the platoon manager the cav belongs to and the corresponding id :return:
- get_platoon_status()¶
Retrive the FSM status for platooning application
- in_platoon()¶
Check whether the vehicle is inside the platoon.
- Parameters
detection result (-) – Flag indication whether in a platoon.
- match_platoon()¶
A naive way to find the best position to join a platoon.
- set_platoon(in_id, platooning_object=None, platooning_id=None, leader=False)¶
Set platooning status
Args -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
- Args
vm (vehicle manager):The target vehicle manager.
- set_platoon_rear(vm)¶
Set the rear vehicle to another vehicle
- Parameters
vm (-) – The target vehicle manager.
- set_platoon_status(status)¶
Set the cav to a different fsm status.
- Args
-status (string): fsm status.
- update_info(ego_pos, ego_spd)¶
Update all communication plugins with current localization info.
opencda.core.common.vehicle_manager module¶
Basic class of CAV
- class opencda.core.common.vehicle_manager.VehicleManager(vehicle, config_yaml, application, carla_map, cav_world, current_time='', data_dumping=False)¶
Bases:
object
A class manager to embed different modules with vehicle together.
- Parameters
vehicle (carla.Vehicle) – The carla.Vehicle. We need this class to spawn our gnss and imu sensor.
config_yaml (dict) – The configuration dictionary of the localization module.
application (list) – The application category, currently support:[‘single’,’platoon’].
carla_map (carla.Map) – The CARLA simulation map.
cav_world (opencda object) – CAV World.
current_time (str) – Timestamp of the simulation beginning.
data_dumping (bool) – Indicates whether to dump sensor data during simulation.
- v2x_manager¶
The current V2X manager.
- Type
opencda object
- localizer¶
The current localization manager.
- Type
opencda object
- perception_manager¶
The current V2X perception manager.
- Type
opencda object
- agent¶
- The current carla agent that handles the basic behavior
planning of ego vehicle.
- Type
opencda object
- controller¶
The current control manager.
- Type
opencda object
- data_dumper¶
Used for dumping sensor data.
- Type
opencda object
- destroy()¶
Destroy the actor vehicle
- run_step(target_speed=None)¶
Execute one step of navigation.
- set_destination(start_location, end_location, clean=False, end_reset=True)¶
Set global route.
- Parameters
start_location (carla.location) – The CAV start location.
end_location (carla.location) – The CAV destination.
clean (bool) – Indicator of whether clean waypoint queue.
end_reset (bool) – Indicator of whether reset the end location.
- update_info()¶
Call perception and localization module to retrieve surrounding info an ego position.