Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS2 | Namespacing & TF Remapping #71

Open
SOHAILMBS opened this issue Dec 12, 2024 · 1 comment
Open

ROS2 | Namespacing & TF Remapping #71

SOHAILMBS opened this issue Dec 12, 2024 · 1 comment

Comments

@SOHAILMBS
Copy link

Dear Mola Team,

Would it be possible to add the remap args for tf to the ros2 package. We want to test this software in a multi-robot system, but for that we need to remap the tf topics e.g.

from launch import LaunchDescription
from launch.substitutions import TextSubstitution
from launch.substitutions import LaunchConfiguration
from launch.conditions import IfCondition
from launch_ros.actions import Node
from launch.actions import DeclareLaunchArgument
from launch.actions import SetEnvironmentVariable
from ament_index_python import get_package_share_directory
import os


def generate_launch_description():
  
    nsp = os.environ.get('ROBOT_NS',  #'husky_0986')
    rmp = [
        ('/path', 'gps'),
        ('/tf', 'tf'),
        ('/tf_static', 'tf_static'),
    ]
  
    # lidar_topic = '/'+nsp+'/livox/lidar'
    lidar_topic = '/livox/lidar'
  
    myDir = get_package_share_directory("mola_lidar_odometry")

    # Mandatory
    lidar_topic_name_arg = DeclareLaunchArgument(
        "lidar_topic_name", default_value=lidar_topic, description="Topic name to listen for PointCloud2 input from the LiDAR (for example '/ouster/points')")
    topic_env_var = SetEnvironmentVariable(
        name='MOLA_LIDAR_TOPIC', value=LaunchConfiguration('lidar_topic_name'))
    # ~~~~~~~~~~~~
    ignore_lidar_pose_from_tf_arg = DeclareLaunchArgument(
        "ignore_lidar_pose_from_tf", default_value="True", description="If true, the LiDAR pose will be assumed to be at the origin (base_link). Set to false (default) if you want to read the actual sensor pose from /tf")
    fixed_sensorpose_env_var = SetEnvironmentVariable(
        name='MOLA_USE_FIXED_LIDAR_POSE', value=LaunchConfiguration('ignore_lidar_pose_from_tf'))
    # ~~~~~~~~~~~~
    gnss_topic_name_arg = DeclareLaunchArgument(
        "gnss_topic_name", default_value="/gps", description="Topic name to listen for NavSatFix input from a GNSS (for example '/gps')")
    gps_topic_env_var = SetEnvironmentVariable(
        name='MOLA_GNSS_TOPIC', value=LaunchConfiguration('gnss_topic_name'))
    # ~~~~~~~~~~~~
    use_rviz = LaunchConfiguration('use_rviz')
    use_rviz_arg = DeclareLaunchArgument(
        "use_rviz", default_value="True", description="Whether to launch RViz2 with default lidar-odometry.rviz configuration")

    # -------------------
    #        Node
    # -------------------
    mola_cli_node = Node(
        namespace=nsp,
        remappings=rmp,
        package='mola_launcher',
        executable='mola-cli',
        output='screen',
        arguments=[
                os.path.join(myDir, 'mola-cli-launchs', 'lidar_odometry_ros2.yaml')],
        
    )

    rviz2_node = Node(
        condition=IfCondition(use_rviz),
        # namespace=nsp,
        # remappings=rmp,
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        arguments=[
                '-d', [os.path.join(myDir, 'rviz2', 'lidar-odometry.rviz')]]
    )

    ld = LaunchDescription()
    
    ld.add_action(lidar_topic_name_arg)
    ld.add_action(topic_env_var)
    ld.add_action(ignore_lidar_pose_from_tf_arg)
    ld.add_action(fixed_sensorpose_env_var)
    ld.add_action(gnss_topic_name_arg)
    ld.add_action(gps_topic_env_var)
    
    ld.add_action(use_rviz_arg)
    
    # ld.add_action(rviz2_node)
    ld.add_action(mola_cli_node)
    
    
    return ld
This was referenced Dec 17, 2024
@jlblancoc
Copy link
Member

jlblancoc commented Dec 17, 2024

This feature is now implemented. Please refer to the updated section with ROS 2 launch arguments: https://docs.mola-slam.org/latest/ros2api.html#ros-2-node-for-lidar-odometry-lo

E.g.:

# Minimal use case:
ros2 launch mola_lidar_odometry ros2-lidar-odometry.launch.py \
   lidar_topic_name:=ouster/points \
   use_namespace:=True \
   namespace:=ROBOT_NS

Feedback would be appreciated. It's already tested on simulation, but we can't test yet on our Husky since it's in the middle of upgrading it to ROS 2 (!).

PS: It requires doing "git pull" and rebuilding two repos: MOLAorg/{mola,mola_lidar_odometry}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants