Skip to content

Commit

Permalink
Improve nanosaur commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rbonghi committed Jan 22, 2025
1 parent cb65ab7 commit 03e6a9a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 23 deletions.
42 changes: 30 additions & 12 deletions src/nanosaur/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import argparse
import argcomplete
import sys
import inquirer
from inquirer.themes import GreenPassion
from jtop import jtop, JtopException

from nanosaur import __version__
Expand All @@ -37,10 +39,11 @@
from nanosaur.swarm import parser_swarm_menu
from nanosaur.prompt_colors import TerminalFormatter
from nanosaur.utilities import RobotList
import inquirer


NANOSAUR_INSTALL_OPTIONS = ['Simple', 'Developer', 'Maintainer']
NANOSAUR_CONFIG_FILE_NAME = 'nanosaur.yaml'
NANOSAUR_HOME_NAME = 'nanosaur_test'
NANOSAUR_HOME_NAME = 'nanosaur'

# Define default parameters
DEFAULT_PARAMS = {
Expand Down Expand Up @@ -106,23 +109,38 @@ def install_old(platform, params: Params, args, password=None):


def install(platform, params: Params, args, password=None):
# Determine the device type
device_type = "robot" if platform['Machine'] == 'jetson' else "desktop"
# Questions to ask the user
questions = [
inquirer.List(
'choice',
message="What would you like to install?",
choices=['Developer Workspace', 'Simulation Tools', 'Robot Configuration'],
choices=NANOSAUR_INSTALL_OPTIONS,
),
inquirer.Confirm(
'confirm',
message="Are you sure you want to install this?",
default=False
)
]

answers = inquirer.prompt(questions)

if answers['choice'] == 'Developer Workspace':
# Ask the user to select an install type
answers = inquirer.prompt(questions, theme=GreenPassion())
if answers is None:
return False
# Check if the user wants to continue
if answers['confirm'] is False:
print(TerminalFormatter.color_text("Installation cancelled", color='red'))
return False
# Get the selected install type
install_type = answers['choice']
print(f"Installing {install_type} workspace...")
if install_type == 'Developer':
workspace.create_developer_workspace(platform, params, args)
elif answers['choice'] == 'Simulation Tools':
print(TerminalFormatter.color_text("Simulation Tools installation is not implemented yet", color='red'))
elif answers['choice'] == 'Robot Configuration':
print(TerminalFormatter.color_text("Robot Configuration installation is not implemented yet", color='red'))

elif install_type == 'Maintainer':
workspace.create_maintainer_workspace(platform, params, args)
elif install_type == 'Simple':
print(TerminalFormatter.color_text(f"Not implemented yet {device_type}", color='red'))

def main():
# Load the parameters
Expand Down
4 changes: 1 addition & 3 deletions src/nanosaur/ros.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
NANOSAUR_DOCKERFILE_SUFFIX = "nanosaur"


def run_dev_script(platform, params: Params, args):

perception_path = get_workspace_path(params, params['ws_perception_name'])
def run_dev_script(params, perception_path):
isaac_ros_common_path = os.path.join(perception_path, 'src', 'isaac_ros_common')
# Get the path to the Isaac ROS common package
os.chdir(isaac_ros_common_path)
Expand Down
36 changes: 28 additions & 8 deletions src/nanosaur/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,24 @@ def add_workspace_subcommand(name, help_text, func):
# Add workspace clean subcommand
add_workspace_subcommand('clean', "Clean the workspace", clean)
add_workspace_subcommand('update', "Update the workspace", update)
add_workspace_subcommand('run', "Run the workspace", run_developer_workspace)
add_workspace_subcommand('deploy', "Deploy workspace to docker image", deploy)
# Add workspace perception subcommand
parser_workspace_perception = workspace_subparsers.add_parser(
'perception', help="Start the Isaac ROS docker container")
parser_workspace_perception.set_defaults(func=ros.run_dev_script)
return parser_workspace


def run_developer_workspace(platform, params: Params, args, password=None):
if args.workspace is not None:
workspace = args.workspace
else:
workspace = "robot" if platform['Machine'] == 'jetson' else "desktop"

if workspace == 'perception':
perception_ws_name = params['ws_perception_name']
perception_ws_path = get_workspace_path(params, perception_ws_name)
ros.run_dev_script(params, perception_ws_path)
else:
print(TerminalFormatter.color_text(f"I cannot run {workspace}", color='red'))

def get_workspaces_path(params: Params) -> bool:
nanosaur_home_path = get_nanosaur_home(params['nanosaur_home'])
# Add all workspaces that exist in the Nanosaur home folder
Expand All @@ -91,7 +101,7 @@ def get_workspace_path(params: Params, ws_name) -> str:
return None


def create_workspace(nanosaur_home_path, ws_name) -> str:
def create_workspace(nanosaur_home_path, ws_name, skip_create_colcon_setting=False) -> str:
ws_name_path = os.path.join(nanosaur_home_path, ws_name)
ws_name_path_src = os.path.join(ws_name_path, "src")
# Check if folder exists, if not, create it
Expand All @@ -101,8 +111,9 @@ def create_workspace(nanosaur_home_path, ws_name) -> str:
else:
print(TerminalFormatter.color_text(f"Workspace '{ws_name}' already exists.", color='yellow'))
# Save the default colcon settings
with open(f"{ws_name_path}/colcon_defaults.yaml", 'w') as file:
yaml.dump(COLCON_DEFAULTS, file)
if not skip_create_colcon_setting:
with open(f"{ws_name_path}/colcon_defaults.yaml", 'w') as file:
yaml.dump(COLCON_DEFAULTS, file)
return ws_name_path


Expand Down Expand Up @@ -195,6 +206,15 @@ def build_workspace(nanosaur_raw_github_repo, branch, workspace_path, rosinstall
return True


def create_developer_workspace(platform, params: Params, args, password=None):
# Get the Nanosaur home folder and branch
nanosaur_home = params['nanosaur_home']
# Create the Nanosaur home folder
nanosaur_home_path = create_nanosaur_home(nanosaur_home)
# Create developer workspace
create_workspace(nanosaur_home_path, params['ws_developer_name'], skip_create_colcon_setting=True)


@require_sudo_password
def create_maintainer_workspace(platform, params: Params, args, password=None):
# determine the device type
Expand Down Expand Up @@ -243,7 +263,7 @@ def create_maintainer_workspace(platform, params: Params, args, password=None):

# Make the perception workspace
ws_name_path = create_workspace(nanosaur_home_path, params['ws_perception_name'])
build_workspace(branch, ws_name_path, 'perception', password, skip_rosdep=True, skip_build=True)
build_workspace(nanosaur_raw_github_repo, branch, ws_name_path, 'perception', password, skip_rosdep=True, skip_build=True)
# Set params in maintainer mode
params['mode'] = 'maintainer'

Expand Down

0 comments on commit 03e6a9a

Please sign in to comment.