ros2 / ros2/rclcpp

`operator+` and `operator-` for `builtin_interfaces::msg::Time` and `rclcpp::Duration`

Open
#2,399 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
C++
Stars
805
Forks
564
Avg merge
1d 17h
Merged PRs (30d)
27

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading rclcpp/include/rclcpp/duration.hpp and rclcpp/src/rclcpp/duration.cpp, especially the existing time and duration operator overloads. Confirm how builtin_interfaces::msg::Time is represented and determine the declarations and definitions needed for +, -, +=, and -=. Done means the examples using a message timestamp on the left compile and have the expected time arithmetic behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
robotics
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.