Skip to content

Commit

Permalink
Added arguments launch_ru|dcs and log_redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
nhjschulz committed Aug 28, 2024
1 parent 10ac060 commit 46ee7cc
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 17 deletions.
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ build only this package (and in verbose mode) use:

The `ros2_dcs_turtlesim` includes a launch configuration. Run it using

ros2 launch ros2_dcs_turtlesim dcs_launch.py [world:=<path-to-world-file>] [launch_webots:=true|false]
ros2 launch ros2_dcs_turtlesim dcs_launch.py [args]

Running with launch_webots:=false only runs the external controllers. This is usefull after a reload
of the world. Default is to launch webots as well.
The default world file is is set to worlds/minimal/DcsMinimal.wbt.
Supported launcher arguments:

| Argument | Default | Description |
|---------------|----------------------|----------------------|
|world|world:=worlds/minimal/DcsMinimal.wbt| Launch Webots with given world file.|
|launch_webots|launch_webots:=true| Enable/Disable launch of Webots.|
|launch_ru|launch_ru:=true| Enable/Disable launch of RadonUlzer controller.|
|launch_dcs|launch_dcs:=true| Enable/Disable launch of DroidControlShip controller.|
|log_redirect|log_redirect:=false| Enable/Disable output redirection to Webots console.|
72 changes: 59 additions & 13 deletions launch/dcs_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,66 @@ def arg_to_bool(arg):
return False


def generate_launch_description():
"""Launch all components necessary for this demo."""
def handle_arguments(args: list[str]) -> argparse.Namespace:
"""Process launcher specific arguments."""
package_dir = get_package_share_directory('ros2_dcs_turtlesim')
wb_ros_ctrl_dir = get_package_share_directory('webots_ros2_driver')

arg_parser = argparse.ArgumentParser()

arg_parser.add_argument(
'--world',
action='store',
type=str,
required=False,
default=os.path.join(package_dir, 'worlds', 'minimal', 'DcsMinimal.wbt')
)

arg_parser.add_argument(
'--launch_webots',
type=arg_to_bool,
nargs='?',
const=True,
default=True,
required=False,
help='Enable/disble launch of Webots process.'
)

arg_parser.add_argument(
'--launch_ru',
type=arg_to_bool,
nargs='?',
const=True,
default=True,
required=False,
help='Enable/disable launch of RadonUlzer process.'
)

arg_parser.add_argument(
'--launch_dcs',
type=arg_to_bool,
nargs='?',
const=True,
default=True,
required=False,
help='Enable/disable launch of DroidControlShip process.'
)

arg_parser.add_argument(
'--log_redirect',
type=arg_to_bool,
nargs='?',
const=True,
default=False,
required=False,
)
launch_args = sys.argv[4:] # 4th+ arguments are the launcher specifc arguments
argv = [f"--{arg.replace(':=', '=')}" for arg in launch_args] # ros2 arg:=val tp --arg=val
my_args = arg_parser.parse_args(argv)

python_args = [f"--{arg.replace(':=', '=')}" for arg in args] # ros2 arg:=val to --arg=val
return arg_parser.parse_args(python_args)


def generate_launch_description():
"""Launch all components necessary for this demo."""
my_args = handle_arguments(sys.argv[4:]) # 4th+ are the launcher specifc.

dcs_home = os.getenv('DCS_HOME')
ru_home = os.getenv('RU_HOME')
Expand All @@ -90,7 +126,12 @@ def generate_launch_description():
sys.exit('RU_HOME environment variable not set.')

wb_ctrl_path = gen_exe_path(
os.path.join(wb_ros_ctrl_dir, 'scripts', 'webots-controller'))
os.path.join(
get_package_share_directory('webots_ros2_driver'),
'scripts',
'webots-controller')
)

if not os.path.isfile(wb_ctrl_path):
sys.exit(f'webots_controller program not found in {wb_ctrl_path}')

Expand All @@ -110,11 +151,14 @@ def generate_launch_description():
#
webots = WebotsLauncher(world=my_args.world)

wb_controller_cmd = [wb_ctrl_path]
if my_args.log_redirect:
wb_controller_cmd += ['--stdout-redirect', '--stderr-redirect']

# DroidControlship Launcher
#
dcs_controller = ExecuteProcess(
cmd=[
wb_ctrl_path,
cmd=wb_controller_cmd + [
'--robot-name=ZumoComSystem',
dcs_path,
'--cfgFilePath',
Expand All @@ -126,8 +170,7 @@ def generate_launch_description():
# RadonUlzer Launcher
#
ru_controller = ExecuteProcess(
cmd=[
wb_ctrl_path,
cmd=wb_controller_cmd + [
'--robot-name=Zumo',
ru_path,
],
Expand All @@ -150,7 +193,10 @@ def generate_launch_description():
)
)

actions.append(dcs_controller)
actions.append(ru_controller)
if my_args.launch_dcs:
actions.append(dcs_controller)

if my_args.launch_ru:
actions.append(ru_controller)

return LaunchDescription(actions)

0 comments on commit 46ee7cc

Please sign in to comment.