Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to configure Traffic Manager in SetAutopilotAction (for Carla) #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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