You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on ros2/realtime_support#94.
We want to change some rttest APIs such as timespec_to_long to timspec_to_uint64.
As these functions are used in pendulum_control, now I'm changing and testing pendulum_control.
In this work, I found the result of timespec_to_long should be printed but actually not.
I think the problem comes from the capture of logging_callback lambda.
The variable fstream is opened outside lambda but not captured.
And fstream is defined in logging_callback lambda without file specification.
According to http://www.cplusplus.com/reference/fstream/ofstream/ofstream/, fstream may be the internal file stream buffer and not associated with file.
// pendulum_logger.cpp L43-67
fstream.open(filename, std::ios_base::app);
size_t i = 0;
auto logging_callback =
[&i](const pendulum_msgs::msg::RttestResults::SharedPtr msg) {
// snip
std::ofstream fstream;
// snip
fstream << i << ...;
};
auto subscription = logger_node->create_subscription<pendulum_msgs::msg::RttestResults>(
"pendulum_statistics", qos, logging_callback);
I fixed as bellow,
auto logging_callback =
[&i, &fstream](const pendulum_msgs::msg::RttestResults::SharedPtr msg) {
// std::ofstream fstream; // delete this lins
fstream << i << ...;
Honestly, that looks like debugging code. And since it is hasn't been enabled in a long time, I think I would just delete that whole block (most of the information is printed by the printf above anyway).
Bug report
I'm working on ros2/realtime_support#94.
We want to change some rttest APIs such as
timespec_to_long
totimspec_to_uint64
.As these functions are used in pendulum_control, now I'm changing and testing pendulum_control.
In this work, I found the result of
timespec_to_long
should be printed but actually not.Required Info:
Steps to reproduce issue
See pendulum_logger_results.csv or stdout or stderr, but I couldn't see output of following line.
https://github.com/ros2/demos/blob/master/pendulum_control/src/pendulum_logger.cpp#L62
The code tries to output to fstream (may be pendulum_logger_result.csv),
but pendulum_logger_result.csv is following, only one line.
Expected behavior
We get log in pendulum_logger_results.csv.
Actual behavior
No log in pendulum_logger_results.csv.
Additional information
I think the problem comes from the capture of logging_callback lambda.
The variable fstream is opened outside lambda but not captured.
And fstream is defined in logging_callback lambda without file specification.
According to http://www.cplusplus.com/reference/fstream/ofstream/ofstream/, fstream may be the internal file stream buffer and not associated with file.
I fixed as bellow,
and get output in pendulum_logger_results.csv.
If it's OK, I'll send PR.
The text was updated successfully, but these errors were encountered: