Skip to content

Commit

Permalink
Adding ability to configure Traffic Manager for Speed Limit and Traff…
Browse files Browse the repository at this point in the history
…ic Light violations
  • Loading branch information
t27 committed Apr 2, 2021
1 parent 49f76e1 commit 7502790
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/scenic/simulators/carla/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

#################################################
Expand Down
14 changes: 11 additions & 3 deletions src/scenic/simulators/carla/behaviors.scenic
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7502790

Please sign in to comment.