I am using ROS2 Humble and Ubuntu 22.04. My aim is to create one launch file which could run multiple launch files and nodes like nav2 and rtabmap and some others. The problem is that default parameters in launch files are ignored and not used when launched from collective launch file
For example, I have main launch file autonomy_localization.launch.py
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
from launch.actions import RegisterEventHandler, DeclareLaunchArgument, SetEnvironmentVariable, IncludeLaunchDescription, TimerAction, GroupAction
from launch.substitutions import LaunchConfiguration, TextSubstitution
from launch.conditions import IfCondition, UnlessCondition
from launch_ros.actions import Node
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch_xml.launch_description_sources import XMLLaunchDescriptionSource
from launch.event_handlers import OnExecutionComplete
from launch_ros.actions import PushRosNamespace
def generate_launch_description():
basic_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_autonomy'), 'launch'),
'/basic_launch.py']))
sensors_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_autonomy'), 'launch'),
'/sensors_launch.py']))
control_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_control'), 'launch'),
'/diffbot.launch.py']))
twist_mux_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_autonomy'), 'launch'),
'/tmux_launch.py']))
rtabmap_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_autonomy'), 'launch'),
'/rtabmap_mapping_launch.py']),
launch_arguments={'frame_id':'base_link'}.items(),
)
nav2_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('robot_autonomy'), 'launch'),
'/navigation_launch.py']),)
vizanti_include = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(
get_package_share_directory('vizanti_server'), 'launch'),
'/vizanti_server.launch.py']))
stag_include = IncludeLaunchDescription(XMLLaunchDescriptionSource([os.path.join(
get_package_share_directory('stag_ros'), 'launch'),
'/stagNode.launch']))
tag_marker_node = Node(
package='tag_marker',
executable='marker',
name='tag_marker'
)
vesc_service = Node(
package='vesc_service',
executable='service',
name='vesc_service'
)
micro_ros_agent = Node(
package= 'micro_ros_agent',
executable= 'micro_ros_agent',
name='micro_ros_agent',
arguments=["serial","--dev", "/dev/serial/by-path/pci-0000:00:14.0-usb-0:3.3:1.0-port0"]
)
return LaunchDescription([
#include nav2 launch
basic_include,
sensors_include,
twist_mux_include,
vizanti_include,
# nav2_include,
# tag_marker_node,
vesc_service,
# micro_ros_agent,
TimerAction(period= 5.0, actions= [(micro_ros_agent)]),
TimerAction(period= 5.0, actions= [(stag_include)]),
TimerAction(period= 5.0, actions= [(tag_marker_node)]),
TimerAction(period= 5.0, actions= [(control_include)]),
TimerAction(period= 5.0, actions= [(nav2_include)]),
TimerAction(period= 10.0, actions= [(rtabmap_include)]),
rtabmap launch file, which I included above, has declared default values as
DeclareLaunchArgument('frame_id', default_value='base_link', description='Fixed frame id of the robot (base frame), you may set "base_link" or "base_footprint" if they are published. For camera-only config, this could be "camera_link".'),
DeclareLaunchArgument('namespace', default_value='rtabmap', description=''),
but when launch from autonomy_localization.launch.py
, default values are ignored. Topics are not in the namespace and frame_id
is set to laser_link
which is set in previous launch file named sensors_launch.py
rplidar_launch = IncludeLaunchDescription(
PythonLaunchDescriptionSource([str(rplidar_launch_src), '/rplidar_a2m8_launch.py']),
launch_arguments={'frame_id': 'laser_link', 'serial_port': '/dev/laser_usb', 'scan_mode':'Standard'}.items(),
)
So default parameters are not used and if any parameter with the same name was set before in other launch file it influenced next files.
Second example involves parameters included in navigation_launch.py
where there is a yaml
file included with parameters for nav2
. But when launched from main launch autonomy_localization.launch.py
, the yaml file is ignored and navigation does not start
because of lack of parameters.
I don't know how to do it properly. I will be thankful for pointing my mistake, because I would love to change current launching from tmux script to ros2 launch file.