Skip to content

Commit 3b2e96a

Browse files
committed
reformat launch models
1 parent a932769 commit 3b2e96a

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

manager/libs/launch_world_model.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Module for managing and validating robotics application launch world configs."""
2+
13
from dataclasses import dataclass
24
from typing import Optional
35
from pydantic import BaseModel, ValidationError
@@ -6,6 +8,8 @@
68

79

810
class ConfigurationModel(BaseModel):
11+
"""Pydantic model for robotics application world and launch file configuration."""
12+
913
world: str
1014
launch_file_path: str
1115

@@ -15,10 +19,23 @@ class ConfigurationModel(BaseModel):
1519

1620
@dataclass
1721
class ConfigurationManager:
22+
"""Manager for robotics application configuration validation and storage."""
23+
1824
configuration: ConfigurationModel
1925

2026
@staticmethod
2127
def validate(configuration: dict):
28+
"""Validate the given configuration dictionary using the ConfigurationModel.
29+
30+
Args:
31+
configuration (dict): The configuration data to validate.
32+
33+
Returns:
34+
ConfigurationModel: The validated configuration model.
35+
36+
Raises:
37+
ValueError: If the configuration is invalid.
38+
"""
2239
try:
2340
return ConfigurationModel(**configuration)
2441
except ValidationError as e:

manager/manager/launcher/launcher_robot.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""LauncherRobot module for managing robot launchers in different simulation worlds."""
2+
13
from typing import Optional
24
from pydantic import BaseModel
35

@@ -66,6 +68,8 @@
6668

6769

6870
class LauncherRobot(BaseModel):
71+
"""Class for managing robot launchers in different simulation worlds."""
72+
6973
world: str
7074
launch_file_path: str
7175
module: str = ".".join(__name__.split(".")[:-1])
@@ -74,7 +78,8 @@ class LauncherRobot(BaseModel):
7478
start_pose: Optional[list] = []
7579

7680
def run(self, start_pose=None):
77-
if start_pose != None:
81+
"""Run the robot launcher with an optional start pose."""
82+
if start_pose is not None:
7883
self.start_pose = start_pose
7984
for module in worlds[self.world][str(self.ros_version)]:
8085
module["launch_file"] = self.launch_file_path
@@ -83,13 +88,16 @@ def run(self, start_pose=None):
8388
LogManager.logger.info(self.launchers)
8489

8590
def terminate(self):
91+
"""Terminate all robot launchers and clear the launchers list."""
8692
LogManager.logger.info("Terminating robot launcher")
8793
if self.launchers:
8894
for launcher in self.launchers:
8995
launcher.terminate()
9096
self.launchers = []
9197

9298
def launch_module(self, configuration):
99+
"""Launch a robot module based on the provided configuration."""
100+
93101
def process_terminated(name, exit_code):
94102
LogManager.logger.info(
95103
f"LauncherEngine: {name} exited with code {exit_code}"
@@ -98,17 +106,24 @@ def process_terminated(name, exit_code):
98106
self.terminated_callback(name, exit_code)
99107

100108
launcher_module_name = configuration["module"]
101-
launcher_module = f"{self.module}.launcher_{launcher_module_name}.Launcher{class_from_module(launcher_module_name)}"
109+
launcher_module = (
110+
f"{self.module}.launcher_{launcher_module_name}."
111+
f"Launcher{class_from_module(launcher_module_name)}"
112+
)
102113
launcher_class = get_class(launcher_module)
103114
launcher = launcher_class.from_config(launcher_class, configuration)
104115

105116
launcher.run(self.start_pose, process_terminated)
106117
return launcher
107118

108119
def launch_command(self, configuration):
120+
"""Launch a robot command based on the provided configuration."""
109121
pass
110122

111123

112124
class LauncherRobotException(Exception):
125+
"""Exception class for errors related to LauncherRobot."""
126+
113127
def __init__(self, message):
128+
"""Initialize the LauncherRobotException with a message."""
114129
super(LauncherRobotException, self).__init__(message)

0 commit comments

Comments
 (0)