Skip to content

Commit

Permalink
Refactor bringup and process settings configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossvg committed Jun 27, 2021
1 parent c5344aa commit 4755a89
Show file tree
Hide file tree
Showing 18 changed files with 455 additions and 319 deletions.
54 changes: 54 additions & 0 deletions pendulum_bringup/launch/controller_bringup.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2019 Carlos San Vicente
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
import launch.substitutions
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


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

# Set parameter file path
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])

with_controller_param = DeclareLaunchArgument(
'controller',
default_value='True',
description='Launch controller node'
)

# Node definitions
pendulum_controller_runner = Node(
package='pendulum_controller',
executable='pendulum_controller_exe',
output='screen',
parameters=[param_file],
arguments=[],
condition=IfCondition(LaunchConfiguration('controller'))
)

ld = LaunchDescription()
ld.add_action(with_controller_param)
ld.add_action(pendulum_controller_runner)

return ld
53 changes: 53 additions & 0 deletions pendulum_bringup/launch/driver_bringup.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2019 Carlos San Vicente
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
import launch.substitutions
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


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

# Set parameter file path
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])

with_driver_param = DeclareLaunchArgument(
'driver',
default_value='True',
description='Launch driver node'
)

pendulum_driver_runner = Node(
package='pendulum_driver',
executable='pendulum_driver_exe',
output='screen',
parameters=[param_file],
arguments=[],
condition=IfCondition(LaunchConfiguration('driver'))
)

ld = LaunchDescription()
ld.add_action(pendulum_driver_runner)
ld.add_action(with_driver_param)

return ld
107 changes: 11 additions & 96 deletions pendulum_bringup/launch/pendulum_bringup.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,112 +15,27 @@
import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
import launch.substitutions
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare

from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource

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

# Set robot description parameters
urdf_file = os.path.join(bringup_dir, 'urdf', 'pendulum.urdf')
with open(urdf_file, 'r') as infp:
robot_desc = infp.read()
rsp_params = {'robot_description': robot_desc}

# Set parameter file path
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])

# Set rviz config path
rviz_cfg_path = os.path.join(bringup_dir, 'rviz/pendulum.rviz')

# Create the launch configuration variables
autostart_param = DeclareLaunchArgument(
name='autostart',
default_value='True',
description='Automatically start lifecycle nodes')
priority_param = DeclareLaunchArgument(
name='priority',
default_value='0',
description='Set process priority')
cpu_affinity_param = DeclareLaunchArgument(
name='cpu-affinity',
default_value='0',
description='Set process CPU affinity')
with_lock_memory_param = DeclareLaunchArgument(
name='lock-memory',
default_value='False',
description='Lock the process memory')
lock_memory_size_param = DeclareLaunchArgument(
name='lock-memory-size',
default_value='0',
description='Set lock memory size in MB')
config_child_threads_param = DeclareLaunchArgument(
name='config-child-threads',
default_value='False',
description='Configure process child threads (typically DDS threads)')
with_rviz_param = DeclareLaunchArgument(
'rviz',
default_value='False',
description='Launch RVIZ2 in addition to other nodes'
rviz_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([bringup_dir, '/launch/rviz.launch.py'])
)

# Node definitions
pendulum_demo_runner = Node(
package='pendulum_demo',
executable='pendulum_demo_waitset',
output='screen',
parameters=[param_file],
arguments=[
'--autostart', LaunchConfiguration('autostart'),
'--priority', LaunchConfiguration('priority'),
'--cpu-affinity', LaunchConfiguration('cpu-affinity'),
'--lock-memory', LaunchConfiguration('lock-memory'),
'--lock-memory-size', LaunchConfiguration('lock-memory-size'),
'--config-child-threads', LaunchConfiguration('config-child-threads')
]
controller_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([bringup_dir, '/launch/controller.launch.py'])
)

robot_state_publisher_runner = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[rsp_params],
condition=IfCondition(LaunchConfiguration('rviz'))
)

rviz_runner = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=['-d', str(rviz_cfg_path)],
condition=IfCondition(LaunchConfiguration('rviz'))
)

pendulum_state_publisher_runner = Node(
package='pendulum_state_publisher',
executable='pendulum_state_publisher',
condition=IfCondition(LaunchConfiguration('rviz'))
driver_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([bringup_dir, '/launch/driver.launch.py'])
)

ld = LaunchDescription()

ld.add_action(autostart_param)
ld.add_action(priority_param)
ld.add_action(cpu_affinity_param)
ld.add_action(with_lock_memory_param)
ld.add_action(lock_memory_size_param)
ld.add_action(config_child_threads_param)
ld.add_action(with_rviz_param)
ld.add_action(robot_state_publisher_runner)
ld.add_action(pendulum_demo_runner)
ld.add_action(rviz_runner)
ld.add_action(pendulum_state_publisher_runner)
ld.add_action(controller_launch)
ld.add_action(driver_launch)
ld.add_action(rviz_launch)

return ld
46 changes: 45 additions & 1 deletion pendulum_bringup/launch/pendulum_bringup_rviz.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,49 @@ def generate_launch_description():
default_value='False',
description='Launch RVIZ2 in addition to other nodes'
)
with_controller_param = DeclareLaunchArgument(
'controller',
default_value='True',
description='Launch controller node'
)
with_driver_param = DeclareLaunchArgument(
'driver',
default_value='True',
description='Launch driver node'
)

# Node definitions
pendulum_controller_runner = Node(
package='pendulum_controller',
executable='pendulum_controller_exe',
output='screen',
parameters=[param_file],
arguments=[
'--autostart', LaunchConfiguration('autostart'),
'--priority', LaunchConfiguration('priority'),
'--cpu-affinity', LaunchConfiguration('cpu-affinity'),
'--lock-memory', LaunchConfiguration('lock-memory'),
'--lock-memory-size', LaunchConfiguration('lock-memory-size'),
'--config-child-threads', LaunchConfiguration('config-child-threads')
],
condition=IfCondition(LaunchConfiguration('controller'))
)

pendulum_driver_runner = Node(
package='pendulum_driver',
executable='pendulum_driver_exe',
output='screen',
parameters=[param_file],
arguments=[
'--autostart', LaunchConfiguration('autostart'),
'--priority', LaunchConfiguration('priority'),
'--cpu-affinity', LaunchConfiguration('cpu-affinity'),
'--lock-memory', LaunchConfiguration('lock-memory'),
'--lock-memory-size', LaunchConfiguration('lock-memory-size'),
'--config-child-threads', LaunchConfiguration('config-child-threads')
],
condition=IfCondition(LaunchConfiguration('driver'))
)

robot_state_publisher_runner = Node(
package='robot_state_publisher',
Expand Down Expand Up @@ -104,8 +145,11 @@ def generate_launch_description():
ld.add_action(lock_memory_size_param)
ld.add_action(config_child_threads_param)
ld.add_action(with_rviz_param)
ld.add_action(with_controller_param)
ld.add_action(with_driver_param)
ld.add_action(robot_state_publisher_runner)
#ld.add_action(pendulum_demo_runner)
ld.add_action(pendulum_controller_runner)
ld.add_action(pendulum_driver_runner)
ld.add_action(rviz_runner)
ld.add_action(pendulum_state_publisher_runner)

Expand Down
79 changes: 79 additions & 0 deletions pendulum_bringup/launch/rviz.launch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2019 Carlos San Vicente
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition
import launch.substitutions
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node
from launch_ros.substitutions import FindPackageShare


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

# Set robot description parameters
urdf_file = os.path.join(bringup_dir, 'urdf', 'pendulum.urdf')
with open(urdf_file, 'r') as infp:
robot_desc = infp.read()
rsp_params = {'robot_description': robot_desc}

# Set parameter file path
param_file_path = os.path.join(bringup_dir, 'params', 'pendulum.param.yaml')
param_file = launch.substitutions.LaunchConfiguration('params', default=[param_file_path])

# Set rviz config path
rviz_cfg_path = os.path.join(bringup_dir, 'rviz/pendulum.rviz')

# Create the launch configuration variables
with_rviz_param = DeclareLaunchArgument(
'rviz',
default_value='False',
description='Launch RVIZ2 in addition to other nodes'
)

robot_state_publisher_runner = Node(
package='robot_state_publisher',
executable='robot_state_publisher',
output='screen',
parameters=[rsp_params],
condition=IfCondition(LaunchConfiguration('rviz'))
)

rviz_runner = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
arguments=['-d', str(rviz_cfg_path)],
condition=IfCondition(LaunchConfiguration('rviz'))
)

pendulum_state_publisher_runner = Node(
package='pendulum_state_publisher',
executable='pendulum_state_publisher',
condition=IfCondition(LaunchConfiguration('rviz'))
)

ld = LaunchDescription()

ld.add_action(with_rviz_param)
ld.add_action(robot_state_publisher_runner)
ld.add_action(rviz_runner)
ld.add_action(pendulum_state_publisher_runner)

return ld
Loading

0 comments on commit 4755a89

Please sign in to comment.