ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Unfortunately, an str()
method would not be that easy. The LaunchConfiguration
is a Substitutible
object, and doesn't derive from str
You're going to need to use the launch.actions.OpaqueFunction
action as it will give you a LaunchContext
object from which you can perform substitutions:
from pathlib import Path
from launch import LaunchDescription, LaunchContext, LaunchService
from launch.actions import OpaqueFunction, DeclareLaunchArgument, ExecuteProcess
from launch.substitutions import LaunchConfiguration
robot_description_path = Path('destination.urdf')
def render_xacro(context: LaunchContext, support_package):
support_package_str = context.perform_substitution(support_package)
# render xacro... just dumping the support_package value in there for example.
robot_description_config = support_package_str
robot_description_path.write_text(robot_description_config)
print(f'wrote robot description to {robot_description_path}')
def generate_launch_description():
return LaunchDescription([
DeclareLaunchArgument('support_package', default_value='hello'),
OpaqueFunction(function=render_xacro, args=[LaunchConfiguration('support_package')]),
ExecuteProcess(cmd=['cat', str(robot_description_path)],
output='screen'),
])
if __name__ == '__main__':
ls = LaunchService()
ls.include_launch_description(generate_launch_description())
ls.run()
which outputs:
[INFO] [launch]: Default logging verbosity is set to INFO
wrote robot description to destination.urdf
[INFO] [cat-1]: process started with pid [31440]
[INFO] [cat-1]: process has finished cleanly [pid 31440]
[cat-1] hello