Skip to content

Commit

Permalink
Improve script with multiple workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 18, 2025
1 parent 53aba86 commit 5d681dc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/nanosaur/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def docker_start(platform, params: Params, args):
print(TerminalFormatter.color_text("Please install Docker and Docker Compose before running the simulation.", color='red'))
return False

workspace_path = workspace.get_workspace_path(params['nanosaur_workspace_name'])
workspace_path = workspace.get_workspace_path(params, params['simulation_ws_name'])
if workspace_path is not None:
# Create a DockerClient object with the docker-compose file
print(TerminalFormatter.color_text(f"Starting workspace src folder in {workspace_path}", color='yellow'))
Expand Down Expand Up @@ -74,7 +74,7 @@ def docker_stop(platform, params: Params, args):
print(TerminalFormatter.color_text("Please install Docker and Docker Compose before running the simulation.", color='red'))
return False

workspace_path = workspace.get_workspace_path(params['nanosaur_workspace_name'])
workspace_path = workspace.get_workspace_path(params, params['simulation_ws_name'])
if workspace_path is not None:
# Create a DockerClient object with the docker-compose file
print(TerminalFormatter.color_text(f"Starting docker from container {workspace_path}", color='yellow'))
Expand Down
2 changes: 1 addition & 1 deletion src/nanosaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def main():
# Add robot start subcommand
parser_robot_start = robot_subparsers.add_parser('start', help="Start the robot")
parser_robot_start.add_argument(
'--developer', '--dev', action='store_true', help="Run in developer mode")
'--container', action='store_true', help="Run from container")
parser_robot_start.add_argument(
'--build', action='store_true', help="Rebuild docker before starting")
parser_robot_start.set_defaults(func=robot.robot_start)
Expand Down
8 changes: 4 additions & 4 deletions src/nanosaur/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def to_dict(self):


def start_robot_simulation(params):
nanosaur_ws_path = workspace.get_workspace_path(params['nanosaur_workspace_name'])
nanosaur_ws_path = workspace.get_workspace_path(params, params['simulation_ws_name'])
bash_file = f'{nanosaur_ws_path}/install/setup.bash'
# Check which simulation tool is selected
if 'simulation_tool' not in params:
Expand Down Expand Up @@ -206,10 +206,10 @@ def robot_start(platform, params: Params, args):
# Check the device type
if device_type == "desktop":
# Start the robot simulation
if args.developer:
start_robot_simulation(params)
else:
if args.container:
docker.docker_start(platform, params, args)
else:
start_robot_simulation(params)
elif device_type == "robot":
print(TerminalFormatter.color_text("Not yet implemented", color='yellow'))
else:
Expand Down
36 changes: 1 addition & 35 deletions src/nanosaur/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
def simulation_start(platform, params: Params, args):
"""Install the simulation tools."""

nanosaur_ws_path = workspace.get_workspace_path(params['nanosaur_workspace_name'])
nanosaur_ws_path = workspace.get_workspace_path(params, params['simulation_ws_name'])
bash_file = f'{nanosaur_ws_path}/install/setup.bash'
# Check which simulation tool is selected
if 'simulation_tool' not in params:
Expand Down Expand Up @@ -117,38 +117,4 @@ def simulation_set(platform, params: Params, args):
else:
print(TerminalFormatter.color_text("Invalid choice. Please enter a number.", color='red'))
return True


@require_sudo_password
def simulation_install(platform, params: Params, args, password=None):
"""Install simulation tools"""
device_type = "robot" if platform['Machine'] == 'jetson' else "desktop"
print(TerminalFormatter.color_text(f"Nanosaur simulation tools installation on {device_type}", bold=True))
# Create workspace
workspace_path = workspace.create_workspace(params['nanosaur_workspace_name'])
# Download rosinstall for this device
print(TerminalFormatter.color_text("- Download rosinstall", bold=True))
branch = params['nanosaur_branch']
url = f"https://raw.githubusercontent.com/rnanosaur/nanosaur/{branch}/nanosaur/rosinstall/simulation.rosinstall"
rosinstall_path = workspace.download_rosinstall(
url, workspace_path, "simulation.rosinstall")
# Import workspace
print(TerminalFormatter.color_text("- Import workspace from simulation.rosinstall", bold=True))
# run vcs import to sync the workspace
vcs_status = workspace.run_vcs_import(workspace_path, rosinstall_path)
if not vcs_status:
print(TerminalFormatter.color_text("Failed to import workspace", color='red'))
return False
# rosdep workspace
print(TerminalFormatter.color_text(f"- Install all dependencies on workspace {workspace_path}", bold=True))
if not workspace.run_rosdep(workspace_path, password):
print(TerminalFormatter.color_text("Failed to install dependencies", color='red'))
return False
# Build environment
print(TerminalFormatter.color_text(f"- Build workspace {workspace_path}", bold=True))
if not workspace.run_colcon_build(workspace_path):
print(TerminalFormatter.color_text("Failed to build workspace", color='red'))
return False
# All fine
return True
# EOF

0 comments on commit 5d681dc

Please sign in to comment.