|
1 | 1 | """Launch nodes for this launch profile.""" |
2 | 2 |
|
| 3 | +from pathlib import Path |
| 4 | + |
3 | 5 | from launch import LaunchDescription |
4 | 6 | from launch_ros.actions import Node |
5 | 7 |
|
| 8 | +# Import the forklift URDF module so it register itself with the URDFConstants |
| 9 | +from node_helpers import launching |
| 10 | +from node_helpers.parameters import ParameterLoader |
| 11 | +from pydantic import BaseModel |
| 12 | + |
| 13 | + |
| 14 | +class MetaParameters(BaseModel): |
| 15 | + """This is a great place to put parameters that affect the generation of the launch |
| 16 | + file. Don't put node specific configuration in here, rather, put configuration for |
| 17 | + what nodes you want to be created in the first place. |
| 18 | +
|
| 19 | + Read more about this functionality under docs/parameters.rst |
| 20 | + """ |
| 21 | + |
| 22 | + urdf_modules_to_load: list[launching.URDFModuleNodeFactory.Parameters] |
| 23 | + """This is an example of dynamically loading an arbitrary number of URDFs. |
| 24 | +
|
| 25 | + This is set in the `/robot/launch-profile/parameters.yaml` under `meta_parameters`. |
| 26 | + """ |
| 27 | + |
6 | 28 |
|
7 | 29 | def generate_launch_description() -> LaunchDescription: |
8 | | - rviz_config = "/robot/launch-profile/rviz-config.rviz" |
| 30 | + # Create a parameter loader to parse all yaml files in the launch-profile/parameters |
| 31 | + # directory, and then apply overrides from the override file, if one exists. |
| 32 | + param_loader: ParameterLoader[MetaParameters] = ParameterLoader( |
| 33 | + parameters_directory=Path("/robot/launch-profile/parameters/"), |
| 34 | + override_file=Path("/robot/launch-profile/parameters.override.yaml"), |
| 35 | + meta_parameters_schema=MetaParameters, |
| 36 | + ) |
| 37 | + |
| 38 | + rviz_config = launching.required_file("/robot/launch-profile/rviz-config.rviz") |
| 39 | + |
| 40 | + urdf_node_factories = ( |
| 41 | + launching.URDFModuleNodeFactory(parameters=node_factory_params) |
| 42 | + for node_factory_params in param_loader.meta_parameters.urdf_modules_to_load |
| 43 | + ) |
| 44 | + urdf_nodes = [] |
| 45 | + for urdf_node_factory in urdf_node_factories: |
| 46 | + urdf_nodes += urdf_node_factory.create_nodes() |
| 47 | + |
9 | 48 | launch_description = [ |
10 | | - Node(package="rviz2", executable="rviz2", arguments=["-d", [rviz_config]]), |
| 49 | + *urdf_nodes, |
| 50 | + Node( |
| 51 | + package="node_helpers", |
| 52 | + executable="run_ExampleNode", |
| 53 | + name="ExampleNode", |
| 54 | + parameters=[param_loader.ros_parameters_file], |
| 55 | + namespace="example_node_namespace", |
| 56 | + ), |
| 57 | + Node( |
| 58 | + package="rviz2", |
| 59 | + executable="rviz2", |
| 60 | + arguments=["-d", [str(rviz_config)]], |
| 61 | + ), |
| 62 | + Node( |
| 63 | + namespace="urdf_arrangement", |
| 64 | + package="node_helpers", |
| 65 | + executable="interactive_transform_publisher", |
| 66 | + parameters=[param_loader.ros_parameters_file], |
| 67 | + ), |
11 | 68 | ] |
12 | 69 | return LaunchDescription(launch_description) |
0 commit comments