Syntax Guide
This page summarizes the syntax of Scenic (excluding syntax inherited from Python). For more details, click the links for individual language constructs to go to the corresponding section of the Language Reference.
Primitive Data Types
expressing truth values |
|
representing distances, angles, etc. as floating-point numbers |
|
representing positions and offsets in space |
|
representing orientations in space |
|
associating an orientation (i.e. a heading) to each point in space |
|
representing sets of points in space |
Distributions
uniformly-distributed real number in the interval |
|
uniformly-distributed integer in the (fixed) interval |
|
normal distribution with the given mean and standard deviation |
|
normal distribution truncated to the given window |
|
uniform over a finite set of values |
|
discrete with given values and weights |
|
uniformly-distributed Point in a region |
Statements
Compound Statements
Syntax |
Meaning |
---|---|
Defines a Scenic class. |
|
Defines a dynamic behavior. |
|
Defines a monitor. |
|
Defines a modular scenario. |
|
Run code with interrupts inside a dynamic behavior or modular scenario. |
Simple Statements
Syntax |
Meaning |
---|---|
Select the world model. |
|
Import a Scenic or Python module. |
|
Define global parameters of the scenario. |
|
Define a hard requirement. |
|
Define a soft requirement. |
|
Define a dynamic hard requirement. |
|
Define a termination condition. |
|
Set the scenario to terminate after a given amount of time. |
|
Enable mutation of the given list of objects. |
|
Save a value at every time step or only at the start/end of the simulation. |
Dynamic Statements
These statements can only be used inside a dynamic behavior, monitor, or compose
block of a modular scenario.
Syntax |
Meaning |
---|---|
Take the action(s) specified. |
|
Take no actions this time step. |
|
Immediately end the scenario. |
|
Run one or more sub-behaviors/sub-scenarios until they complete. |
|
Run sub-behaviors/scenarios until they complete or a condition is met. |
|
Run sub-behaviors/scenarios for (at most) a specified period of time. |
|
Run one choice of sub-behavior/scenario whose preconditions are satisfied. |
|
Run several sub-behaviors/scenarios in a random order, satisfying preconditions. |
|
Break out of the current |
|
Override properties of an object for the duration of the current scenario. |
Objects
The syntax class specifier, ...
creates an instance of a Scenic class.
The Scenic class Point provides the basic position properties in the first table below; its subclass OrientedPoint adds the orientation properties in the second table. Finally, the class Object, which represents physical objects and is the default superclass of user-defined Scenic classes, adds the properties in the third table. See the Objects and Classes Reference for details.
Property |
Default |
Meaning |
position 1 |
(0, 0) |
position in global coordinates |
viewDistance |
50 |
distance for the ‘can see’ operator |
mutationScale |
0 |
overall scale of mutations |
positionStdDev |
1 |
mutation standard deviation for |
Properties added by OrientedPoint:
Property |
Default |
Meaning |
heading 1 |
0 |
heading in global coordinates |
viewAngle |
360 degrees |
angle for the ‘can see’ operator |
headingStdDev |
5 degrees |
mutation standard deviation for |
Properties added by Object:
Property |
Default |
Meaning |
width |
1 |
width of bounding box (X axis) |
length |
1 |
length of bounding box (Y axis) |
speed 1 |
0 |
initial speed (later, instantaneous speed) |
velocity 1 |
from |
initial velocity (later, instantaneous velocity) |
angularSpeed 1 |
0 |
angular speed (change in heading/time) |
behavior |
dynamic behavior, if any |
|
allowCollisions |
whether collisions are allowed |
|
requireVisible |
whether object must be visible from ego |
|
regionContainedIn |
Region the object must lie within |
|
cameraOffset |
(0, 0) |
position of camera for ‘can see’ |
Specifiers
The with property value
specifier can specify any property, including new properties not built into Scenic.
Additional specifiers for the position
and heading
properties are listed below.
Specifier for |
Meaning |
---|---|
Positions the object at the given global coordinates |
|
Positions the object at the given coordinates in the local coordinate system of ego (which must already be defined) |
|
Positions the object at the given coordinates, in a local coordinate system centered at ego and oriented along the given direction |
|
Positions the object further to the left/right by the given scalar distance |
|
As above, except placing the object ahead of or behind the given position |
|
Positions the object at coordinates given by the second vector, centered at the first vector and oriented along the line of sight from the third vector/ego |
|
Positions the object uniformly at random in the visible region of the ego, or of the given Point/OrientedPoint if given |
|
Positions the object uniformly at random in the non-visible region of the ego, or of the given Point/OrientedPoint if given |
Specifier for |
Meaning |
---|---|
Positions the object uniformly at random in the given Region |
|
Positions the object to the left/right of the given OrientedPoint, depending on the object’s width |
|
As above, except positioning the object ahead of or behind the given OrientedPoint, thereby depending on length |
|
Position by following the given vector field for the given distance starting from ego or the given vector |
Specifier for |
Meaning |
---|---|
Orients the object along the given heading in global coordinates |
|
Orients the object along the given vector field at the object’s position |
|
Orients the object toward/away from the given position (thereby depending on the object’s position) |
|
Orients the object so that it has the given heading with respect to the line of sight from ego (or the given vector) |
Operators
Scalar Operators |
Meaning |
---|---|
The relative heading of the given heading with respect to ego (or the |
|
The apparent heading of the OrientedPoint, with respect to the line of sight from ego (or the given vector) |
|
The distance to the given position from ego (or the |
|
The heading to the given position from ego (or the |
Boolean Operators |
Meaning |
---|---|
Whether or not a position or Object is visible from a Point or OrientedPoint. |
|
Whether a position or Object lies in the region |
Heading Operators |
Meaning |
---|---|
The given heading, interpreted as being in degrees |
|
The heading specified by the vector field at the given position |
|
The first direction, interpreted as an offset relative to the second direction |
Vector Operators |
Meaning |
---|---|
The first vector, interpreted as an offset relative to the second vector (or vice versa) |
|
The second vector, interpreted in a local coordinate system centered at the first vector and oriented along the given direction |
Region Operators |
Meaning |
---|---|
The part of the given region visible from ego |
|
The part of the given region not visible from ego |
OrientedPoint Operators |
Meaning |
---|---|
The given vector, interpreted in the local coordinate system of the OrientedPoint |
|
Equivalent to |
|
The midpoint of the corresponding edge of the bounding box of the Object, oriented along its heading |
|
The corresponding corner of the Object’s bounding box, also oriented along its heading |
Built in Functions
Function |
Description |
---|---|
Various Python functions including |
|
Filter a possibly-random list (allowing limited randomized control flow). |
|
Sample a new value from a distribution. |
|
Convert a relative path to an absolute path, based on the current directory. |
|
Like |
|
Get the the current simulation object. |