Architecture
Overview
Trajectory datasets suitable for conversion into the CommonRoad format come in many different formats. Therefore, high flexibility for the conversion framework is required. We tackle this problem with a hierarchical approach, allowing customization and adaptation on each layer. On the highest level, a simple single-producer, multi-consumer scheme is introduced to split work into independent jobs (usually creating one scenario), which can be run in parallel.

A runner object drives the processing and takes care of the (optional) multiprocessing.
crdata.conversion.util.runner
WorkerRunner
dataclass
Bases: Generic[JobT]
Run a single producer-multi consumer scheme.
If only one consumer process is requested, the scheme does not use the multiprocessing library. This is useful for debugging.
Source code in crdata/conversion/util/runner.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Factory
To separate object creation logic from processing logic, the factory pattern is used. For each dataset, a factory builds the runner object considering the parameters for the conversion. Factories can be reused by splitting up the tasks of building the producer and consumer into more fine-grained tasks and overriding methods, as done in crdata.conversion.tabular.factory.TabularConverterFactory.
Tabular API
Since many trajectory datasets come in the form of tabular data or can be easily brought into a tabular form, we create an API specifically designed to make the conversion of these datasets as simple as possible. The main idea is to bring the dataset into a form consisting of:
- A table of dynamic obstacle states,
- A table of static information about obstacles (e.g., obstacle shape and type),
- A static scene environment represented as a scenario without any dynamic obstacles.

To convert a new tabular dataset, only an iterator providing time windows of the dynamic obstacle information (1. and 2.) and a meta scenario creator need to be implemented. Practically speaking, this is fulfilled by implementing the corresponding interfaces interface.IRecordingGenerator and interface.IMetaScenarioCreator.
@dataclass
class MyRecordingMeta:
# Store metadata, e.g., to select the map corresponding to the recording.
recording_meta: Dict[str, Any]
@dataclass
class MyMetaScenarioCreator(IMetaScenarioCreator[MyRecordingMeta]):
map_dir: Path
...
def __call__(self, window: Window, window_meta: MyRecordingMeta) -> Scenario:
# Read map from file or cache
return self.open_map(self.map_dir)
@dataclass
class MyRecordingGenerator(IRecordingGenerator[MyRecordingMeta]):
data_path: Path
...
def __iter__(self) -> Iterable[Tuple[Window, MyRecordingMeta]]:
# Read dynamic obstacle data from files
yield Window(
vehicle_tracks[["x", "y", "velocity", "orientation", "acceleration"]],
tracks_meta[["width", "length", "obstacle_type"]],
dt
), MyRecordingMeta(recording_meta_data)
The base classes are generic to allow passing a WindowMeta object. This object tells the MetaScenarioCreator
which meta scenario to create.
Finally, building the converter is achieved by creating a corresponding factory inheriting from
interface.TabularConverterFactory, instantiating the previously created classes.
class MyConverterFactory(TabularConverterFactory, metaclass=ABCMeta):
input_dir: Path
...
def build_recording_generator(self) -> MyRecordingCreator:
return MyRecordingGenerator(self.input_dir)
def build_meta_scenario_creator(self) -> MyMetaScenarioGenerator:
return MyMetaScenarioCreator(
self.input_dir.parent / "DEU_Map-1.xml"
)