/rosout missing messages
Hi everyone,
I created a simple publisher, called tick_node, that is closed to the demo talker (source code below). In this talker I have two log messages published in the constructor and one message on each callback process.
When i subscribe to /rosout, I only see callback log message and not init ones.
$ ros2 run my_package tick_node
[INFO] [1672860164.164503973] [tick]: tick is launched
[WARN] [1672860164.164671835] [tick]: yolo
[INFO] [1672860165.164699272] [tick]: 1
[INFO] [1672860166.164675575] [tick]: 2
[INFO] [1672860167.164696142] [tick]: 3
[INFO] [1672860168.164682984] [tick]: 4
^C[INFO] [1672860168.332540873] [rclcpp]: signal_handler(signal_value=2)
Here is the output for rosout :
$ ros2 topic echo /rosout
stamp:
sec: 1672860165
nanosec: 164699272
level: 20
name: tick
msg: '1'
file: ...my_package/src/tick_node.cpp
function: process
line: 42
---
stamp:
sec: 1672860166
nanosec: 164675575
level: 20
name: tick
msg: '2'
file: ...my_package/src/tick_node.cpp
function: process
line: 42
---
stamp:
sec: 1672860167
nanosec: 164696142
level: 20
name: tick
msg: '3'
file: ...my_package/src/tick_node.cpp
function: process
line: 42
---
stamp:
sec: 1672860168
nanosec: 164682984
level: 20
name: tick
msg: '4'
file: ...my_package/src/tick_node.cpp
function: process
line: 42
---
The question is : why is there no "tick is launched" and "yolo" in the rosout topic ?
Talker code :
#include "my_packge/tick_node.hpp"
tickNode::tickNode()
: Node("tick"), count_(0)
{
// Initialisation process
timer_ = this->create_wall_timer(
std::chrono::milliseconds(process_period_ms),
std::bind(&tickNode::process, this));
RCLCPP_INFO(
this->get_logger(),
(std::string(this->get_name()) + std::string(" is launched")).c_str());
RCLCPP_WARN(
this->get_logger(),
"yolo");
}
void tickNode::process()
{
c = c + 1;
RCLCPP_INFO(
this->get_logger(),
std::to_string((c)));
}
int main(int argc, char *argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<tickNode>());
rclcpp::shutdown();
return 0;
}
Asked by Erysme on 2023-01-04 14:39:57 UTC
Answers
Your Node("tick") needs a small amount of time to create connections to each of the subscribers of the /rosout topic.
The ros behavior is to discard any message sent to a publisher that is not connected. So one reason you don't see those log messages on /rosout is that the code published them too soon after node creation. Note that the log messages sent to stdout do not pass through a ros topic, so you will see those.
Asked by Mike Scheutzow on 2023-01-06 08:23:47 UTC
Comments
Thanks for the reply, I understand it now :)
Asked by Erysme on 2023-01-07 04:54:03 UTC
Comments