Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added world types #101

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manager/manager/launcher/launcher_drones_ros2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand All @@ -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}"
Expand Down
58 changes: 56 additions & 2 deletions manager/manager/launcher/launcher_engine.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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']
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion manager/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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
Expand Down