Myzhar / ldrobot-lidar-ros2

ROS2 package for LDRobot lidar. Based on ROS2 Lifecycle nodes
Apache License 2.0
64 stars 24 forks source link

remapping lifecycle node from /ldlidar_node/scan to /scan #23

Open Mubashir-alam opened 4 months ago

Mubashir-alam commented 4 months ago

I am using ldlidar for cartographer slam ros2 humble. The ldlidar published scan data on topic /ldlidar_node/scan but the cartographer node expects scan data on /scan topic. I remap the topic name from /ldlidar_node/scan to /scan following launch file remap but no data was published on /scan here is my launch file

import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
from launch_ros.actions import Node, LifecycleNode

def generate_launch_description():

    node_name = LaunchConfiguration('node_name')

    # Lidar node configuration file
    lidar_config_path = os.path.join(
        get_package_share_directory('ldlidar_node'),
        'params',
        'ldlidar.yaml'
    )

    # Launch arguments
    declare_node_name_cmd = DeclareLaunchArgument(
        'node_name',
        default_value='ldlidar_node',
        description='Name of the node'
    )

    # LDLidar lifecycle node
    ldlidar_node = LifecycleNode(
        package='ldlidar_node',
        executable='ldlidar_node',
        name=node_name,
        namespace='',
        output='screen',
        parameters=[
            # YAML files
            lidar_config_path  # Parameters
        ],
        remappings=[('/ld_scan', '/scan')]
    )

    # URDF path
    urdf_file_name = 'ldlidar_descr.urdf.xml'
    urdf = os.path.join(
        get_package_share_directory('ldlidar_node'),
        'urdf',
        urdf_file_name)
    with open(urdf, 'r') as infp:
        robot_desc = infp.read()

    # Robot State Publisher node
    rsp_node = Node(
        package='robot_state_publisher',
        executable='robot_state_publisher',
        name='ldlidar_state_publisher',
        output='screen',
        parameters=[{'robot_description': robot_desc}],
        arguments=[urdf]
    )

    # Define LaunchDescription variable
    ld = LaunchDescription()

    # Launch arguments
    ld.add_action(declare_node_name_cmd)

    # Launch Nav2 Lifecycle Manager
    ld.add_action(rsp_node)

    # LDLidar Lifecycle node
    ld.add_action(ldlidar_node)

    return ld
altineller commented 2 months ago

I have tried 'remappings=[('/ldlidar_node/scan', '/scan')]' which publishes /scan topic but when you ros2 topic echo /scan it does not publish anything.

I understand (from the slam example) that you can remap your cartographer or slam to remap /scan to /ldlidar_node/scan and this kind of works. but considering there are many nodes and software reading /scan for the sake of ergonomics can we not publish at /scan?

I also understand this might not be possible with lifecycle management nodes.

Best Regards, C.A.