Skip to content

Commit

Permalink
Added simulation option
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 20, 2025
1 parent 19a4657 commit b97ee3c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/nanosaur/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
DEFAULT_ROBOT_CONFIG = {
'name': 'nanosaur',
'domain_id': 0,
'simulation': False,
'camera_type': '',
'lidar_type': '',
'engines': [],
Expand All @@ -59,8 +60,9 @@ def __init__(self, robot_config=None, name=None):
setattr(self, key, value)

def __repr__(self):
attributes = ', '.join(f"{key}={value}" for key, value in self.__dict__.items() if key not in ['name', 'domain_id'] and value)
return f"{self.name}[DID={self.domain_id}]({attributes})"
attributes = ', '.join(f"{key}={value}" for key, value in self.__dict__.items() if key not in ['name', 'domain_id', 'simulation'] and value)
sim_prefix = "(sim) " if self.simulation else ""
return f"{sim_prefix}{self.name}[DID={self.domain_id}]({attributes})"

def to_dict(self) -> dict:
return self.__dict__
Expand All @@ -71,14 +73,19 @@ def config_to_ros(self) -> str:
if key == 'domain_id' or not value:
continue
param_name = 'robot_name' if key == 'name' else key
if key == 'simulation':
param_name = 'use_sim_time'
if isinstance(value, list):
value = f'"[{", ".join(value)}]"'
ros_params.append(f"{param_name}:={value}")
return ' '.join(ros_params)

def verbose(self):
"""Print the robot configuration."""
print(TerminalFormatter.color_text("Robot:", bold=True))
if self.simulation:
print(TerminalFormatter.color_text("Robot: (simulated)", bold=True, color='magenta'))
else:
print(TerminalFormatter.color_text("Robot:", bold=True))
print(f" {TerminalFormatter.color_text('Name:', bold=True)} {self.name}")
print(f" {TerminalFormatter.color_text('Domain ID:', bold=True)} {self.domain_id}")
print(f" {TerminalFormatter.color_text('Camera:', bold=True)} {self.camera_type or 'not set'}")
Expand All @@ -88,7 +95,7 @@ def verbose(self):
if other_attributes := {
key: value
for key, value in self.__dict__.items()
if key not in ['name', 'domain_id', 'camera_type', 'lidar_type', 'engines']
if key not in ['name', 'simulation', 'domain_id', 'camera_type', 'lidar_type', 'engines']
}:
print(f" {TerminalFormatter.color_text('Other attributes:', bold=True)}")
for key, value in other_attributes.items():
Expand Down

0 comments on commit b97ee3c

Please sign in to comment.