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

operator+ and operator- for builtin_interfaces::msg::Time and rclcpp::Duration #2399

Open
HuaTsai opened this issue Dec 25, 2023 · 1 comment · May be fixed by #2424
Open

operator+ and operator- for builtin_interfaces::msg::Time and rclcpp::Duration #2399

HuaTsai opened this issue Dec 25, 2023 · 1 comment · May be fixed by #2424
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@HuaTsai
Copy link
Contributor

HuaTsai commented Dec 25, 2023

Feature request

I wonder if rclcpp could support add/minus time with msg::Time on the left as caller.
In the current delivery,

std_msgs::msg::Header header;
header.stamp = rclcpp::Duration::from_seconds(1) + header.stamp; // OK, unintuitive
header.stamp = rclcpp::Time(header.stamp) + rclcpp::Duration::from_seconds(1);  // OK, with conversion and implicit conversion
header.stamp = header.stamp + rclcpp::Duration::from_seconds(1); // CE
header.stamp += rclcpp::Duration::from_seconds(1);  // CE

It is more intuitive for the user to choose the third (furthermore, fourth) option instead of the first two.
I think the operators +, -, +=, -= can be implemented in duration.hpp and duration.cpp without any backward incompatiblity.
Furthermore, aside from rclcpp::Time containing a clock, rclcpp::Duration only contains nanoseconds which makes this task simpler.
Also in a higher level view, "a time" can always add "a duration" and conclude another "time."

@clalancette
Copy link
Contributor

We ended up discussing this, and we think that yes, all of those operators could be implemented. In addition, we should make sure to have documentation somewhere that builtin_msgs::msg::Time is assumed to be ROS time, as these operators should enforce that we are only adding together compatible times.

I don't think we are going to work on this anytime soon, but please feel free to open a pull request.

@clalancette clalancette added enhancement New feature or request help wanted Extra attention is needed labels Jan 18, 2024
@HuaTsai HuaTsai linked a pull request Feb 15, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants