From 66e26c34747741e48f71bae3c7411f793d809bf2 Mon Sep 17 00:00:00 2001 From: David Gasinski Date: Mon, 28 Jul 2025 14:11:55 +0100 Subject: [PATCH] bug fixes --- Dockerfile | 1 + aw_scenario_runner.py | 18 ++++++++++++++--- config.yaml | 1 + example_scenario.json | 1 - srunner/autoagents/autoware_agent.py | 3 +-- .../autoagents/autoware_nodes/state_node.py | 20 +++++-------------- srunner/tools/environment_parser.py | 12 ++++++----- 7 files changed, 30 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index be919d3..3f4b3e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN mkdir /ros_workspace/ && \ tar -xvf /ros_workspace/autoware_msgs.tar && \ rm -rf /ros_workspace/autoware_msgs.tar && \ source /opt/ros/humble/setup.bash && \ + apt install ros-humble-rmw-cyclonedds-cpp ros-humble-tf-transformations && \ rosdep install -i --from-path /ros_workspace/src --rosdistro humble -y && \ colcon build diff --git a/aw_scenario_runner.py b/aw_scenario_runner.py index fa4ee21..00e6479 100644 --- a/aw_scenario_runner.py +++ b/aw_scenario_runner.py @@ -67,6 +67,12 @@ def __init__(self, config: dict) -> None: sys.path.insert(0, os.path.dirname(autoware_agent_path)) self.module_aw_agent = importlib.import_module(module_name) + # load the algorithm of choice + algorithm = self._scenario_config["algorithm"] # relative path to entry point + alg_module = os.path.basename(algorithm).split(".")[0] + sys.path.insert(0, os.path.dirname(algorithm)) + self.module_algorithm = importlib.import_module(alg_module) + # main class to execute scenarios self.scenario_manager = ScenarioManager( self._scenario_config["debug"], @@ -221,7 +227,7 @@ def run_scenario( result = True except Exception: traceback.print_exc() - print("It doesn't wokr") + print("It doesn't work") result = False return result @@ -238,6 +244,8 @@ def _spawn_ego(self, env_config: EnvironmentConfig) -> None: ) self.ego_vehicles.append(ego) + CarlaDataProvider.get_world().wait_for_tick() # wait for tick + bp_library = self.carla_world.get_blueprint_library() # setup sensors for sensor in env_config.sensor_config: @@ -254,11 +262,15 @@ def _load_route_scenario( return route_config[0] def run(self) -> bool: + # load the original JSON file # load the route config - # load the scenarion - # run it + # load the scenario config + # run scenario # get the metrics # call the algorithm callback + # save using ResultsManager static class + + # repeat for iterations env_config = self._load_scenario_config() route_config = self._load_route_scenario(env_config) diff --git a/config.yaml b/config.yaml index 88bc9d5..84bc835 100644 --- a/config.yaml +++ b/config.yaml @@ -19,4 +19,5 @@ scenario_runner: in_docker: true # used for dev algorithm: iterations: 1000 + path: /srunner/ # relative path hyperparmaters: # will be passed into the algorithm class diff --git a/example_scenario.json b/example_scenario.json index 018b743..8d3255a 100644 --- a/example_scenario.json +++ b/example_scenario.json @@ -174,7 +174,6 @@ "upper_fov": 10.0, "lower_fov": -30.0, "rotation_frequency": 20, - "noise_stddev": 0.0 } }, { diff --git a/srunner/autoagents/autoware_agent.py b/srunner/autoagents/autoware_agent.py index 2c884ef..f29aa41 100644 --- a/srunner/autoagents/autoware_agent.py +++ b/srunner/autoagents/autoware_agent.py @@ -53,7 +53,6 @@ def setup(self, config: EnvironmentConfig | None = None) -> None: # check the bridge is ready # publish sensor information to the bridge # wait for it to return the correct message - # hang until ego_config_msg = EgoConfig() ego_config_msg.ego_name = config.ego_name @@ -69,7 +68,7 @@ def setup(self, config: EnvironmentConfig | None = None) -> None: # keep publishing ego_sensor config until the bridge is ready while not self.autoware_state.bridge_ready: time.sleep(1) - self.autoware_state.ego_config_publisher.publish(ego_config_msg) + self.state_node.ego_config_publisher.publish(ego_config_msg) def set_route(self) -> None: # for every point in the plan diff --git a/srunner/autoagents/autoware_nodes/state_node.py b/srunner/autoagents/autoware_nodes/state_node.py index 8a57b15..2e234f9 100644 --- a/srunner/autoagents/autoware_nodes/state_node.py +++ b/srunner/autoagents/autoware_nodes/state_node.py @@ -5,15 +5,13 @@ from srunner.autoagents.agent_state import autoware_state from autoware_carla_interface.msg import EgoConfig, BridgeState -from srunner.tools.environment_parser import DefaultSensor - class StateNode(Node): route_state = "/planning/mission_planning/state" motion_state = "/api/motion/state" localize_state = "/api/localization/initialization_state" - ego_config = "/bridge/ego_vehicle/config" # publish sensor config type: EgoConfig + ego_config = "/bridge/ego_vehicle/config" # publish sensor config type: EgoConfig bridge_state = "/bridge/state" def __init__(self, autoware_state: autoware_state.AutowareState) -> None: @@ -33,18 +31,13 @@ def __init__(self, autoware_state: autoware_state.AutowareState) -> None: 10, ) self.autoware_state_subscriber = self.create_subscription( - BridgeState, - self.bridge_state, - self.bridge_state_cb, - 10 + BridgeState, self.bridge_state, self.bridge_state_cb, 10 ) - + self.ego_config_publisher = self.create_publisher( - EgoConfig, - self.ego_config, - 10 + EgoConfig, self.ego_config, 10 ) - + def bridge_state_cb(self, bridge_state_msg: BridgeState): """Set the AutowareState attribute bridge_state @@ -78,6 +71,3 @@ def localize_state_cb( localize_state_msg (LocalizationInitializationState): localization message received """ self.autoware_state.localize_state = localize_state_msg.state - - def publish_sensor_info(self, sensor_config: list[DefaultSensor]) -> None: - return diff --git a/srunner/tools/environment_parser.py b/srunner/tools/environment_parser.py index 6f470d9..24769de 100644 --- a/srunner/tools/environment_parser.py +++ b/srunner/tools/environment_parser.py @@ -39,13 +39,15 @@ def _spawn(self, bp_library, vehicle) -> None: sensor_params = [attr for attr in dir(self) if attr not in ignored_params] for param in sensor_params: - sensor_bp.set_attribute(param, getattr(self, param)) + sensor_bp.set_attribute(param, str(getattr(self, param))) CarlaDataProvider.get_world().spawn_actor(sensor_bp, self.spawn, vehicle) + CarlaDataProvider.get_world().wait_for_tick() def serealize(self): return self.type, self.id + class CameraRGB(DefaultSensor): """ A class to hold additional information about a camera sensor @@ -70,8 +72,7 @@ def __init__(self) -> None: self.points_per_second: int = 0 self.upper_fov: float = 0.0 self.lower_fov: float = 0.0 - self.rotation_freq: int = 0 - self.noise_sttdev: float = 0.0 + self.rotation_frequency: int = 0 class SensorGNSS(DefaultSensor): @@ -171,8 +172,9 @@ def parse_ego_config(config: EnvironmentConfig, elem: Element) -> None: sensor_obj.points_per_second = sensor.attrib.get("points_per_second", 0) sensor_obj.upper_fov = sensor.attrib.get("upper_fov", 0.0) sensor_obj.lower_fov = sensor.attrib.get("lower_fov", 0.0) - sensor_obj.rotation_freq = sensor.attrib.get("rotation_frequency", 0) - sensor_obj.noise_sttdev = sensor.attrib.get("noise_sttdev", 0.0) + sensor_obj.rotation_frequency = sensor.attrib.get( + "rotation_frequency", 0 + ) sensor_obj.type = sensor_type sensor_obj.id = sensor.attrib.get("id", "")