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

Switch from bind to lambda for timer callback #43

Merged
merged 1 commit into from
Jan 17, 2024

Conversation

Ryanf55
Copy link
Collaborator

@Ryanf55 Ryanf55 commented Jan 17, 2024

Purpose

This switches from using bind to lambda for setting up a timer callback. In the past month, ROS 2 tutorials have been all migrated to lambda.
Why? Placeholders are hard to read, and disables some compile time checks.
And: ros2/rclcpp#1701

Risk

None

original_map_pub_->publish(std::move(msg));
}
};
timer_ = this->create_wall_timer(5s, timer_callback);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting,

I think for this node it makes a lot of sense since there is not much going on. How much does this apply for general controllers that need to run on a fixed schedule? For me just slightly weird that you would have all the logic implemented in the constructor?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, it's still possible to have a separate member function to call the timer if we want, and this can be called from outside the class (in main) if it's public scope. Currently, for this node, where the grid_map data is fixed at runtime, the rate of publish does not matter, so I just made it simple and did all the work in the constructor.

Happy to change if you are not a fan.

Copy link
Member

@Jaeyoung-Lim Jaeyoung-Lim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, Thanks!

Would you be able to rebase?

@Ryanf55
Copy link
Collaborator Author

Ryanf55 commented Jan 17, 2024

Looks great, Thanks!

Would you be able to rebase?

Done.

@Jaeyoung-Lim Jaeyoung-Lim merged commit 88d5ea2 into ethz-asl:ros2 Jan 17, 2024
2 checks passed
@Ryanf55 Ryanf55 deleted the bind-to-lambda branch January 17, 2024 20:43
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