opensbt.simulation package
Submodules
opensbt.simulation.dummy_simulation module
- class opensbt.simulation.dummy_simulation.DummySimulator[source]
Bases:
Simulator
This class implements a simplified driving simulator for two actors, where the ego and adversary move with linear velocity. The ego scans for nearby vehicles. If the distance is below some threshold the ego reduces its speed until it is 0. The ego continues driving when no adversary is visible within the threshold distance. The position of ego deviates based on some random noise.
- DETECTION_THRESH = 2
- RANDOMNESS_BIAS = 0.1
- _abc_impl = <_abc._abc_data object>
- archive = {}
- now = '06-01-2025_22-37-12'
- static simulate(list_individuals: List[Individual], variable_names: List[str], scenario_path: str, sim_time: float, time_step: float = 1, do_visualize: bool = False) List[SimulationOutput] [source]
Simulates a set of scenarios based on a list of individuals and returns the simulation outputs.
- Parameters:
list_individuals (List[Individual]) – A list of individuals representing different scenarios to be simulated.
variable_names (List[str]) – A list of variable names used in the simulation.
scenario_path (str) – The file path to the scenario configuration.
sim_time (float) – Total simulation time.
time_step (float, optional) – Time step for the simulation, by default DummySimulator.time_step.
do_visualize (bool, optional) – Whether to visualize the simulation, by default False.
- Returns:
A list of simulation outputs for each individual in the input list.
- Return type:
List[SimulationOutput]
- static simulate_single(vars: List[Individual], variable_names: List[str], filepath: str, sim_time: float, time_step: float, detection_dist=2, randomness_bias=0.1) SimulationOutput [source]
Executes single scenario in DummySimulator
- time_step = 1
- opensbt.simulation.dummy_simulation.are_actors_nearby(pos_ego, pos_others, detection_dist=3)[source]
Checks if the ego actor is within a certain distance of any actor in a list of positions
- Parameters:
pos_ego (tuple or list) – The position of the ego actor
pos_others (list) – A list of positions of other actors
detection_dist (float) – The distance within which actors are considered nearby
- Returns:
True if the ego actor is within the specified distance of any other actor, False otherwise
- Return type:
bool
- opensbt.simulation.dummy_simulation.plan_motion(starting_position, orientation, velocity, sim_time, sampling_time)[source]
Plans the motion of an ego vehicle in a linear trajectory based on initial conditions.
- Parameters:
starting_position (tuple) – The initial (x, y) position of the ego vehicle.
orientation (float) – The initial orientation (yaw) of the ego vehicle in degrees.
velocity (float) – The constant velocity of the ego vehicle.
sim_time (float) – The total simulation time.
sampling_time (float) – The time interval between each simulation step.
- Returns:
A 2D array representing the trajectory with rows as [Time, X, Y, V, Yaw].
- Return type:
np.ndarray
- opensbt.simulation.dummy_simulation.random() x in the interval [0, 1).
opensbt.simulation.simulator module
- class opensbt.simulation.simulator.SimulationOutput(**kwargs)[source]
Bases:
object
Class represents data output after execution of a simulation. An example JSON representation of a SimulationOutput instance is:
- {
“simTime”: 10, // Simulation time “times”: [0.0, 0.1, 0.2, … , 10.0 ], // Time steps; delta is not predefined “location”: {
- “ego”: [
[0.0, 0.0], [0.1, 0.1], … // x,y positions for each time step
], “adversary”: [
[10.0, 0.0], [9.9, 0.1], …
]
}, “velocity”: {
- “ego”: [
[1,1,0], [1,1,0], … // velocity vector for each time step
- “adversary”: [
[0,1,0], [0, 1, 1], …
]
}, “speed”: {
“ego”: [1.4, 1.4, … ], // magnitude of velocity vector (known as “speed”) for each time step “adversary”: [1, 1, … ]
}, “acceleration”: {
“ego”: [0.1, 0, …], “adversary”: [0.05, 0, …]
}, “yaw”: { // heading in rad for each time step
“ego”: [0.5, 0.5, …], “adversary”: [0.2, 0.2, …]
}, “collisions”: [ // actor ids with timesteps if any collisions ], “actors”: { // type of actors mapped to ids; the actor types “ego” and “adversary” have to be assigned
“ego”: “ego”, “adversary”: “adversary”, “vehicles”: [], “pedestrians”: []
}, “otherParams”: { // store custom data
“car_width” : 3, “car_length” : 5
}
}
- acceleration: Dict
- actors: Dict
- collisions: List
- location: Dict
- otherParams: Dict
- simTime: float
- speed: Dict
- times: List
- velocity: Dict
- yaw: Dict
- class opensbt.simulation.simulator.Simulator[source]
Bases:
ABC
Base class to be inherited and implemented by a concrete simulator in OpenSBT
- _abc_impl = <_abc._abc_data object>
- abstract static simulate(list_individuals: List[Individual], variable_names: List[str], scenario_path: str, sim_time: float = 10, time_step: float = 0.01, do_visualize: bool = True) List[SimulationOutput] [source]
Instantiates a list of scenarios using the scenario_path, the variable_names and variable values in list_individuals, and simulates scenarios in defined simulator.
- Parameters:
list_individuals (List[Individual]) – List of individuals. On individual corresponds to one scenario.
variable_names (List[str]) – The scenario variables.
scenario_path (str) – The path to the abstract/logical scenario.
sim_time (float, optional) – The simulation time, defaults to 10
time_step (float, optional) – The time step, defaults to 0.01
do_visualize (bool, optional) – Visualize or not simulation, defaults to True
- Returns:
Returns a list of Simulation output instances.
- Return type:
List[SimulationOutput]