Skip to content

Commit

Permalink
Improved Scenic scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
glopezdiest committed Oct 23, 2024
1 parent 6884200 commit 2616d21
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 212 deletions.
6 changes: 5 additions & 1 deletion Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
* [CARLA ScenarioRunner 0.9.5](#carla-scenariorunner-095)
* [CARLA ScenarioRunner 0.9.2](#carla-scenariorunner-092)

## Upcoming

## CARLA ScenarioRunner 0.10
* Updated the scenarios to match the limitations of CARLA 0.10. This means moving them to Town10HD_Opt and updating the blueprints to the available ones.
* Added Scenic examples to the repo, and updated the [available ones in their repo](https://github.com/BerkeleyLearnVerify/Scenic/tree/main/examples/carla/Carla_Challenge) to match the new release.

* Improvements to the CarlaDataProvider:
- Added `spawn_actor` for a blueprint based actor creation similar to `World.spawn_actor`

Expand Down
46 changes: 2 additions & 44 deletions srunner/examples/ControlLoss.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,6 @@
<?xml version="1.0"?>
<scenarios>
<scenario name="ControlLoss_1" type="ControlLoss" town="Town01">
<ego_vehicle x="392.5" y="195" z="0.5" yaw="90" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_2" type="ControlLoss" town="Town01">
<ego_vehicle x="-2.0" y="160" z="0.5" yaw="90" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_3" type="ControlLoss" town="Town01">
<ego_vehicle x="168.9" y="59.8" z="0.5" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_4" type="ControlLoss" town="Town02">
<ego_vehicle x="27" y="110" z="0.22" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_5" type="ControlLoss" town="Town02">
<ego_vehicle x="54.8" y="307.2" z="0.22" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_6" type="ControlLoss" town="Town02">
<ego_vehicle x="57.4" y="191.7" z="0.5" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_7" type="ControlLoss" town="Town03">
<ego_vehicle x="15" y="207.5" z="2" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_8" type="ControlLoss" town="Town03">
<ego_vehicle x="-74" y="-12" z="0.1" yaw="270" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_9" type="ControlLoss" town="Town03">
<ego_vehicle x="-85.1" y="-87.4" z="0.3" yaw="89" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_10" type="ControlLoss" town="Town04">
<ego_vehicle x="218.4" y="193" z="0" yaw="338" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_11" type="ControlLoss" town="Town04">
<ego_vehicle x="-40.4" y="-229.5" z="0" yaw="131" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_12" type="ControlLoss" town="Town04">
<ego_vehicle x="-45" y="37.2" z="11" yaw="0" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_13" type="ControlLoss" town="Town05">
<ego_vehicle x="90.9" y="-66" z="0" yaw="67" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_14" type="ControlLoss" town="Town05">
<ego_vehicle x="-54.7" y="110.9" z="0.1" yaw="90" model="vehicle.lincoln.mkz_2017" />
</scenario>
<scenario name="ControlLoss_15" type="ControlLoss" town="Town05">
<ego_vehicle x="119.1" y="-142.7" z="0.1" yaw="-170" model="vehicle.lincoln.mkz_2017" />
<scenario name="ControlLoss_1" type="ControlLoss" town="Town10HD_Opt">
<ego_vehicle x="-17" y="140" z="0.5" yaw="0" model="vehicle.lincoln.mkz" />
</scenario>
</scenarios>
4 changes: 2 additions & 2 deletions srunner/scenic/carlaChallenge1.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ ego = new Car at start,
with blueprint EGO_MODEL,
with behavior EgoBehavior(EGO_SPEED)

debris1 = new Debris following roadDirection for Range(10, 20)
debris1 = new Debris following roadDirection from start for Range(10, 20)
debris2 = new Debris following roadDirection from debris1 for Range(5, 10)
debris3 = new Debris following roadDirection from debris2 for Range(5, 10)

require (distance to intersection) > 50
terminate when (distance from debris3 to ego) > 10 and (distance to start) > 50
terminate when (distance to start) > 50
10 changes: 5 additions & 5 deletions srunner/scenic/carlaChallenge2.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ model srunner.scenic.models.model

## CONSTANTS
EGO_MODEL = "vehicle.lincoln.mkz"
EGO_SPEED = 10
EGO_SPEED = 7
EGO_BRAKING_THRESHOLD = 12

LEAD_CAR_SPEED = 10
LEADCAR_BRAKING_THRESHOLD = 10
LEAD_CAR_SPEED = 8
LEADCAR_BRAKING_THRESHOLD = 15

BRAKE_ACTION = 1.0

Expand Down Expand Up @@ -46,12 +46,12 @@ lane = Uniform(*network.lanes)

obstacle = new Trash on lane.centerline

leadCar = new Car following roadDirection from obstacle for Range(-50, -30),
leadCar = new Car following roadDirection from obstacle for Range(-60, -50),
with behavior LeadingCarBehavior(LEAD_CAR_SPEED)

ego = new Car following roadDirection from leadCar for Range(-15, -10),
with blueprint EGO_MODEL,
with behavior EgoBehavior(EGO_SPEED)

require (distance to intersection) > 50
require (distance to intersection) > 60
terminate when ego.speed < 0.1 and (distance to obstacle) < 30
10 changes: 5 additions & 5 deletions srunner/scenic/carlaChallenge3_dynamic.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ model srunner.scenic.models.model

## CONSTANTS
EGO_MODEL = "vehicle.lincoln.mkz"
EGO_SPEED = 6
SAFETY_DISTANCE = 10
EGO_SPEED = 7
SAFETY_DISTANCE = 17
BRAKE_INTENSITY = 1.0

PEDESTRIAN_MIN_SPEED = 2.0
PEDESTRIAN_MIN_SPEED = 15
THRESHOLD = 30

# EGO BEHAVIOR: Follow lane and brake when reaches threshold distance to obstacle
Expand Down Expand Up @@ -48,10 +48,10 @@ vending_machine = new VendingMachine right of vending_spot by 3,
with heading -90 deg relative to vending_spot.heading,
with regionContainedIn None

ego = new Car following roadDirection from spot for Range(-50, -40),
ego = new Car following roadDirection from spot for Range(-40, -35),
with blueprint EGO_MODEL,
with behavior EgoBehavior(EGO_SPEED)

require (distance to intersection) > 50
require (ego.laneSection._slowerLane is None)
terminate when (distance to spot) > 30
terminate when (distance to spot) > 40
2 changes: 1 addition & 1 deletion srunner/scenic/carlaChallenge3_static.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ model srunner.scenic.models.model

## CONSTANTS
EGO_MODEL = "vehicle.lincoln.mkz"
EGO_SPEED = 10
EGO_SPEED = 8
EGO_BRAKING_THRESHOLD = 12

BRAKE_ACTION = 1.0
Expand Down
43 changes: 19 additions & 24 deletions srunner/scenic/carlaChallenge4.scenic
Original file line number Diff line number Diff line change
@@ -1,52 +1,47 @@
""" Scenario Description
Traffic Scenario 04.
Obstacle avoidance without prior action.
The ego-vehicle encounters an obstacle / unexpected entity on the road and must perform an
emergency brake or an avoidance maneuver.
"""

## SET MAP AND MODEL (i.e. definitions of all referenceable vehicle types, road library, etc)
param map = localPath('assets/Town10HD_Opt.xodr')
param carla_map = 'Town10HD_Opt'
model srunner.scenic.models.model

## CONSTANTS
EGO_MODEL = "vehicle.lincoln.mkz"
BICYCLE_MIN_SPEED = 1.5
THRESHOLD = 18
PEDESTRIAN_MIN_SPEED = 15
THRESHOLD = 25
BRAKE_ACTION = 1.0
SAFETY_DISTANCE = 10
SAFETY_DISTANCE = 25

## DEFINING BEHAVIORS
behavior EgoBehavior(trajectory):
try:
do FollowTrajectoryBehavior(trajectory = trajectory)
do FollowTrajectoryBehavior(target_speed=7, trajectory=trajectory)
terminate

interrupt when withinDistanceToObjsInLane(self, SAFETY_DISTANCE):
take SetBrakeAction(BRAKE_ACTION)

behavior BicycleBehavior(speed=3, threshold=15):
behavior PedestrianBehavior(speed=1, threshold=15):
do CrossingBehavior(ego, speed, threshold)

## DEFINING SPATIAL RELATIONS
# make sure to put '*' to uniformly randomly select from all elements of the list
intersec = Uniform(*network.intersections)
startLane = Uniform(*intersec.incomingLanes)
maneuver = Uniform(*startLane.maneuvers)
ego_trajectory = [maneuver.startLane, maneuver.connectingLane, maneuver.endLane]

# Get the ego manuever
maneuvers = filter(lambda i: i.type != ManeuverType.STRAIGHT, startLane.maneuvers)
maneuver = Uniform(*maneuvers)
trajectory = [maneuver.startLane, maneuver.connectingLane, maneuver.endLane]

spot = new OrientedPoint in maneuver.startLane.centerline
ego = new Car at spot,
with blueprint EGO_MODEL,
with behavior EgoBehavior(trajectory = ego_trajectory)
with behavior EgoBehavior(trajectory=trajectory)

spotBicycle = new OrientedPoint in maneuver.endLane.centerline,
spotPedestrian = new OrientedPoint in maneuver.endLane.centerline,
facing roadDirection
bicycle = new Bicycle at spotBicycle offset by 3.5@0,
with heading 90 deg relative to spotBicycle.heading,
with behavior BicycleBehavior(BICYCLE_MIN_SPEED, THRESHOLD),
Pedestrian = new Pedestrian at spotPedestrian offset by 3.5@0,
with heading 90 deg relative to spotPedestrian.heading,
with behavior PedestrianBehavior(PEDESTRIAN_MIN_SPEED, THRESHOLD),
with regionContainedIn None

require (maneuver.endLane.sections[0]._slowerLane is None)
require 10 <= (distance to intersec) <= 15
require 10 <= (distance from bicycle to intersec) <= 15
terminate when (distance to spot) > 50
require 10 <= (distance from Pedestrian to intersec) <= 20
terminate when (distance to intersec) >= 30
8 changes: 4 additions & 4 deletions srunner/scenic/carlaChallenge5.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ param carla_map = 'Town10HD_Opt'
model srunner.scenic.models.model

#CONSTANTS
EGO_SPEED = 10
SLOW_CAR_SPEED = 6
EGO_TO_BICYCLE = 10
EGO_SPEED = 8
SLOW_CAR_SPEED = 3
EGO_TO_BICYCLE = 25
DIST_THRESHOLD = 15

#EGO BEHAVIOR: Follow lane, then perform a lane change
Expand All @@ -20,7 +20,7 @@ behavior EgoBehavior(leftpath, origpath=[]):
do FollowLaneBehavior(EGO_SPEED)

interrupt when withinDistanceToAnyObjs(self, DIST_THRESHOLD) and not laneChangeCompleted:
do LaneChangeBehavior(laneSectionToSwitch=leftpath, target_speed=10)
do LaneChangeBehavior(laneSectionToSwitch=leftpath, target_speed=8)
laneChangeCompleted = True

#OTHER BEHAVIOR
Expand Down
54 changes: 28 additions & 26 deletions srunner/scenic/carlaChallenge7.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,49 @@ param map = localPath('assets/Town10HD_Opt.xodr')
param carla_map = 'Town10HD_Opt'
model srunner.scenic.models.model

DELAY_TIME_1 = 1 # the delay time for ego
DELAY_TIME_2 = 40 # the delay time for the slow car
FOLLOWING_DISTANCE = 13 # normally 10, 40 when DELAY_TIME is 25, 50 to prevent collisions
EGO_MODEL = "vehicle.lincoln.mkz"

DISTANCE_TO_INTERSECTION1 = Uniform(15, 20) * -1
DISTANCE_TO_INTERSECTION2 = Uniform(10, 15) * -1
SAFETY_DISTANCE = 20
SAFETY_DISTANCE = 15
BRAKE_INTENSITY = 1.0

DISTANCE_TO_INTERSECTION = Uniform(10, 15) * -1

behavior CrossingCarBehavior(trajectory):
while True:
do FollowTrajectoryBehavior(trajectory = trajectory)
do FollowTrajectoryBehavior(trajectory=trajectory)
wait

behavior EgoBehavior(trajectory):

try:
do FollowTrajectoryBehavior(trajectory=trajectory)
do FollowTrajectoryBehavior(target_speed=7, trajectory=trajectory)
terminate
interrupt when withinDistanceToAnyObjs(self, SAFETY_DISTANCE):
take SetBrakeAction(BRAKE_INTENSITY)


spawnAreas = []
fourWayIntersection = filter(lambda i: i.is4Way, network.intersections)
intersec = Uniform(*fourWayIntersection)

# Get the ego manuever
startLane = Uniform(*intersec.incomingLanes)
straight_maneuvers = filter(lambda i: i.type == ManeuverType.STRAIGHT, startLane.maneuvers)
straight_maneuver = Uniform(*straight_maneuvers)
ego_trajectory = [straight_maneuver.startLane, straight_maneuver.connectingLane, straight_maneuver.endLane]
ego_maneuvers = filter(lambda i: i.type == ManeuverType.STRAIGHT, startLane.maneuvers)
ego_maneuver = Uniform(*ego_maneuvers)
ego_trajectory = [ego_maneuver.startLane, ego_maneuver.connectingLane, ego_maneuver.endLane]

# Get the adversary maneuver
other_maneuvers = filter(lambda i: i.type == ManeuverType.STRAIGHT, ego_maneuver.conflictingManeuvers)
other_maneuver = Uniform(*other_maneuvers)
other_trajectory = [other_maneuver.startLane, other_maneuver.connectingLane, other_maneuver.endLane]

conflicting_straight_maneuvers = filter(lambda i: i.type == ManeuverType.STRAIGHT, straight_maneuver.conflictingManeuvers)
csm = Uniform(*conflicting_straight_maneuvers)
crossing_startLane = csm.startLane
crossing_car_trajectory = [csm.startLane, csm.connectingLane, csm.endLane]
## OBJECT PLACEMENT
other_spwPt = new OrientedPoint in other_maneuver.startLane.centerline
ego_spwPt = new OrientedPoint in ego_maneuver.startLane.centerline

ego_spwPt = startLane.centerline[-1]
csm_spwPt = crossing_startLane.centerline[-1]
ego = new Car at ego_spwPt,
with blueprint EGO_MODEL,
with behavior EgoBehavior(trajectory=ego_trajectory)

ego = new Car following roadDirection from ego_spwPt for DISTANCE_TO_INTERSECTION1,
with behavior EgoBehavior(trajectory = ego_trajectory)
crossing_car = new Truck at other_spwPt,
with blueprint 'vehicle.ambulance.ford',
with behavior CrossingCarBehavior(other_trajectory)

crossing_car = new Car following roadDirection from csm_spwPt for DISTANCE_TO_INTERSECTION2,
with behavior CrossingCarBehavior(crossing_car_trajectory)
require 10 <= (distance to intersec) <= 15
terminate when (distance to ego_spwPt) >= 40
3 changes: 1 addition & 2 deletions srunner/scenic/carlaChallenge8.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require monitor TrafficLights()
## DEFINING BEHAVIORS
behavior AdversaryBehavior(trajectory):
do FollowTrajectoryBehavior(trajectory=trajectory)
wait

behavior EgoBehavior(speed, trajectory):
try:
Expand Down Expand Up @@ -76,6 +77,4 @@ adversary = new Car at adv_spawn_pt,
with behavior AdversaryBehavior(adv_trajectory)

require (ego_start_section.laneToLeft == adv_end_section) # make sure the ego and adversary are spawned in opposite lanes
require 25 <= (distance to intersec) <= 30
require 15 <= (distance from adversary to intersec) <= 20
terminate when (distance to ego_spawn_pt) > 70
Loading

0 comments on commit 2616d21

Please sign in to comment.