scenic.domains.driving.model

Scenic world model for scenarios using the driving domain.

Imports actions and behaviors for dynamic agents from scenic.domains.driving.actions and scenic.domains.driving.behaviors.

The map file to use for the scenario must be specified before importing this model by defining the global parameter map. This path is passed to the Network.fromFile function to create a Network object representing the road network. Extra options may be passed to the function by defining the global parameter map_options, which should be a dictionary of keyword arguments. For example, we could write:

param map = localPath('mymap.xodr')
param map_options = { 'tolerance': 0.1 }
model scenic.domains.driving.model

If you are writing a generic scenario that supports multiple maps, you may leave the map parameter undefined; then running the scenario will produce an error unless the user uses the --param command-line option to specify the map.

The use2DMap global parameter determines whether or not maps are generated in 2D. Currently 3D maps are not supported, but are under development. By default, this parameter is False (so that future versions of Scenic will automatically use 3D maps), unless 2D Compatibility Mode is enabled, in which case the default is True. The parameter can be manually set to True to ensure 2D maps are used even if the scenario is not compiled in 2D compatibility mode.

Note

If you are using a simulator, you may have to also define simulator-specific global parameters to tell the simulator which world to load. For example, our LGSVL interface uses a parameter lgsvl_map to specify the name of the Unity scene. See the documentation of the simulator interfaces for details.

Summary of Module Members

Module Attributes

network

The road network being used for the scenario, as a Network object.

road

The union of all drivable roads, including intersections but not shoulders or parking lanes.

curb

The union of all curbs.

sidewalk

The union of all sidewalks.

shoulder

The union of all shoulders, including parking lanes.

roadOrShoulder

All drivable areas, including both ordinary roads and shoulders.

intersection

The union of all intersections.

roadDirection

A VectorField representing the nominal traffic direction at a given point.

Functions

is2DMode

withinDistanceToAnyCars

returns boolean

withinDistanceToAnyObjs

checks whether there exists any obj (1) in front of the vehicle, (2) within thresholdDistance

withinDistanceToObjsInLane

checks whether there exists any obj (1) in front of the vehicle, (2) on the same lane, (3) within thresholdDistance

Classes

Car

A car.

DrivingObject

Abstract class for objects in a road network.

NPCCar

Car for which accurate physics is not required.

Pedestrian

A pedestrian.

Vehicle

Vehicles which drive, such as cars.

Member Details

network: Network

The road network being used for the scenario, as a Network object.

road: Region

The union of all drivable roads, including intersections but not shoulders or parking lanes.

curb: Region

The union of all curbs.

sidewalk: Region = <EmptyRegion nowhere>

The union of all sidewalks.

shoulder: Region = <EmptyRegion nowhere>

The union of all shoulders, including parking lanes.

roadOrShoulder: Region

All drivable areas, including both ordinary roads and shoulders.

intersection: Region = <EmptyRegion nowhere>

The union of all intersections.

roadDirection: VectorField

A VectorField representing the nominal traffic direction at a given point.

Inside intersections or anywhere else where there can be multiple nominal traffic directions, the choice is arbitrary. At such points, the function Network.nominalDirectionsAt can be used to get all nominal directions.

class DrivingObject <specifiers>[source]

Bases: Object2D

Abstract class for objects in a road network.

Provides convenience properties for the lane, road, intersection, etc. at the object’s current position (if any).

Also defines the elevation property as a standard way to access the Z component of an object’s position, since the Scenic built-in property position is only 2D. If elevation is set to None, the simulator is responsible for choosing an appropriate Z coordinate so that the object is on the ground, then updating the property. 2D simulators should set the property to zero.

Properties:
  • elevation (float or None; dynamic) – default None (see above).

  • requireVisible (bool) – Default value False (overriding the default from Object).

property lane: Lane

The Lane at the object’s current position.

The simulation is rejected if the object is not in a lane. (Use DrivingObject._lane to get None instead.)

property _lane: Optional[Lane]

The Lane at the object’s current position, if any.

property laneSection: LaneSection

The LaneSection at the object’s current position.

The simulation is rejected if the object is not in a lane.

property _laneSection: Optional[LaneSection]

The LaneSection at the object’s current position, if any.

property laneGroup: LaneGroup

The LaneGroup at the object’s current position.

The simulation is rejected if the object is not in a lane.

property _laneGroup: Optional[LaneGroup]

The LaneGroup at the object’s current position, if any.

property oppositeLaneGroup: LaneGroup

The LaneGroup on the other side of the road from the object.

The simulation is rejected if the object is not on a two-way road.

property road: Road

The Road at the object’s current position.

The simulation is rejected if the object is not on a road.

property _road: Optional[Road]

The Road at the object’s current position, if any.

property intersection: Intersection

The Intersection at the object’s current position.

The simulation is rejected if the object is not in an intersection.

property _intersection: Optional[Intersection]

The Intersection at the object’s current position, if any.

property crossing: PedestrianCrossing

The PedestrianCrossing at the object’s current position.

The simulation is rejected if the object is not in a crosswalk.

property _crossing: Optional[PedestrianCrossing]

The PedestrianCrossing at the object’s current position, if any.

property element: NetworkElement

The highest-level NetworkElement at the object’s current position.

See Network.elementAt for the details of how this is determined. The simulation is rejected if the object is not in any network element.

property _element: Optional[NetworkElement]

The highest-level NetworkElement at the object’s current position, if any.

distanceToClosest(type)[source]

Compute the distance to the closest object of the given type.

For example, one could write self.distanceToClosest(Car) in a behavior.

Parameters:

type (type) –

Return type:

Object2D

class Vehicle <specifiers>[source]

Bases: DrivingObject

Vehicles which drive, such as cars.

Properties:
  • position – The default position is uniformly random over the road.

  • parentOrientation – The default parentOrientation is aligned with roadDirection, plus an offset given by roadDeviation.

  • roadDeviation (float) – Relative heading with respect to the road direction at the Vehicle’s position. Used by the default value for parentOrientation.

  • regionContainedIn – The default container is roadOrShoulder.

  • viewAngle – The default view angle is 90 degrees.

  • width – The default width is 2 meters.

  • length – The default length is 4.5 meters.

  • color (Color or RGB tuple) – Color of the vehicle. The default value is a distribution derived from car color popularity statistics; see Color.defaultCarColor.

class Car <specifiers>[source]

Bases: Vehicle

A car.

class NPCCar <specifiers>[source]

Bases: Car

Car for which accurate physics is not required.

class Pedestrian <specifiers>[source]

Bases: DrivingObject

A pedestrian.

Properties:
  • position – The default position is uniformly random over sidewalks and crosswalks.

  • parentOrientation – The default parentOrientation has uniformly random yaw.

  • viewAngle – The default view angle is 90 degrees.

  • width – The default width is 0.75 m.

  • 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.

withinDistanceToAnyCars(car, thresholdDistance)[source]

returns boolean

withinDistanceToAnyObjs(vehicle, thresholdDistance)[source]

checks whether there exists any obj (1) in front of the vehicle, (2) within thresholdDistance

withinDistanceToObjsInLane(vehicle, thresholdDistance)[source]

checks whether there exists any obj (1) in front of the vehicle, (2) on the same lane, (3) within thresholdDistance