diff --git a/README.md b/README.md index 0351157..11032fe 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,8 @@ sessions: - `-c` or `--config`: Specify the path to the YAML configuration file that defines the hosts, sessions, and other settings. The default configuration file path is "/etc/ros/upstart_robot.yaml." - `-s` or `--sessions`: Optionally, specify which sessions should be started or stopped. You can provide multiple session names as arguments. - `-f` or `--force`: Use this flag to force the closure of sessions, even if they are locked. +- `-l ` or `--logging_level `: Use this flag to set the logging level, ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] +- `--instance_id `: An unique id used to prepend to each session name and used within multi-robot setups. ### YAML Configuration diff --git a/robmuxinator/robmuxinator.py b/robmuxinator/robmuxinator.py index baac798..1be719b 100755 --- a/robmuxinator/robmuxinator.py +++ b/robmuxinator/robmuxinator.py @@ -795,12 +795,19 @@ def main(): default="INFO", help="logging level", ) + parser.add_argument( + "--instance_id", + type=int, + help="an unique id used to prepend to each session name within the config file. used for multi-robot emulation. the instance_id is also exported to the env used within the sessions as well as to guarantee a unique ROS_DOMAIN_ID", + default=0, + ) argcomplete.autocomplete(parser) args = parser.parse_args() # parse arguments yaml_file = args.config command = args.command + instance_id = args.instance_id # set logging level logger.setLevel(level=args.logging_level) @@ -880,6 +887,13 @@ def main(): else: envs = None + # Check if 'instance_id' was given by the user. + # This indicates the a multi-instance setup, e.g. for multi-robot emulation. + # Therefore we export the INSTANCE_ID and use it for to guarantee a unique ROS_DOMAIN_ID + if instance_id != 0: + envs.append(("INSTANCE_ID", instance_id)) + envs.append(("ROS_DOMAIN_ID", instance_id)) + # get sessions from yaml yaml_sessions = None if "sessions" in yaml_content: @@ -911,7 +925,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - key, + str(instance_id) + "_" + key if instance_id != 0 else key, yaml_sessions[key], envs ) @@ -920,7 +934,7 @@ def main(): sessions.append( Session( SSHClient(user=user, hostname=hosts[host].get_hostname(), port=hosts[host].get_ssh_port()), - key, + str(instance_id) + "_" + key if instance_id != 0 else key, yaml_sessions[key], envs )