Skip to content
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

Merged
merged 27 commits into from
May 2, 2024
Merged

Initial implementation #1

merged 27 commits into from
May 2, 2024

Conversation

Rayman
Copy link
Collaborator

@Rayman Rayman commented Apr 29, 2024

It doesn't receive it's own messages, and by default it uses 30% less CPU to run

image

26.96 / (20.43 + 17.34) = 0.71

With the EventsExecutor it uses 40% less CPU

image

27.35 / (25.20 + 21.72) = 0.58

@Rayman Rayman requested a review from Timple April 29, 2024 11:35
@Rayman Rayman self-assigned this Apr 29, 2024
#include <rclcpp/experimental/executors/events_executor/events_executor.hpp>
#include <thread>

std::string to_string(const can_msgs::msg::Frame & msg)
Copy link
Member

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));

Copy link
Collaborator Author

@Rayman Rayman Apr 30, 2024

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));

Copy link
Member

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));

Copy link
Collaborator Author

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...

Copy link
Member

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.

Copy link
Collaborator Author

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_views.

Copy link
Collaborator Author

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

src/socketcan_bridge.cpp Outdated Show resolved Hide resolved
src/socketcan_bridge.cpp Outdated Show resolved Hide resolved
src/socketcan_bridge.cpp Outdated Show resolved Hide resolved
src/socketcan_bridge.cpp Outdated Show resolved Hide resolved
@Timple
Copy link
Member

Timple commented Apr 29, 2024

I'd call it ros2_socketcan_bridge for SEO purposes ;-)

README.md Outdated Show resolved Hide resolved
perf.data Outdated Show resolved Hide resolved
@Rayman Rayman merged commit 4d5efba into main May 2, 2024
4 checks passed
@Rayman Rayman deleted the initial-implementation branch May 2, 2024 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants