Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ it to the replay, but this greatly increases the size of the encoded simulation.
can return to one later for further analysis), but it is not guaranteed to be
compatible across major versions of Scenic.

.. _xosc_export:

OpenScenarioXML Export
----------------------

Scenic provides experimental support for exporting completed simulations via `toOpenScenario`.
Comment thread
Eric-Vin marked this conversation as resolved.
This function currently only supports cars and pedestrians, and may be subject to breaking changes
in the future.

.. seealso:: If you get exceptions or unexpected behavior when using the API, Scenic provides various debugging features: see :ref:`debugging`.

.. rubric:: Footnotes
Expand Down
5 changes: 4 additions & 1 deletion docs/simulators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ See the individual entries for details on each interface's capabilities and how
While Scenic aims to support multiple Python versions, some simulators may have more limited compatibility.
Be sure to check the documentation of each simulator to confirm which Python versions are supported.

.. note::
Scenic also supports outputing data in formats that may be imported into other simulators and tools (e.g. :ref:`xosc_export`).
For more details, see :ref:`serialization`.

.. contents:: List of Simulators
:local:

Expand Down Expand Up @@ -163,7 +167,6 @@ This interface is part of the VerifAI toolkit; documentation and examples can be

.. _VerifAI repository: https://github.com/BerkeleyLearnVerify/VerifAI


Deprecated
==========

Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ metadrive = [
"metadrive-simulator >= 0.4.3",
"sumolib >= 1.21.0",
]
openscenario = [
"scenariogeneration"
]
test = [ # minimum dependencies for running tests (used for tox virtualenvs)
"pytest >= 7.0.0",
"pytest-cov >= 3.0.0",
Expand All @@ -68,6 +71,7 @@ test = [ # minimum dependencies for running tests (used for tox virtualenvs)
test-full = [ # like 'test' but adds dependencies for optional features
"scenic[test]", # all dependencies from 'test' extra above
"scenic[guideways]", # for running guideways modules
"scenic[openscenario]",
"astor >= 0.8.1",
'carla >= 0.9.12; python_version <= "3.12" and (platform_system == "Linux" or platform_system == "Windows")',
"dill",
Expand Down
2 changes: 2 additions & 0 deletions src/scenic/core/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import hashlib
import io
import math
import os
import pickle
import struct
import types
import warnings

from scenic.core.distributions import Samplable, needsSampling
from scenic.core.utils import DefaultIdentityDict
Expand Down
25 changes: 21 additions & 4 deletions src/scenic/core/simulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,11 +807,28 @@ def currentState(self):
"""Return the current state of the simulation.

The definition of 'state' is up to the simulator; the 'state' is simply saved
at each time step to define the 'trajectory' of the simulation.

The default implementation returns a tuple of the positions of all objects.
at each time step to define the 'trajectory' of the simulation. Changing this
method is however discouraged, unless one is adding additional attributes to
the returned ``SimulationState`` object.

The default implementation returns a custom ``SimulationState`` object, which is a tuple
of positions of all objects (for backwards compatibility) and also has two attributes:
``positions`` and ``orientations``, which are themselves tuples of the positions and
orientations of all objects.
"""
return tuple(obj.position for obj in self.objects)

class SimulationState(tuple):
Comment thread
Eric-Vin marked this conversation as resolved.
def __new__(cls, positions, orientations):
return super().__new__(cls, positions)

def __init__(self, positions, orientations):
self.positions = positions
self.orientations = orientations

positions = tuple(obj.position for obj in self.objects)
orientation = tuple(obj.orientation for obj in self.objects)

return SimulationState(positions, orientation)

@property
def currentRealTime(self):
Expand Down
37 changes: 37 additions & 0 deletions src/scenic/domains/driving/model.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class DrivingObject:
def isVehicle(self):
return False

@property
def isPedestrian(self):
return False

@property
def isCar(self):
return False
Expand Down Expand Up @@ -282,6 +286,25 @@ class Vehicle(DrivingObject):
color (:obj:`Color` or RGB tuple): Color of the vehicle. The default value is a
distribution derived from car color popularity statistics; see
:obj:`Color.defaultCarColor`.
wheelbase: The distance between the front and rear axles of the vehicle. Default value is 0.6
times the length of the vehicle.
maxSteeringAngle: The maximum steering angle of the vehicle. The full steering range would be
two times this value, going from (-maxSteeringAngle, maxSteeringAngle). Default value
35 degrees.
wheelDiameter: The diameter of the *entire* wheel (including the tire). Default value is 0.7 meters.
trackWidth: Distance between the vehicle's wheels when pointed straight ahead. Default value
is 0.85 times the width of the vehicle.
groundClearance: The distance between the bottom of the vehicle's chassis and the ground. Default
value is half the wheel diameter.
maxSpeed: The maximum rated speed of the vehicle. Default value is 45 meters per second (~100 mph).
This value is not enforced by Scenic and is provided simply for other tools to reference (e.g.
exporting to OpenScenarioXML).
maxAcceleration: The maximum rated acceleration of the vehicle. Default value is 5 meters per second^2.
This value is not enforced by Scenic and is provided simply for other tools to reference (e.g.
exporting to OpenScenarioXML).
maxDeceleration: The maximum rated deceleration of the vehicle. Default value is 10 meters per second^2.
This value is not enforced by Scenic and is provided simply for other tools to reference (e.g.
exporting to OpenScenarioXML).
"""
regionContainedIn: roadOrShoulder
position: new Point on road
Expand All @@ -291,6 +314,14 @@ class Vehicle(DrivingObject):
width: 2
length: 4.5
color: Color.defaultCarColor()
wheelbase: 0.6*self.length
maxSteeringAngle: 35 deg
wheelDiameter: 0.7
trackWidth: 0.85*self.width
groundClearance: 0.5*self.wheelDiameter
maxSpeed: 45
maxAcceleration: 5
maxDeceleration: 10

@property
def isVehicle(self):
Expand All @@ -317,6 +348,7 @@ class Pedestrian(DrivingObject):
length: The default length is 0.75 m.
color: The default color is turquoise. Pedestrian colors are not necessarily
used by simulators, but do appear in the debugging diagram.
mass: Default value is 65 kg.
"""
regionContainedIn: network.walkableRegion
position: new Point on network.walkableRegion
Expand All @@ -325,6 +357,11 @@ class Pedestrian(DrivingObject):
width: 0.75
length: 0.75
color: [0, 0.5, 1]
mass: 65

@property
def isPedestrian(self):
return True

## Stub sensor implementations

Expand Down
Loading
Loading