Skip to content

Commit d254c61

Browse files
Merge pull request #43 from Intelligent-Testing-Lab/28-add-support-for-spawning-ego-vehicle-through-scenario-runner
refactored threading to use MultiThreadedExecutors for callbacks
2 parents 0d0bb3c + 1f87daa commit d254c61

5 files changed

Lines changed: 25 additions & 22 deletions

File tree

aw_scenario_runner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,11 @@ def run_scenario(
129129

130130
self.carla_world.wait_for_tick()
131131

132-
logger.info("Setting up sensort configuration...")
132+
logger.info("Setting up sensor configuration...")
133133
ego.setup_sensors()
134134

135+
self.carla_world.wait_for_tick()
136+
135137
if not self.DEV_MODE:
136138
logger.info("Loading Autoware agent")
137139
agent_class_name = self.module_aw_agent.__name__.title().replace("_", "")

config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ carla:
77
timeout: 20
88
sync: true
99
fixed_delta_seconds: 0.05 # update rate 1 / FPS
10-
dev_mode: false
11-
debug: false
1210
traffic_manager:
1311
active: false
1412
sync: true # must be the same as carla sync
1513
seed: 0
1614
port: 8000
1715
scenario_runner:
16+
debug: false
17+
dev_mode: false
1818
json: ./example_scenario.json
1919
route_id: 0
2020
agent: srunner/autoagents/autoware_agent
2121
algorithm:
2222
iterations: 1000
23-
path: /srunner/ # relative path
23+
path: /algorithms # relative path
2424
hyperparmaters: # will be passed into the algorithm class

srunner/autoagents/autoware_agent.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ def setup(self, config: EnvironmentConfig | None = None) -> None:
4242
self.state_node = state_node.StateNode(self.autoware_state)
4343
self.autoware_node = autoware_node.AutowareNode(self.autoware_state)
4444

45-
self._nodes = [self.route_node, self.autoware_node, self.state_node]
46-
self._node_threads = [
47-
threading.Thread(target=rclpy.spin, args=(self.route_node)),
48-
threading.Thread(target=rclpy.spin, args=(self.autoware_node)),
49-
threading.Thread(target=rclpy.spin, args=(self.state_node)),
50-
]
45+
self._multi_thread_executor = rclpy.executor.MultiThreadedExecutor()
46+
47+
self._multi_thread_executor.add(self.route_node)
48+
self._multi_thread_executor.add(self.state_node)
49+
self._multi_thread_executor.add(self.autoware_node)
50+
51+
self._executor_thread = threading.Thread(
52+
target=self._multi_thread_executor.spin, daemon=True
53+
)
54+
self._executor_thread.start()
5155

5256
# check the bridge is ready
5357
# publish sensor information to the bridge
@@ -105,14 +109,14 @@ def _convert_to_waypoint(self, point):
105109
def destroy(self) -> None:
106110
"""Cleanup"""
107111
try:
108-
for thread in range(len(self._node_threads)):
109-
self._node_threads[thread].join()
110-
self._nodes[thread].destroy_node()
112+
self.autoware_node.destroy()
113+
self.state_node.destroy()
114+
self.route_node.destroy()
115+
rclpy.shutdown()
116+
self._executor_thread.join()
111117
except RuntimeError:
112118
logger.info("Cleaned up threads...")
113119

114-
rclpy.shutdown()
115-
116120
def run_step(self) -> None:
117121
"""Tick method containing all logic based on autoware state"""
118122
self.counter += 1

srunner/objects/ego_vehicle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ def __del__(self) -> None:
6767
"""Clean up
6868
Check if the actor exists in CARLA, delete if so
6969
"""
70-
if self._actor.is_alive():
70+
if self._actor.is_alive:
7171
self._actor.destroy()

srunner/objects/sensors.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ def __init__(self) -> None:
1616
def _spawn(self, bp_library, vehicle) -> None:
1717
sensor_bp = bp_library.find(str(self.type))
1818

19-
ignored_params = ["serealize", "id", "spawn", "type"]
19+
ignored_params = ["serealize", "id", "_spawn", "type", "spawn"]
2020

21-
sensor_params = [
22-
attr
23-
for attr in dir(self)
24-
if attr not in ignored_params or not attr.startswith("_")
25-
]
21+
sensor_params = [attr for attr in dir(self) if attr not in ignored_params]
22+
sensor_params = filter(lambda x: not x.startswith("__"), sensor_params)
2623

2724
for param in sensor_params:
2825
sensor_bp.set_attribute(param, str(getattr(self, param)))

0 commit comments

Comments
 (0)