Skip to content

Commit

Permalink
Improve robot definiton parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 20, 2025
1 parent 79ec867 commit 8bfc251
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/nanosaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def info(platform, params: Params, args):
if ws_path := workspace.get_workspace_path(
params, params.get(ws_name)
):
print(f" {TerminalFormatter.color_text(ws_name, bold=True)}: {ws_path}")
ws_name_split = ws_name.split('_')[1] # Split and get the middle part
print(f" {TerminalFormatter.color_text(ws_name_split, bold=True)}: {ws_path}")

# Print all robot configurations
if args.verbose:
Expand Down
8 changes: 6 additions & 2 deletions src/nanosaur/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ def start_robot_simulation(params):
command = simulation_tools[params['simulation_tool']]['robot']
# Load the robot configuration
robot = RobotList.get_robot(params)
print(TerminalFormatter.color_text(f"Starting {robot.name} ID={robot.domain_id}", color='green'))
print(TerminalFormatter.color_text(f"Starting {robot}", color='green'))

# Print the command to be run
print(f"ROS_DOMAIN_ID={robot.domain_id} {command} {robot.config_to_ros()}")

try:
# Combine sourcing the bash file with running the command
process = subprocess.Popen(
f"source {bash_file} && ROS_DOMAIN_ID={robot.domain_id} {command} namespace:={robot.name}",
f"source {bash_file} && ROS_DOMAIN_ID={robot.domain_id} {command} {robot.config_to_ros()}",
shell=True,
executable="/bin/bash",
stdout=subprocess.PIPE,
Expand Down
20 changes: 15 additions & 5 deletions src/nanosaur/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
DEFAULT_ROBOT_CONFIG = {
'name': 'nanosaur',
'domain_id': 0,
'camera': '',
'lidar': '',
'camera_type': '',
'lidar_type': '',
'engines': [],
}

CAMERA_CHOICES = ['', 'realsense', 'zed']
LIDAR_CHOICES = ['', 'rplidar']
LIDAR_CHOICES = ['', 'LD06', 'rplidar']
ENGINES_CHOICES = ['vlslam', 'nvblox', 'apriltag']


Expand All @@ -59,13 +59,23 @@ def __init__(self, robot_config=None, name=None):
setattr(self, key, value)

def __repr__(self):
# "Nanosaur[DID=](cover=AAA, )"
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}"
return f"{self.name}[DID={self.domain_id}]({attributes})"

def to_dict(self) -> dict:
return self.__dict__

def config_to_ros(self) -> str:
ros_params = []
for key, value in self.__dict__.items():
if key == 'domain_id' or not value:
continue
param_name = 'robot_name' if key == 'name' else key
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))
Expand Down

0 comments on commit 8bfc251

Please sign in to comment.