Skip to content

Commit

Permalink
Added OSC Property to turn on all vehicle lights
Browse files Browse the repository at this point in the history
Change-Id: I1c70db507c3c89ff1b623c78e420f26056f57053
  • Loading branch information
fabianoboril authored Aug 25, 2021
1 parent 5eab069 commit 8cd7035
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
11 changes: 10 additions & 1 deletion srunner/scenariomanager/actorcontrols/npc_vehicle_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def run_step(self):

self._actor.apply_control(control)

current_speed = math.sqrt(self._actor.get_velocity().x**2 + self._actor.get_velocity().y**2)

if self._init_speed:
current_speed = math.sqrt(self._actor.get_velocity().x**2 + self._actor.get_velocity().y**2)

# If _init_speed is set, and the PID controller is not yet up to the point to take over,
# we manually set the vehicle to drive with the correct velocity
Expand All @@ -121,3 +122,11 @@ def run_step(self):
vx = math.cos(yaw) * target_speed
vy = math.sin(yaw) * target_speed
self._actor.set_target_velocity(carla.Vector3D(vx, vy, 0))

light_state = self._actor.get_light_state()
if current_speed >= target_speed:
light_state |= carla.VehicleLightState.Brake
else:
light_state &= ~carla.VehicleLightState.Brake

self._actor.set_light_state(carla.VehicleLightState(light_state))
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,16 @@ def _set_new_velocity(self, next_location):
target_speed = 0

if target_speed < current_speed:
self._actor.set_light_state(carla.VehicleLightState.Brake)
light_state = self._actor.get_light_state()
light_state |= carla.VehicleLightState.Brake
self._actor.set_light_state(carla.VehicleLightState(light_state))
if self._max_deceleration is not None:
target_speed = max(target_speed, current_speed - (current_time -
self._last_update) * self._max_deceleration)
else:
self._actor.set_light_state(carla.VehicleLightState.NONE)
light_state = self._actor.get_light_state()
light_state &= ~carla.VehicleLightState.Brake
self._actor.set_light_state(carla.VehicleLightState(light_state))
if self._max_acceleration is not None:
tmp_speed = min(target_speed, current_speed + (current_time -
self._last_update) * self._max_acceleration)
Expand Down
19 changes: 11 additions & 8 deletions srunner/scenariomanager/carla_data_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,11 +571,12 @@ def request_new_actors(actor_list, safe_blueprint=False, tick=True):
- actor_list: list of ActorConfigurationData
"""

SpawnActor = carla.command.SpawnActor # pylint: disable=invalid-name
PhysicsCommand = carla.command.SetSimulatePhysics # pylint: disable=invalid-name
FutureActor = carla.command.FutureActor # pylint: disable=invalid-name
ApplyTransform = carla.command.ApplyTransform # pylint: disable=invalid-name
SetAutopilot = carla.command.SetAutopilot # pylint: disable=invalid-name
SpawnActor = carla.command.SpawnActor # pylint: disable=invalid-name
PhysicsCommand = carla.command.SetSimulatePhysics # pylint: disable=invalid-name
FutureActor = carla.command.FutureActor # pylint: disable=invalid-name
ApplyTransform = carla.command.ApplyTransform # pylint: disable=invalid-name
SetAutopilot = carla.command.SetAutopilot # pylint: disable=invalid-name
SetVehicleLightState = carla.command.SetVehicleLightState # pylint: disable=invalid-name

batch = []

Expand Down Expand Up @@ -616,10 +617,12 @@ def request_new_actors(actor_list, safe_blueprint=False, tick=True):
command = SpawnActor(blueprint, _spawn_point)
command.then(SetAutopilot(FutureActor, actor.autopilot, CarlaDataProvider._traffic_manager_port))

if actor.category == 'misc':
command.then(PhysicsCommand(FutureActor, True))
elif actor.args is not None and 'physics' in actor.args and actor.args['physics'] == "off":
if actor.args is not None and 'physics' in actor.args and actor.args['physics'] == "off":
command.then(ApplyTransform(FutureActor, _spawn_point)).then(PhysicsCommand(FutureActor, False))
elif actor.category == 'misc':
command.then(PhysicsCommand(FutureActor, True))
if actor.args is not None and 'lights' in actor.args and actor.args['lights'] == "on":
command.then(SetVehicleLightState(FutureActor, carla.VehicleLightState.All))

batch.append(command)

Expand Down

0 comments on commit 8cd7035

Please sign in to comment.