Skip to content

Commit 071a731

Browse files
committed
Rework ActivateControllerAction OSC action
Change-Id: I91034ba6728af16582bbfc4c992f2186b3ea1908
1 parent 8034a7d commit 071a731

File tree

5 files changed

+119
-12
lines changed

5 files changed

+119
-12
lines changed

srunner/scenariomanager/actorcontrols/actor_control.py

+18
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,24 @@ def set_init_speed(self):
173173
"""
174174
self.control_instance.set_init_speed()
175175

176+
def change_lon_control(self, enable):
177+
"""
178+
Enable/Disable longitudinal control component of actor controller
179+
180+
Args:
181+
enable (boolean): Enable/Disable signal
182+
"""
183+
self.control_instance.change_lon_control(enable)
184+
185+
def change_lat_control(self, enable):
186+
"""
187+
Enable/Disable lateral control component of actor controller
188+
189+
Args:
190+
enable (boolean): Enable/Disable signal
191+
"""
192+
self.control_instance.change_lat_control(enable)
193+
176194
def run_step(self):
177195
"""
178196
Execute on tick of the controller's control loop

srunner/scenariomanager/actorcontrols/basic_control.py

+26
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class BasicControl(object):
3737
Defaults to False.
3838
_reached_goal (boolean):
3939
Defaults to False.
40+
_use_lon_control (boolean):
41+
Use longitudinal component of controller
42+
Defaults to True
43+
_use_lat_control (boolean):
44+
Use lateral component of controller
45+
Defaults to True
4046
"""
4147

4248
_actor = None
@@ -47,6 +53,8 @@ class BasicControl(object):
4753
_target_speed = 0
4854
_reached_goal = False
4955
_init_speed = False
56+
_use_lon_control = True
57+
_use_lat_control = True
5058

5159
def __init__(self, actor):
5260
"""
@@ -90,6 +98,24 @@ def set_init_speed(self):
9098
"""
9199
self._init_speed = True
92100

101+
def change_lon_control(self, enable):
102+
"""
103+
Enable/Disable longitudinal control component
104+
105+
Args:
106+
enable (boolean): Enable/Disable signal
107+
"""
108+
self._use_lon_control = enable
109+
110+
def change_lat_control(self, enable):
111+
"""
112+
Enable/Disable lateral control component
113+
114+
Args:
115+
enable (boolean): Enable/Disable signal
116+
"""
117+
self._use_lat_control = enable
118+
93119
def check_reached_waypoint_goal(self):
94120
"""
95121
Check if the actor reached the end of the waypoint list

srunner/scenariomanager/actorcontrols/simple_vehicle_control.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class SimpleVehicleControl(BasicControl):
7070
Defaults to False.
7171
_proximity_threshold (float): Distance in front of actor in which obstacles are considered
7272
Defaults to infinity.
73+
_consider_trafficlights (boolean): Enable/Disable consideration of red traffic lights
74+
Defaults to False.
75+
_max_deceleration (float): Deceleration value of the vehicle when braking
76+
Defaults to None (infinity).
77+
_max_acceleration (float): Acceleration value of the vehicle when accelerating
78+
Defaults to None (infinity).
7379
_cv_image (CV Image): Contains the OpenCV image, in case a debug camera is attached to the actor
7480
Defaults to None.
7581
_camera (sensor.camera.rgb): Debug camera attached to actor
@@ -283,7 +289,6 @@ def _set_new_velocity(self, next_location):
283289
target_speed = 0
284290

285291
if target_speed < current_speed and math.fabs(target_speed - current_speed) > 0.01:
286-
print(target_speed, current_speed)
287292
self._actor.set_light_state(carla.VehicleLightState.Brake)
288293
if self._max_deceleration is not None:
289294
target_speed = max(target_speed, current_speed - (current_time -

srunner/scenariomanager/scenarioatomics/atomic_behaviors.py

+59-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class ChangeActorControl(AtomicBehavior):
278278
Atomic to change the longitudinal/lateral control logic for an actor.
279279
The (actor, controller) pair is stored inside the Blackboard.
280280
281-
The behavior immediately terminates with SUCCESS after the controller.
281+
The behavior immediately terminates with SUCCESS after the controller was changed.
282282
283283
Args:
284284
actor (carla.Actor): Actor that should be controlled by the controller.
@@ -329,6 +329,64 @@ def update(self):
329329
return py_trees.common.Status.SUCCESS
330330

331331

332+
class DeActivateActorControlComponents(AtomicBehavior):
333+
334+
"""
335+
Atomic to enable/disable the longitudinal/lateral control component of an actor controller.
336+
The (actor, controller) pair is retrieved from the Blackboard.
337+
338+
The behavior immediately terminates with SUCCESS.
339+
340+
Args:
341+
actor (carla.Actor): Actor that should be controlled by the controller.
342+
control_py_module (string): Name of the python module containing the implementation
343+
of the controller.
344+
args (dictionary): Additional arguments for the controller.
345+
scenario_file_path (string): Additional path to controller implementation.
346+
name (string): Name of the behavior.
347+
Defaults to 'ChangeActorControl'.
348+
349+
Attributes:
350+
_actor_control (ActorControl): Instance of the actor control.
351+
"""
352+
353+
def __init__(self, actor, lon_control=None, lat_control=None, name="ChangeActorControl"):
354+
"""
355+
Setup actor controller.
356+
"""
357+
super(DeActivateActorControlComponents, self).__init__(name, actor)
358+
359+
self._lon_control = lon_control
360+
self._lat_control = lat_control
361+
362+
def update(self):
363+
"""
364+
Write (actor, controler) pair to Blackboard, or update the controller
365+
if actor already exists as a key.
366+
367+
returns:
368+
py_trees.common.Status.SUCCESS
369+
"""
370+
371+
actor_dict = {}
372+
373+
try:
374+
check_actors = operator.attrgetter("ActorsWithController")
375+
actor_dict = check_actors(py_trees.blackboard.Blackboard())
376+
except AttributeError:
377+
pass
378+
379+
if self._actor.id in actor_dict:
380+
if self._lon_control is not None:
381+
actor_dict[self._actor.id].change_lon_control(self._lon_control)
382+
if self._lat_control is not None:
383+
actor_dict[self._actor.id].change_lat_control(self._lat_control)
384+
else:
385+
return py_trees.common.Status.FAILURE
386+
387+
return py_trees.common.Status.SUCCESS
388+
389+
332390
class UpdateAllActorControls(AtomicBehavior):
333391

334392
"""

srunner/tools/openscenario_parser.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
ActorTransformSetterToOSCPosition,
2727
RunScript,
2828
ChangeWeather,
29-
ChangeAutoPilot,
3029
ChangeRoadFriction,
3130
ChangeActorTargetSpeed,
3231
ChangeActorControl,
3332
ChangeActorWaypoints,
3433
ChangeActorLateralMotion,
34+
DeActivateActorControlComponents,
3535
ChangeActorLaneOffset,
3636
SyncArrivalOSC,
3737
Idle)
@@ -1081,31 +1081,25 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs):
10811081
lat_maneuver = private_action.find('LaneOffsetAction')
10821082
continuous = strtobool(lat_maneuver.attrib.get('continuous', True))
10831083
# Parsing of the different Dynamic shapes is missing
1084-
10851084
lane_target_offset = lat_maneuver.find('LaneOffsetTarget')
10861085
if lane_target_offset.find('AbsoluteTargetLaneOffset') is not None:
10871086
absolute_offset = float(
10881087
lane_target_offset.find('AbsoluteTargetLaneOffset').attrib.get('value', 0))
10891088
atomic = ChangeActorLaneOffset(
10901089
actor, absolute_offset, continuous=continuous, name=maneuver_name)
1091-
10921090
elif lane_target_offset.find('RelativeTargetLaneOffset') is not None:
10931091
relative_target_offset = lane_target_offset.find('RelativeTargetLaneOffset')
10941092
relative_offset = float(relative_target_offset.attrib.get('value', 0))
1095-
10961093
relative_actor = None
10971094
for _actor in actor_list:
10981095
if relative_target_offset.attrib.get('entityRef', None) == _actor.attributes['role_name']:
10991096
relative_actor = _actor
11001097
break
1101-
11021098
if relative_actor is None:
11031099
raise AttributeError("Cannot find actor '{}' for condition".format(
11041100
relative_target_offset.attrib.get('entityRef', None)))
1105-
11061101
atomic = ChangeActorLaneOffset(actor, relative_offset, relative_actor,
11071102
continuous=continuous, name=maneuver_name)
1108-
11091103
else:
11101104
raise AttributeError("Unknown target offset")
11111105
else:
@@ -1147,13 +1141,19 @@ def convert_maneuver_to_atomic(action, actor, actor_list, catalogs):
11471141
raise AttributeError("Unknown speed action")
11481142
elif private_action.find('ActivateControllerAction') is not None:
11491143
private_action = private_action.find('ActivateControllerAction')
1150-
activate = strtobool(private_action.attrib.get('longitudinal'))
1151-
atomic = ChangeAutoPilot(actor, activate, name=maneuver_name)
1144+
lon_control = None
1145+
lat_control = None
1146+
if 'longitudinal' in private_action.attrib.keys():
1147+
lon_control = strtobool(private_action.attrib.get('longitudinal'))
1148+
if 'lateral' in private_action.attrib.keys():
1149+
lat_control = strtobool(private_action.attrib.get('lateral'))
1150+
atomic = DeActivateActorControlComponents(actor, lon_control, lat_control, name=maneuver_name)
11521151
elif private_action.find('ControllerAction') is not None:
11531152
controller_action = private_action.find('ControllerAction')
11541153
module, args = OpenScenarioParser.get_controller(controller_action, catalogs)
11551154
atomic = ChangeActorControl(actor, control_py_module=module, args=args,
1156-
scenario_file_path=OpenScenarioParser.osc_filepath)
1155+
scenario_file_path=OpenScenarioParser.osc_filepath,
1156+
name=maneuver_name)
11571157
elif private_action.find('TeleportAction') is not None:
11581158
teleport_action = private_action.find('TeleportAction')
11591159
position = teleport_action.find('Position')

0 commit comments

Comments
 (0)