Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: BerkeleyLearnVerify/Scenic
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: t27/Scenic
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Apr 2, 2021

  1. Adding ability to configure Traffic Manager for Speed Limit and Traff…

    …ic Light violations
    t27 committed Apr 2, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    7502790 View commit details
Showing with 25 additions and 4 deletions.
  1. +14 −1 src/scenic/simulators/carla/actions.py
  2. +11 −3 src/scenic/simulators/carla/behaviors.scenic
15 changes: 14 additions & 1 deletion src/scenic/simulators/carla/actions.py
Original file line number Diff line number Diff line change
@@ -96,13 +96,26 @@ def applyTo(self, obj, sim):
traffic_light.set_state(self.color)

class SetAutopilotAction(VehicleAction):
def __init__(self, enabled):
def __init__(self, enabled, ignore_lights_percentage=0, vehicle_percentage_speed_difference=30):
"""Enable or Disable the Autopilot for the current agent. Also allows to set certain TrafficManager
parameters to configure the Autopilot behavior.
The default values of the Traffic Manager parameters are set to their Carla defaults
Arguments
:param enabled: True if you want to turn on autopilot
:param ignore_lights_percentage: Between 0 and 100. Amount of times traffic lights will be ignored.
:param vehicle_percentage_speed_difference: Percentage difference between intended speed and the current limit. Can be negative to exceed the limit.
"""
if not isinstance(enabled, bool):
raise RuntimeError('Enabled must be a boolean.')
self.enabled = enabled
self.ignore_lights_percentage = ignore_lights_percentage
self.vehicle_percentage_speed_difference = vehicle_percentage_speed_difference

def applyTo(self, obj, sim):
vehicle = obj.carlaActor
sim.tm.ignore_lights_percentage(vehicle, self.ignore_lights_percentage)
sim.tm.vehicle_percentage_speed_difference(vehicle, self.vehicle_percentage_speed_difference)
vehicle.set_autopilot(self.enabled, sim.tm.get_port())

#################################################
14 changes: 11 additions & 3 deletions src/scenic/simulators/carla/behaviors.scenic
Original file line number Diff line number Diff line change
@@ -8,9 +8,17 @@ try:
except ModuleNotFoundError:
pass # ignore; error will be caught later if user attempts to run a simulation

behavior AutopilotBehavior():
"""Behavior causing a vehicle to use CARLA's built-in autopilot."""
take SetAutopilotAction(True)
behavior AutopilotBehavior(ignore_lights_percentage=0, vehicle_percentage_speed_difference=30):
"""
Behavior causing a vehicle to use CARLA's built-in autopilot.
This also, optionally, allows setting some [TrafficManager](https://carla.readthedocs.io/en/latest/python_api/#carlatrafficmanager) parameters.
Args:
ignore_lights_percentage(float): Between 0 and 100. Amount of times traffic lights will be ignored.
vehicle_percentage_speed_difference(float): Percentage difference between intended speed and the current limit. Can be negative to exceed the limit.
"""
take SetAutopilotAction(True, ignore_lights_percentage, vehicle_percentage_speed_difference)

behavior WalkForwardBehavior(speed=0.5):
take SetWalkingDirectionAction(self.heading), SetWalkingSpeedAction(speed)