ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

No output from ros2 topic

asked 2023-07-11 16:00:19 -0500

Robo_guy gravatar image

Hello everyone, I am trying to combine the realsense node and openvins node using this launch file -

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument, LogInfo, OpaqueFunction
from launch.conditions import IfCondition
from launch.substitutions import LaunchConfiguration, TextSubstitution
from launch_ros.actions import ComposableNodeContainer
from launch_ros.descriptions import ComposableNode
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory, get_package_prefix
import os
import sys

def generate_launch_description():
    # Define launch arguments
    launch_args = [
    DeclareLaunchArgument(name="namespace", default_value="ov_msckf", description="namespace"),
    DeclareLaunchArgument(
        name="ov_enable", default_value="true", description="enable OpenVINS node"
    ),
    DeclareLaunchArgument(
        name="rviz_enable", default_value="false", description="enable rviz node"
    ),
    DeclareLaunchArgument(
        name="config",
        default_value="euroc_mav",
        description="euroc_mav, tum_vi, rpng_aruco...",
    ),
    DeclareLaunchArgument(
        name="config_path",
        default_value="",
        description="path to estimator_config.yaml. If not given, determined based on provided 'config' above",
    ),
    DeclareLaunchArgument(
        name="verbosity",
        default_value="INFO",
        description="ALL, DEBUG, INFO, WARNING, ERROR, SILENT",
    ),
    DeclareLaunchArgument(
        name="use_stereo",
        default_value="true",
        description="if we have more than 1 camera, if we should try to track stereo constraints between pairs",
    ),
    DeclareLaunchArgument(
        name="max_cameras",
        default_value="2",
        description="how many cameras we have 1 = mono, 2 = stereo, >2 = binocular (all mono tracking)",
    ),
    DeclareLaunchArgument(
        name="save_total_state",
        default_value="false",
        description="record the total state with calibration and features to a txt file",
    )
    ]   

    def launch_setup(context):
        config_path = LaunchConfiguration("config_path").perform(context)
        if not config_path:
            configs_dir = os.path.join(get_package_share_directory("ov_msckf"), "config")
            available_configs = os.listdir(configs_dir)
            config = LaunchConfiguration("config").perform(context)
            if config in available_configs:
                config_path = os.path.join(
                            get_package_share_directory("ov_msckf"),
                            "config",config,"estimator_config.yaml"
                        )
            else:
                return [
                    LogInfo(
                        msg="ERROR: unknown config: '{}' - Available configs are: {} - not starting OpenVINS".format(
                            config, ", ".join(available_configs)
                        )
                    )
                ]
        else:
            if not os.path.isfile(config_path):
                return [
                    LogInfo(
                        msg="ERROR: config_path file: '{}' - does not exist. - not starting OpenVINS".format(
                            config_path)
                        )
                ]

        node1 = Node(
            package="ov_msckf",
            executable="run_subscribe_msckf",
            condition=IfCondition(LaunchConfiguration("ov_enable")),
            namespace=LaunchConfiguration("namespace"),
            output='screen',
            parameters=[
            {"verbosity": LaunchConfiguration("verbosity")},
            {"use_stereo": LaunchConfiguration("use_stereo")},
            {"max_cameras": LaunchConfiguration("max_cameras")},
            {"save_total_state": LaunchConfiguration("save_total_state")},
            {"config_path": config_path},
        ],
        )

        node2 = Node(
            package="rviz2",
            executable="rviz2",
            condition=IfCondition(LaunchConfiguration("rviz_enable")),
            arguments=[
                "-d",
                os.path.join(
                    get_package_share_directory("ov_msckf"), "launch", "display_ros2.rviz"
                ),
                "--ros-args",
                "--log-level",
                "warn",
            ],
        )

        # Config file
        config_file = os.path.join(
            get_package_share_directory('argos_launch'),
            'config', 'sensors', 'realsense_ov.yaml')

        # Realsense driver node
        realsense_node = ComposableNode(
            namespace="camera",
            package='realsense2_camera',
            plugin='realsense2_camera::RealSenseNodeFactory',
            parameters=[config_file],
            remappings = [("/camera/imu", "/imu0")])


        # Container
        realsense_container = ComposableNodeContainer(
            name='realsense_container',
            namespace='',
            package='rclcpp_components',
            executable='component_container',
            composable_node_descriptions=[
                realsense_node,
            ],
            output='screen')

        return [node1, node2, realsense_container]

    opfunc = OpaqueFunction(function=launch_setup)

    ld = LaunchDescription(launch_args)
    ld.add_action(opfunc)

    return ld

But whenever I run the launch file and run this command in another terminal -

ros2 topic hz /ov_msckf/odomimu

I do not get any output, please can anybody help me solve this issue and tell me what could be going wrong, I tried remapping the topics also but still I don't get any output

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-08-07 18:36:17 -0500

Robo_guy gravatar image

I solved this issue by myself, turns out there was issue with the correct use of namespace for the composable nodes and also how the parameters need to be read from the configuration yaml file.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-07-11 16:00:19 -0500

Seen: 109 times

Last updated: Aug 07 '23