Accessing and manipulating launch.substitution values
Greetings. I want to build a utility spawner for a robot sim in Gazebo. The spawner should also allow for appropriate namespaces, in order to be able to spawn multiples of the same robot/entity within the simulation. For each entity some basic nodes are required:
- spawn_entity_node.py (My Gazebo spawn node)
- ros2_control_node (For ros2_control)
- spawner.py (From ros2_control to spawn all defined controllers)
- robot_state_publisher (For building the /tf)
Therefore, I created a Python launch file for spawning a single entity. In order to access the values of the given launch arguments (DeclareLaunchArgument
) I run LaunchConfiguration.perform(context)
within a outsourced launch_setup
via OpaqueFunction
like jrgnicho. This works for LaunchConfigurations
, however in order to set the namespaces like TheConstruct I have to manipulate the URDF.
Perhaps I will pursue the direct method with writing namespaces into the URDF when creating it via xacro.
However, out of curiosity: Is there a way to access the output of launch.substitutions.Command
?
launch.substitutions.Command
also exposes perform(context)
, but it leads to the following traceback, and I do not know why it tries to search for a package with an instance of LaunchConfiguraton
, it does not make a lot of sense to me to be frank.
future: <Task finished name='Task-2' coro=<LaunchService._process_one_event() done, defined at /opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py:226> exception=PackageNotFoundError("package '<launch.substitutions.launch_configuration.LaunchConfiguration object at 0x7f971af526a0>' not found, searching: ['/root/ros2_ws/install/ros_foxy_utility_code', '/root/ros2_ws/install/ur_simulation_gazebo', '/root/ros2_ws/install/ur_robot_driver', '/root/ros2_ws/install/ur_controllers', '/root/ros2_ws/install/ur_msgs', '/root/ros2_ws/install/ur_moveit_config', '/root/ros2_ws/install/modprof_bringup', '/root/ros2_ws/install/ur_description', '/root/ros2_ws/install/ur_dashboard_msgs', '/root/ros2_ws/install/ur_bringup', '/root/ros2_ws/install/srdfdom', '/root/ros2_ws/install/modprof_moveit', '/root/ros2_ws/install/modprof_models', '/root/ros2_ws/install/modprof_cv', '/root/ros2_ws/install/control_msgs', '/opt/ros/foxy']")>
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/packages.py", line 50, in get_package_prefix
content, package_prefix = get_resource('packages', package_name)
File "/opt/ros/foxy/lib/python3.8/site-packages/ament_index_python/resources.py", line 48, in get_resource
raise LookupError(
LookupError: Could not find the resource '<launch.substitutions.launch_configuration.LaunchConfiguration object at 0x7f971af526a0>' of type 'packages'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 228, in _process_one_event
await self.__process_event(next_event)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/launch_service.py", line 248, in __process_event
visit_all_entities_and_collect_futures(entity, self.__context))
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 45, in visit_all_entities_and_collect_futures
futures_to_return += visit_all_entities_and_collect_futures(sub_entity, context)
[Previous line repeated 8 more times]
File "/opt/ros/foxy/lib/python3.8/site-packages/launch/utilities/visit_all_entities_and_collect_futures_impl.py", line 38, in visit_all_entities_and_collect_futures
sub_entities = entity.visit(context)
File ...