-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initial implementation #1
Conversation
src/socketcan_bridge.cpp
Outdated
#include <rclcpp/experimental/executors/events_executor/events_executor.hpp> | ||
#include <thread> | ||
|
||
std::string to_string(const can_msgs::msg::Frame & msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can simply specify a formatter for can_msgs::msg::Frame
. That way you can do:
RCLCPP_INFO(logger_, fmt::format("Received {}", msg));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this require you to do this?
RCLCPP_INFO(logger_, "%s", fmt::format("Received {}", msg).c_str());
RCLCPP_INFO_STREAM(logger_, fmt::format("Received {}", msg));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. Actually one of these two I think:
RCLCPP_INFO(logger_, fmt::format("Received {}", msg).data());
RCLCPP_INFO_STREAM(logger_, fmt::format("Received {}", msg));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first is dangerous because use data could contain a string formatting. Also you should use c_str because it should be null terminated.
So the second option seems more clean, but then I could also just add a stream operator and not use fmt at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.data()
is the same as .c_str()
but works on std::string_view
and std::string
.
At least, that was my understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that since C++11 they are required to be the same. But indeed .data()
is available for string_view
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now using ostream
because its a bit more readable
I'd call it |
It doesn't receive it's own messages, and by default it uses 30% less CPU to run
26.96 / (20.43 + 17.34) = 0.71
With the
EventsExecutor
it uses 40% less CPU27.35 / (25.20 + 21.72) = 0.58