ros2 node stuck in RCLCPP_INFO when using launch files

asked 2020-09-28 03:25:32 -0600

Phymin gravatar image

updated 2020-09-28 04:28:46 -0600


I write the following main function for runing my node:

int main(int argc, char** argv)
    rclcpp::init(argc, argv);
    auto baseNode = std::make_shared<ElfinBaseNode>();
    if (!baseNode->start())
      std::cout << "Failed to start elfin base node!" << std::endl;
      return -1;
   RCLCPP_INFO(baseNode->get_logger(), "Elfin base node starts OK.");
   //std::cout << "Elfin base node starts OK." << std::endl;


   return 0;


But what is strange is if I start the node with launch file and comment the code:std::cout << "Elfin base node starts OK." << std::endl;, the output of the console with be like this: image description

but if I uncomment the std::cout code, the output of the console with be like this: image description

It's obvious that the second output is correct, and it seems the node was stuck in somewhere from the first output picture. I have also try with ros2 run command, with and without comment the std::cout code, the output are all correct.

I am wondering if I did something wrong in ros2, because this code is ported from ros1. Hope someone could help me out, Thanks for advance.

Here is the 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

 def generate_launch_description():
    param_file = LaunchConfiguration(
    default = os.path.join(
        'params', 'base_config.yaml'

 return LaunchDescription([
        default_value = param_file,
        description="Full path to param file to load"

edit retag flag offensive close merge delete


Anyone could give me some clues? I am really frustrated about this problem, thanks.

Phymin gravatar image Phymin  ( 2020-09-30 03:04:14 -0600 )edit