Skip to content

Commit

Permalink
Refactor sim_config.py to add docstrings and improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
ll7 committed Feb 13, 2024
1 parent 645bdf5 commit 2578433
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion robot_sf/sim_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,28 @@

@dataclass
class EnvSettings:
"""
Data class to hold environment settings for a simulation.
"""
sim_config: SimulationSettings = SimulationSettings()
lidar_config: LidarScannerSettings = LidarScannerSettings()
robot_config: Union[DifferentialDriveSettings, BicycleDriveSettings] = DifferentialDriveSettings()
robot_config: Union[DifferentialDriveSettings, BicycleDriveSettings] = \
DifferentialDriveSettings()
map_pool: MapDefinitionPool = MapDefinitionPool()

def __post_init__(self):
"""
Check if any of the properties are not initialized (None) and raise an error if so.
"""
if not self.sim_config or not self.lidar_config \
or not self.robot_config or not self.map_pool:
raise ValueError('Please make sure all properties are initialized!')

def robot_factory(self) -> Union[DifferentialDriveRobot, BicycleDriveRobot]:
"""
Factory method to create a robot instance based on the type of robot configuration provided.
:return: robot instance.
"""
if isinstance(self.robot_config, DifferentialDriveSettings):
return DifferentialDriveRobot(self.robot_config)
elif isinstance(self.robot_config, BicycleDriveSettings):
Expand Down

0 comments on commit 2578433

Please sign in to comment.