interface
This module provides an interface between a local Sumo installation and an ego vehicle steered by a motion planner.
Sumo Simulation
SumoSimulation class
- class sumocr.interface.sumo_simulation.SumoSimulation[source]
Class for interfacing between the SUMO simulation and CommonRoad.
- 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 files folder conf.scenarios_path + conf.scenario_nameplanning_problem_set (
Optional[PlanningProblemSet]) – initialize initial state of ego vehicles
(if None, use planning_problem_set from self.scenario)
- Return type
None
- 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
- property ego_vehicles: Dict[int, sumocr.interface.ego_vehicle.EgoVehicle]
Returns the ego vehicles of the current simulation.
- Return type
Dict[int,EgoVehicle]
- property current_time_step: int
- Return type
int- Returns
current time step of interface
- 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)
- simulate_step()[source]
Executes next simulation step (consisting of delta_steps sub-steps with dt_sumo=dt/delta_steps) in SUMO
- Return type
None
- check_ego_collisions(raise_error=True)[source]
Checks if the ego vehicle is colliding in the current time step of the simulation. :param raise_error: raise EgoCollisionError, other return False :return: False if collision occurs, True otherwise
- 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:
- 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)
Ego Vehicle
EgoVehicle class
- class sumocr.interface.ego_vehicle.EgoVehicle(id, initial_state, delta_steps, width=2.0, length=5.0, planning_problem=None)[source]
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).
- property pp_id: int
- Return type
int- 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 get_planned_trajectory: List[commonroad.scenario.trajectory.State]
Gets planned trajectory according to the current time step
- Return type
List[State]
- 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
- 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 current_state: commonroad.scenario.trajectory.State
Returns the current state.
- Return type
State
- property current_time_step: int
Returns current time step.
- Return type
int
- property goal: commonroad.planning.goal.GoalRegion
Returns the goal of the planning problem.
- Return type
GoalRegion
- add_state(state)[source]
Adds a state to the current state dictionary.
- Parameters
state (
State) – the state to be added- Return type
None
- property driven_trajectory: commonroad.prediction.prediction.TrajectoryPrediction
Returns trajectory prediction object for driven trajectory (mainly for plotting)
- Return type
TrajectoryPrediction
- property width: float
Returns the width of the ego vehicle.
- Return type
float
- property length: float
Returns the length of the ego vehicle.
- Return type
float
- property initial_state: commonroad.scenario.trajectory.State
Returns the initial state of the ego vehicle.
- Return type
State
Helper Functions
- 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]
- sumocr.interface.util.initialize_id_dicts(id_convention)[source]
Creates empty nested dict structure for sumo2cr and cr2sumo dicts from id_convention and returns them.
- Parameters
id_convention (
dict) – dict with mapping from object type to id start number- Return type
Tuple[dict,dict]
- sumocr.interface.util.generate_cr_id(type, sumo_id, sumo_prefix, ids_sumo2cr, max_cr_id)[source]
Generates a new commonroad ID without adding it to any ID dictionary.
- Parameters
type (
str) – one of the keys in params.id_convention; the type defines the first digit of the cr_idsumo_id (
str) – id in sumo simulationids_sumo2cr (
dict) – dictionary of ids in sumo2cr
- Return type
int