Interfacing to New Simulators¶
To interface Scenic to a new simulator, there are two steps: using the Scenic API to compile scenarios and generate scenes, and writing a Scenic library defining the virtual world provided by the simulator.
Using the Scenic API¶
Compiling a Scenic scenario is easy: just call the
scenic.scenarioFromFile function with the path to a Scenic file (there’s also a variant
scenic.scenarioFromString which works on strings).
This returns a
Scenario object representing the scenario; to sample a scene from it, call its
Scenes are represented by
Scene objects, from which you can extract the objects and their properties as well as the values of the global parameters (see the
Scene documentation for details).
Supporting dynamic scenarios requires additionally implementing a subclass of
Simulator which communicates periodically with your simulator to implement the actions taken by dynamic agents and read back the state of the simulation.
scenic.simulators.lgsvl.simulator modules for examples.
Defining a World Model¶
To make writing scenarios for your simulator easier, you should write a Scenic library specifying all the relevant information about the simulated world. This “world model” could include:
Scenic classes (subclasses of
Object) corresponding to types of objects in the simulator;
Regioncorresponding to locations of interest (e.g. one for each road);
Workspacespecifying legal locations for objects (and optionally providing methods for schematically rendering scenes);
a set of actions (subclasses of
Action) which can be taken by dynamic agents during simulations;
any other information or utility functions that might be useful in scenarios.
Then any Scenic programs for your simulator can import this world model and make use of the information within.
Each of the simulators natively supported by Scenic has a corresponding
model.scenic file containing its world model.
See the Supported Simulators page for links to the module under
scenic.simulators for each simulator, where the world model can be found.
scenic.simulators.webots.mars model is particularly simple and would be a good place to start.