1111import argparse
1212
1313import rclpy
14- from rclpy .node import Node
1514from gymnasium .spaces import Discrete
15+ from rclpy .node import Node
1616from stable_baselines3 .common .base_class import BaseAlgorithm
1717
1818from pyrobosim_ros_gym import get_config
1919from pyrobosim_ros_gym .envs import available_envs_w_subtype , get_env_by_name
2020from pyrobosim_ros_gym .policies import ManualPolicy , model_and_env_type_from_path
2121
22+ MANUAL_STR = "manual"
23+
2224
2325def get_args () -> argparse .Namespace :
2426 """Helper function to parse the command-line arguments."""
2527 parser = argparse .ArgumentParser ()
2628 parser .add_argument (
2729 "--model" ,
2830 type = str ,
29- help = "The name of the model to evaluate. Can be 'manual ' for manual control." ,
31+ help = f "The path of the model to evaluate. Can be '{ MANUAL_STR } ' for manual control." ,
3032 )
3133 parser .add_argument (
3234 "--env" ,
3335 type = str ,
34- help = "The name of the environment to use if '--model manual ' is selected." ,
36+ help = f "The name of the environment to use if '--model { MANUAL_STR } ' is selected." ,
3537 choices = available_envs_w_subtype (),
3638 )
3739 parser .add_argument (
@@ -50,6 +52,13 @@ def get_args() -> argparse.Namespace:
5052 "--realtime" , action = "store_true" , help = "If true, slows down to real time."
5153 )
5254 args = parser .parse_args ()
55+
56+ # Ensure '--env' is provided if '--model' is 'manual'
57+ if args .model == MANUAL_STR and not args .env :
58+ parser .error (f"--env must be specified when --model is '{ MANUAL_STR } '." )
59+ if args .env and args .model is None :
60+ print ("--env is specified but --model is not. Defaulting to manual control." )
61+ args .model = MANUAL_STR
5362 return args
5463
5564
@@ -62,7 +71,7 @@ def get_args() -> argparse.Namespace:
6271
6372 # Load the model and environment
6473 model : BaseAlgorithm | ManualPolicy
65- if args .model == "manual" :
74+ if args .model == MANUAL_STR :
6675 env = get_env_by_name (
6776 args .env ,
6877 node ,
0 commit comments