sumocr.interface package
Submodules
sumocr.interface.ego_vehicle module
- class sumocr.interface.ego_vehicle.EgoVehicle(id, initial_state, delta_steps, width=2.0, length=5.0, planning_problem=None)[source]
Bases:
object
Interface object for ego vehicle. How to use: After each simulation step, get current state with EgoVehicle.current_state() and set planned trajectory with EgoVehicle.set_planned_trajectory(planned_trajectory).
- add_state(state)[source]
Adds a state to the current state dictionary.
- Parameters:
state (
State
) – the state to be added- Return type:
None
- property current_state: State
Returns the current state.
- property current_time_step: int
Returns current time step.
- property driven_trajectory: TrajectoryPrediction
Returns trajectory prediction object for driven trajectory (mainly for plotting)
- get_dynamic_obstacle(time_step=None)[source]
If time step is None, adds complete driven trajectory and returns the dynamic obstacles. If time step is int: starts from given step and adds planned trajectory and returns the dynamic obstacles.
- Parameters:
time_step (
Optional
[int
]) – initial time step of vehicle- Return type:
DynamicObstacle
- Returns:
DynamicObstacle object of the ego vehicle.
- get_planned_state(delta_step=0)[source]
Returns the planned state.
- Parameters:
delta_step (
int
) – get planned state after delta steps
- property get_planned_trajectory: List[State]
Gets planned trajectory according to the current time step
- get_state_at_timestep(time_step)[source]
Returns the state according to the given time step.
- Parameters:
time_step (
int
) – the state is returned according to this time step.- Return type:
State
- property goal: GoalRegion
Returns the goal of the planning problem.
- property initial_state: State
Returns the initial state of the ego vehicle.
- property length: float
Returns the length of the ego vehicle.
- property pp_id: int | None
- Returns:
associated planning problem id
- set_planned_trajectory(planned_state_list)[source]
Sets planned trajectory beginning with current time step.
- Parameters:
planned_state_list (
List
[State
]) – the planned trajectory- Return type:
None
- property width: float
Returns the width of the ego vehicle.
sumocr.interface.id_mapper module
- class sumocr.interface.id_mapper.IdDomain(value)[source]
Bases:
Enum
Different seperate domains under which IDs can be registered, such that, duplicate SUMO IDs are possible, as long as they reside in different domains.
- EGO_VEHICLE = 'egoVehicle'
- OBSTACLE_VEHICLE = 'obstacleVehicle'
- PEDESTRIAN = 'pedestrian'
- TRAFFIC_LIGHT = 'trafficLight'
- VEHICLE = 'vehicle'
- class sumocr.interface.id_mapper.IdMapper[source]
Bases:
object
IdMapper bi-directionally maps Ids between CommonRoad and
- cr2sumo(cr_id, domain)[source]
Retrive the SumoId that is associated with the given cr_id from the given domain.
- Return type:
Optional
[str
]- Returns:
The associated SumoId, or None if no SumoId could be found
- has_cr2sumo(cr_id, domain)[source]
Check whether the given cr_id has a sumo_id associated in the given domain
- Return type:
bool
- has_sumo2cr(sumo_id, domain)[source]
Check whether the given sumo_id is already mapped to a CommonRoadId in the given domain.
- Return type:
bool
- insert_mapping(sumo_id, cr_id, domain)[source]
Map the provided sumo_id and cr_id together for the given domain. No checks are performed, to verify the validatity of the mapping.
- Return type:
None
sumocr.interface.params module
sumocr.interface.sumo_simulation module
- class sumocr.interface.sumo_simulation.SumoSimulation(simulation_backend=None)[source]
Bases:
object
Class for interfacing between the SUMO simulation and CommonRoad.
- check_ego_collisions(raise_error=True)[source]
Checks if the ego vehicle is colliding in the current time step of the simulation. :type raise_error: :param raise_error: raise EgoCollisionError, other return False :return: False if collision occurs, True otherwise
- check_lanelets_future_change(current_state, planned_traj)[source]
Checks the lanelet changes of the ego vehicle in the future time_window.
- Parameters:
lanelet_network – object of the lanelet network
time_window – the time of the window to check the lanelet change
traj_index – index of the planner output corresponding to the current time step
- Return type:
Tuple
[str
,int
]- Returns:
lc_status, lc_duration: lc_status is the status of the lanelet change in the next time_window; lc_duration is the unit of time steps (using sumo dt)
- commonroad_scenario_at_time_step(time_step, add_ego=False, start_0=True)[source]
Creates and returns a commonroad scenario at the given time_step. Initial time_step=0 for all obstacles.
- Parameters:
time_step (
int
) – the scenario will be created according this time step.add_ego – whether to add ego vehicles to the scenario.
start_0 – if set to true, initial time step of vehicles is 0, otherwise, the current time step
- Return type:
Scenario
- commonroad_scenarios_all_time_steps()[source]
Creates and returns a commonroad scenario with all the dynamic obstacles. :param lanelet_network: :rtype:
Scenario
:return: list of cr scenarios, list of cr scenarios with ego, list of planning problem sets)
- property current_time_step: int
- Returns:
current time step of interface
- property ego_vehicles: Dict[int, EgoVehicle]
Returns the ego vehicles of the current simulation.
- get_ego_obstacles(time_step=None)[source]
Get list of ego vehicles converted to Dynamic obstacles :type time_step:
Optional
[int
] :param time_step: initial time step, if None, get complete driven trajectory :rtype:List
[DynamicObstacle
] :return:
- init_ego_vehicles_from_planning_problem(planning_problem_set)[source]
Initializes the ego vehicles according to planning problem set.
- Parameters:
planning_problem_set (
PlanningProblemSet
) – The planning problem set which defines the ego vehicles.- Return type:
None
- initialize(conf, scenario_wrapper, planning_problem_set=None)[source]
Reads scenario files, starts traci simulation, initializes vehicles, conducts pre-simulation.
- Parameters:
conf (
DefaultConfig
) – configuration object. If None, use default configuration.scenario_wrapper (
ScenarioWrapper
) – handles all files required for simulation. If None it is initialized with filesplanning_problem_set (
Optional
[PlanningProblemSet
]) – initialize initial state of ego vehicles
- Return type:
None
folder conf.scenarios_path + conf.scenario_name
(if None, use planning_problem_set from self.scenario)
- is_in_field_of_view(position, veh_id)[source]
Returns True if the position is in the FOV of any ego vehicle. :type position:
ndarray
:param position: position of other vehicle :return:
- property scenarios: ScenarioWrapper
sumocr.interface.sumo_simulation_backend module
- class sumocr.interface.sumo_simulation_backend.GuiSumoSimulationBackend(config, sumo_config_file, sumo_binary_path=None)[source]
Bases:
TraciApiSumoSimulationBackend
Provides an interface to perform sumo simulation with a GUI by utilizing traci.
- class sumocr.interface.sumo_simulation_backend.HeadlessSumoSimulationBackend(config, sumo_config_file, sumo_binary_path=None)[source]
Bases:
TraciApiSumoSimulationBackend
Provides an interface to perform sumo simulation without a GUI by utilizing libsumo.
- class sumocr.interface.sumo_simulation_backend.SumoSimulationBackend(config, sumo_config_file)[source]
Bases:
ABC
SumoSimulationBackend provides an interface for interacting with a more concrete sumo simulator (e.g. based on libsumo).
- abstract property edge_domain: EdgeDomain | edge
- abstract property lane_domain: LaneDomain | lane
- abstract property person_domain: PersonDomain | person
- abstract property route_domain: RouteDomain | route
- abstract property simulation_domain: SimulationDomain | simulation
- abstract property traffic_light_domain: TrafficLightDomain | trafficlight
- abstract property vehicle_domain: VehicleDomain | vehicle
- abstract property vehicle_type_domain: VehicleTypeDomain | vehicletype
- class sumocr.interface.sumo_simulation_backend.SumoSimulationBackendConfiguration(dt, delta_steps, lateral_resolution, random_seed=None)[source]
Bases:
object
-
delta_steps:
int
-
dt:
int
-
lateral_resolution:
float
-
random_seed:
Optional
[float
] = None
-
delta_steps:
- class sumocr.interface.sumo_simulation_backend.TraciApiSumoSimulationBackend(config, sumo_config_file, sumo_interface, sumo_binary_path)[source]
Bases:
SumoSimulationBackend
This is an abstract interface for libraries that support the traci API (libsumo and traci).
- property edge_domain
- property lane_domain
- property person_domain
- property route_domain
- property simulation_domain
- property traffic_light_domain
- property vehicle_domain
- property vehicle_type_domain
sumocr.interface.sumo_simulation_interface module
sumocr.interface.util module
- exception sumocr.interface.util.EgoCollisionError(time_step=None)[source]
Bases:
Exception
Exception raised if the ego vehicle collides with another vehicle
- exception sumocr.interface.util.NetError(len)[source]
Bases:
Exception
Exception raised if there is no net-file or multiple net-files.
- exception sumocr.interface.util.RouteError[source]
Bases:
Exception
Exception raised if there is no route-file.
- class sumocr.interface.util.SumoSignalIndices(value)[source]
Bases:
IntEnum
All interpretations with their respective bit indices ref.: https://sumo.dlr.de/docs/TraCI/Vehicle_Signalling.html
- VEH_SIGNAL_BACKDRIVE = 7
- VEH_SIGNAL_BLINKER_EMERGENCY = 2
- VEH_SIGNAL_BLINKER_LEFT = 1
- VEH_SIGNAL_BLINKER_RIGHT = 0
- VEH_SIGNAL_BRAKELIGHT = 3
- VEH_SIGNAL_DOOR_OPEN_LEFT = 9
- VEH_SIGNAL_DOOR_OPEN_RIGHT = 10
- VEH_SIGNAL_EMERGENCY_BLUE = 11
- VEH_SIGNAL_EMERGENCY_RED = 12
- VEH_SIGNAL_EMERGENCY_YELLOW = 13
- VEH_SIGNAL_FOGLIGHT = 5
- VEH_SIGNAL_FRONTLIGHT = 4
- VEH_SIGNAL_HIGHBEAM = 6
- VEH_SIGNAL_WIPER = 8
- sumocr.interface.util.cr_obstacle_type_to_sumo_vehicle_class(obstacle_type)[source]
- Return type:
str
- sumocr.interface.util.get_route_files(config_file)[source]
Returns net-file and route-files specified in the config file.
- Parameters:
config_file – SUMO config file (.sumocfg)
- Return type:
List
[str
]