diff --git a/manager/manager/launcher/launcher_drones_ros2.py b/manager/manager/launcher/launcher_drones_ros2.py index 51afdb4..639ccdd 100644 --- a/manager/manager/launcher/launcher_drones_ros2.py +++ b/manager/manager/launcher/launcher_drones_ros2.py @@ -13,7 +13,7 @@ class LauncherDronesRos2(ILauncher): resource_folders: List[str] model_folders: List[str] plugin_folders: List[str] - world_file: str + launch_file: str running = False threads: List[Any] = [] @@ -27,7 +27,7 @@ def run(self, callback): # expand variables in configuration paths self._set_environment() - world_file = os.path.expandvars(self.world_file) + world_file = os.path.expandvars(self.launch_file) # Launching MicroXRCE and Aerostack2 nodes as2_launch_cmd = f"ros2 launch jderobot_drones as2_default_classic_gazebo.launch.py world_file:={world_file}" diff --git a/manager/manager/launcher/launcher_engine.py b/manager/manager/launcher/launcher_engine.py index fd5e8f9..3bb41fb 100644 --- a/manager/manager/launcher/launcher_engine.py +++ b/manager/manager/launcher/launcher_engine.py @@ -1,10 +1,50 @@ -from typing import Any +from typing import List, Any from pydantic import BaseModel import time from src.manager.libs.process_utils import get_class, class_from_module from src.manager.ram_logging.log_manager import LogManager +worlds = { + "gazebo": + {"1": [{ + "type": "module", + "module": "ros_api", + "resource_folders": [], + "model_folders": [], + "plugin_folders": [], + "parameters": [], + "launch_file": [], + }], "2": [{ + "type": "module", + "module": "ros2_api", + "resource_folders": [], + "model_folders": [], + "plugin_folders": [], + "parameters": [], + "launch_file": [], + }]}, + "drones": + {"1": [{ + "type": "module", + "module": "drones", + "resource_folders": [], + "model_folders": [], + "plugin_folders": [], + "parameters": [], + "launch_file": [], + }], "2": [{ + "type": "module", + "module": "drones_ros2", + "resource_folders": [], + "model_folders": [], + "plugin_folders": [], + "parameters": [], + "launch_file": [], + }]}, + "physical": {} + } + visualization = { "none": [], "console": [{"module":"console", @@ -80,13 +120,27 @@ class LauncherEngine(BaseModel): exercise_id: str + ros_version: int launch: dict + world: str + resource_folders: str + model_folders: str + launch_file: str visualization: str module:str = '.'.join(__name__.split('.')[:-1]) terminated_callback: Any = None def run(self): keys = sorted(self.launch.keys()) + # Launch world + for module in worlds[self.world][str(self.ros_version)]: + module["exercise_id"] = self.exercise_id + module["resource_folders"] = [self.resource_folders] + module["model_folders"] = [self.model_folders] + module["launch_file"] = self.launch_file + launcher = self.launch_module(module) + self.launch[str(module['module'])] = {'launcher': launcher} + # Launch plugins for key in keys: launcher_data = self.launch[key] launcher_type = launcher_data['type'] @@ -105,7 +159,7 @@ def run(self): self.launch_command(launcher_data) else: raise LauncherEngineException(f"Launcher type {launcher_type} not valid") - # Launch visualization + # Launch visualization for module in visualization[self.visualization]: module["exercise_id"] = self.exercise_id launcher = self.launch_module(module) diff --git a/manager/manager/manager.py b/manager/manager/manager.py index 0974807..94e725a 100644 --- a/manager/manager/manager.py +++ b/manager/manager/manager.py @@ -117,6 +117,7 @@ def terminated_callback(name, code): self.terminate() configuration = event.kwargs.get('data', {}) + configuration['ros_version'] = self.ros_version # generate exercise_folder environment variable self.exercise_id = configuration['exercise_id'] @@ -292,7 +293,7 @@ def signal_handler(sign, frame): def get_ros_version(self): output = subprocess.check_output(['bash', '-c', 'echo $ROS_VERSION']) - return output.decode('utf-8') + return output.decode('utf-8')[0] if __name__ == "__main__": import argparse