Skip to content

Commit d873a54

Browse files
committed
Refactor bringup and process settings configuration
1 parent c5344aa commit d873a54

22 files changed

+591
-427
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2019 Carlos San Vicente
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
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+
from launch_ros.substitutions import FindPackageShare
24+
25+
26+
def generate_launch_description():
27+
# Get the bringup directory
28+
bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup')
29+
30+
# Set parameter file path
31+
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
32+
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])
33+
34+
with_controller_param = DeclareLaunchArgument(
35+
'controller',
36+
default_value='True',
37+
description='Launch controller node'
38+
)
39+
40+
# Node definitions
41+
pendulum_controller_runner = Node(
42+
package='pendulum_controller',
43+
executable='pendulum_controller_exe',
44+
output='screen',
45+
parameters=[param_file],
46+
arguments=[],
47+
condition=IfCondition(LaunchConfiguration('controller'))
48+
)
49+
50+
ld = LaunchDescription()
51+
ld.add_action(with_controller_param)
52+
ld.add_action(pendulum_controller_runner)
53+
54+
return ld
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2019 Carlos San Vicente
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
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+
from launch_ros.substitutions import FindPackageShare
24+
25+
26+
def generate_launch_description():
27+
# Get the bringup directory
28+
bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup')
29+
30+
# Set parameter file path
31+
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
32+
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])
33+
34+
with_driver_param = DeclareLaunchArgument(
35+
'driver',
36+
default_value='True',
37+
description='Launch driver node'
38+
)
39+
40+
pendulum_driver_runner = Node(
41+
package='pendulum_driver',
42+
executable='pendulum_driver_exe',
43+
output='screen',
44+
parameters=[param_file],
45+
arguments=[],
46+
condition=IfCondition(LaunchConfiguration('driver'))
47+
)
48+
49+
ld = LaunchDescription()
50+
ld.add_action(with_driver_param)
51+
ld.add_action(pendulum_driver_runner)
52+
53+
return ld

pendulum_bringup/launch/pendulum_bringup.launch.py

Lines changed: 11 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,112 +15,27 @@
1515
import os
1616

1717
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
2318
from launch_ros.substitutions import FindPackageShare
24-
19+
from launch.actions import IncludeLaunchDescription
20+
from launch.launch_description_sources import PythonLaunchDescriptionSource
2521

2622
def generate_launch_description():
2723
# Get the bringup directory
2824
bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup')
2925

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'])
7228
)
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_bringup.launch.py'])
8831
)
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_bringup.launch.py'])
11034
)
11135

11236
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)
12540

12641
return ld

pendulum_bringup/launch/pendulum_bringup_rviz.launch.py

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,49 @@ def generate_launch_description():
7070
default_value='False',
7171
description='Launch RVIZ2 in addition to other nodes'
7272
)
73+
with_controller_param = DeclareLaunchArgument(
74+
'controller',
75+
default_value='True',
76+
description='Launch controller node'
77+
)
78+
with_driver_param = DeclareLaunchArgument(
79+
'driver',
80+
default_value='True',
81+
description='Launch driver node'
82+
)
7383

7484
# Node definitions
85+
pendulum_controller_runner = Node(
86+
package='pendulum_controller',
87+
executable='pendulum_controller_exe',
88+
output='screen',
89+
parameters=[param_file],
90+
arguments=[
91+
'--autostart', LaunchConfiguration('autostart'),
92+
'--priority', LaunchConfiguration('priority'),
93+
'--cpu-affinity', LaunchConfiguration('cpu-affinity'),
94+
'--lock-memory', LaunchConfiguration('lock-memory'),
95+
'--lock-memory-size', LaunchConfiguration('lock-memory-size'),
96+
'--config-child-threads', LaunchConfiguration('config-child-threads')
97+
],
98+
condition=IfCondition(LaunchConfiguration('controller'))
99+
)
100+
101+
pendulum_driver_runner = Node(
102+
package='pendulum_driver',
103+
executable='pendulum_driver_exe',
104+
output='screen',
105+
parameters=[param_file],
106+
arguments=[
107+
'--autostart', LaunchConfiguration('autostart'),
108+
'--priority', LaunchConfiguration('priority'),
109+
'--cpu-affinity', LaunchConfiguration('cpu-affinity'),
110+
'--lock-memory', LaunchConfiguration('lock-memory'),
111+
'--lock-memory-size', LaunchConfiguration('lock-memory-size'),
112+
'--config-child-threads', LaunchConfiguration('config-child-threads')
113+
],
114+
condition=IfCondition(LaunchConfiguration('driver'))
115+
)
75116

76117
robot_state_publisher_runner = Node(
77118
package='robot_state_publisher',
@@ -104,8 +145,11 @@ def generate_launch_description():
104145
ld.add_action(lock_memory_size_param)
105146
ld.add_action(config_child_threads_param)
106147
ld.add_action(with_rviz_param)
148+
ld.add_action(with_controller_param)
149+
ld.add_action(with_driver_param)
107150
ld.add_action(robot_state_publisher_runner)
108-
#ld.add_action(pendulum_demo_runner)
151+
ld.add_action(pendulum_controller_runner)
152+
ld.add_action(pendulum_driver_runner)
109153
ld.add_action(rviz_runner)
110154
ld.add_action(pendulum_state_publisher_runner)
111155

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright 2019 Carlos San Vicente
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
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+
from launch_ros.substitutions import FindPackageShare
24+
25+
26+
def generate_launch_description():
27+
# Get the bringup directory
28+
bringup_dir = FindPackageShare('pendulum_bringup').find('pendulum_bringup')
29+
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+
with_rviz_param = DeclareLaunchArgument(
45+
'rviz',
46+
default_value='False',
47+
description='Launch RVIZ2 in addition to other nodes'
48+
)
49+
50+
robot_state_publisher_runner = Node(
51+
package='robot_state_publisher',
52+
executable='robot_state_publisher',
53+
output='screen',
54+
parameters=[rsp_params],
55+
condition=IfCondition(LaunchConfiguration('rviz'))
56+
)
57+
58+
rviz_runner = Node(
59+
package='rviz2',
60+
executable='rviz2',
61+
name='rviz2',
62+
arguments=['-d', str(rviz_cfg_path)],
63+
condition=IfCondition(LaunchConfiguration('rviz'))
64+
)
65+
66+
pendulum_state_publisher_runner = Node(
67+
package='pendulum_state_publisher',
68+
executable='pendulum_state_publisher',
69+
condition=IfCondition(LaunchConfiguration('rviz'))
70+
)
71+
72+
ld = LaunchDescription()
73+
74+
ld.add_action(with_rviz_param)
75+
ld.add_action(robot_state_publisher_runner)
76+
ld.add_action(rviz_runner)
77+
ld.add_action(pendulum_state_publisher_runner)
78+
79+
return ld

0 commit comments

Comments
 (0)