|
15 | 15 | import os |
16 | 16 |
|
17 | 17 | from launch import LaunchDescription |
18 | | -from launch.actions import DeclareLaunchArgument |
19 | | -from launch.conditions import IfCondition |
20 | | -import launch.substitutions |
21 | | -from launch.substitutions import LaunchConfiguration |
22 | | -from launch_ros.actions import Node |
23 | 18 | from launch_ros.substitutions import FindPackageShare |
24 | | - |
| 19 | +from launch.actions import IncludeLaunchDescription |
| 20 | +from launch.launch_description_sources import PythonLaunchDescriptionSource |
25 | 21 |
|
26 | 22 | def generate_launch_description(): |
27 | 23 | # Get the bringup directory |
28 | 24 | bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup') |
29 | 25 |
|
30 | | - # Set robot description parameters |
31 | | - urdf_file = os.path.join(bringup_dir, 'urdf', 'pendulum.urdf') |
32 | | - with open(urdf_file, 'r') as infp: |
33 | | - robot_desc = infp.read() |
34 | | - rsp_params = {'robot_description': robot_desc} |
35 | | - |
36 | | - # Set parameter file path |
37 | | - param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml') |
38 | | - param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path]) |
39 | | - |
40 | | - # Set rviz config path |
41 | | - rviz_cfg_path = os.path.join(bringup_dir, 'rviz/pendulum.rviz') |
42 | | - |
43 | | - # Create the launch configuration variables |
44 | | - autostart_param = DeclareLaunchArgument( |
45 | | - name='autostart', |
46 | | - default_value='True', |
47 | | - description='Automatically start lifecycle nodes') |
48 | | - priority_param = DeclareLaunchArgument( |
49 | | - name='priority', |
50 | | - default_value='0', |
51 | | - description='Set process priority') |
52 | | - cpu_affinity_param = DeclareLaunchArgument( |
53 | | - name='cpu-affinity', |
54 | | - default_value='0', |
55 | | - description='Set process CPU affinity') |
56 | | - with_lock_memory_param = DeclareLaunchArgument( |
57 | | - name='lock-memory', |
58 | | - default_value='False', |
59 | | - description='Lock the process memory') |
60 | | - lock_memory_size_param = DeclareLaunchArgument( |
61 | | - name='lock-memory-size', |
62 | | - default_value='0', |
63 | | - description='Set lock memory size in MB') |
64 | | - config_child_threads_param = DeclareLaunchArgument( |
65 | | - name='config-child-threads', |
66 | | - default_value='False', |
67 | | - description='Configure process child threads (typically DDS threads)') |
68 | | - with_rviz_param = DeclareLaunchArgument( |
69 | | - 'rviz', |
70 | | - default_value='False', |
71 | | - description='Launch RVIZ2 in addition to other nodes' |
| 26 | + rviz_launch = IncludeLaunchDescription( |
| 27 | + PythonLaunchDescriptionSource([bringup_dir, '/launch/rviz.launch.py']) |
72 | 28 | ) |
73 | | - |
74 | | - # Node definitions |
75 | | - pendulum_demo_runner = Node( |
76 | | - package='pendulum_demo', |
77 | | - executable='pendulum_demo_waitset', |
78 | | - output='screen', |
79 | | - parameters=[param_file], |
80 | | - arguments=[ |
81 | | - '--autostart', LaunchConfiguration('autostart'), |
82 | | - '--priority', LaunchConfiguration('priority'), |
83 | | - '--cpu-affinity', LaunchConfiguration('cpu-affinity'), |
84 | | - '--lock-memory', LaunchConfiguration('lock-memory'), |
85 | | - '--lock-memory-size', LaunchConfiguration('lock-memory-size'), |
86 | | - '--config-child-threads', LaunchConfiguration('config-child-threads') |
87 | | - ] |
| 29 | + controller_launch = IncludeLaunchDescription( |
| 30 | + PythonLaunchDescriptionSource([bringup_dir, '/launch/controller.launch.py']) |
88 | 31 | ) |
89 | | - |
90 | | - robot_state_publisher_runner = Node( |
91 | | - package='robot_state_publisher', |
92 | | - executable='robot_state_publisher', |
93 | | - output='screen', |
94 | | - parameters=[rsp_params], |
95 | | - condition=IfCondition(LaunchConfiguration('rviz')) |
96 | | - ) |
97 | | - |
98 | | - rviz_runner = Node( |
99 | | - package='rviz2', |
100 | | - executable='rviz2', |
101 | | - name='rviz2', |
102 | | - arguments=['-d', str(rviz_cfg_path)], |
103 | | - condition=IfCondition(LaunchConfiguration('rviz')) |
104 | | - ) |
105 | | - |
106 | | - pendulum_state_publisher_runner = Node( |
107 | | - package='pendulum_state_publisher', |
108 | | - executable='pendulum_state_publisher', |
109 | | - condition=IfCondition(LaunchConfiguration('rviz')) |
| 32 | + driver_launch = IncludeLaunchDescription( |
| 33 | + PythonLaunchDescriptionSource([bringup_dir, '/launch/driver.launch.py']) |
110 | 34 | ) |
111 | 35 |
|
112 | 36 | ld = LaunchDescription() |
113 | | - |
114 | | - ld.add_action(autostart_param) |
115 | | - ld.add_action(priority_param) |
116 | | - ld.add_action(cpu_affinity_param) |
117 | | - ld.add_action(with_lock_memory_param) |
118 | | - ld.add_action(lock_memory_size_param) |
119 | | - ld.add_action(config_child_threads_param) |
120 | | - ld.add_action(with_rviz_param) |
121 | | - ld.add_action(robot_state_publisher_runner) |
122 | | - ld.add_action(pendulum_demo_runner) |
123 | | - ld.add_action(rviz_runner) |
124 | | - ld.add_action(pendulum_state_publisher_runner) |
| 37 | + ld.add_action(controller_launch) |
| 38 | + ld.add_action(driver_launch) |
| 39 | + ld.add_action(rviz_launch) |
125 | 40 |
|
126 | 41 | return ld |
0 commit comments