christianrauch / apriltag_ros

ROS2 node for AprilTag detection
MIT License
163 stars 96 forks source link

When launching with include from other launch file the tf topic gets published to /apriltag/tf instead of /tf #4

Closed jonipol closed 2 years ago

jonipol commented 3 years ago

Hello @christianrauch

I am having issues when launching the node from other launch file using IncludeLaunchDescription. (Using Foxy). On launch the /tf topic is somehow published to /apriltag/tf and setting remappings does nothing to it. (Tried remapping /apriltag/tf, /tf and tf. None of those does it.) But when I launch it from command line with ros2 launch ... the /tf topic is correctly published from the node.

Something I found was that when the topic name in AprilTagNode.cpp at line 55 was changed to tf instead of /tf the remapping started to work as it should but then without remapping the tf was published to /apriltag/tf regardless of launching method.

Also one interesting thing is that I tried adding /detections as topic name in detections publisher and I was able to remap it without any problems again regardless of launching method...

Wondering why does this happen and why /tf seems to behave differently than other topics?

Below you can find snippet of the launch I do and the apriltag launch file I use.

apriltag_detector = IncludeLaunchDescription(
    PythonLaunchDescriptionSource(
        os.path.join(get_package_share_directory('tag_detection'), 'launch', 'apriltag_detection.launch.py'),
    ),
    launch_arguments={'camera_topic': '/camera_1/image_raw',
                      'camera_info_topic': '/camera_1/camera_info',
                      'params_file': tag_param_path,
                      }.items()
)

apriltag_detection.launch.py

from ament_index_python import get_package_share_directory
from os import path
import yaml

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, OpaqueFunction
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode

def launch_setup(context):
    emulate_tty = LaunchConfiguration('emulate_tty')
    params_file = LaunchConfiguration('params_file').perform(context)
    camera_topic = LaunchConfiguration('camera_topic')
    camera_info_topic = LaunchConfiguration('camera_info_topic')

    params = yaml.load(open(params_file), Loader=yaml.FullLoader)

    composable_node = ComposableNode(
        name='apriltag',
        package='apriltag_ros',
        plugin='AprilTagNode',
        remappings=[("/apriltag/image", camera_topic),
                    ("/apriltag/camera_info", camera_info_topic),
                    ("detections", "/tag_detections"),
                    ],
        parameters=[params['apriltag']['apriltag']['ros__parameters']])

    apriltag_container = ComposableNodeContainer(
        name='tag_container',
        namespace='apriltag',
        package='rclcpp_components',
        executable='component_container',
        emulate_tty=emulate_tty,
        composable_node_descriptions=[composable_node],
        output='screen',
    )

    return [
        apriltag_container,
    ]

def generate_launch_description():
    params_path = path.join(get_package_share_directory('tag_detection'), 'params', 'tag_params.yaml')
    params_file_argument = DeclareLaunchArgument(
        'params_file',
        default_value=params_path,
        description='Full path to apriltag parameters yaml'
    )

    tty_argument = DeclareLaunchArgument(
        'emulate_tty',
        default_value='true',
        description='Emulate tty to show python prints for Nodes and to show log colors correctly'
    )

    camera_argument = DeclareLaunchArgument(
        'camera_topic',
        default_value='/camera_1/image_raw',
        description='Camera image topic'
    )

    camera_info_argument = DeclareLaunchArgument(
        'camera_info_topic',
        default_value='/camera_1/camera_info',
        description='Camera info topic'
    )

    return LaunchDescription([
        params_file_argument,
        tty_argument,
        camera_argument,
        camera_info_argument,
        OpaqueFunction(function=launch_setup)
    ])
christianrauch commented 2 years ago

Something I found was that when the topic name in AprilTagNode.cpp at line 55 was changed to tf instead of /tf the remapping started to work as it should but then without remapping the tf was published to /apriltag/tf regardless of launching method.

I replaced the custom publishing to topic /tf by the tf2_ros::TransformBroadcaster. This should handle the topic.