-
Notifications
You must be signed in to change notification settings - Fork 421
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
Addition and subtraction assignment operators #2424
Open
HuaTsai
wants to merge
16
commits into
ros2:rolling
Choose a base branch
from
HuaTsai:rolling
base: rolling
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+48
−1
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7c57ad5
feat: add/minus for msg::Time and rclcpp::Duration
HuaTsai ba5b21a
fix: add needed headers
HuaTsai 76afcf6
style: formatting
HuaTsai a1afbd4
test: operators with message stamp
HuaTsai f563e00
style: formatting
HuaTsai 78ab451
refactor: function converting nanoseconds to seconds and nanoseconds
HuaTsai 52fc2e6
fix: missing semicolon
HuaTsai 7037cc8
fix: callee should be rcl_time_point_value_t
HuaTsai 963d3e9
fix: add necessary header
HuaTsai 9247045
refactor: move convert function to time.hpp/cpp
HuaTsai 5993efc
Update rclcpp/test/rclcpp/test_duration.cpp
HuaTsai 135c469
refactor: add consistent unsigned suffix 'u'
HuaTsai 9f77873
refactor: return inline function
HuaTsai 0c510bb
Merge branch 'ros2:rolling' into rolling
HuaTsai 0952187
feat: addition/subtraction assignment operators
HuaTsai 5df5661
fix: test case with negative operand
HuaTsai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any special handling needed for overflow/underflow?
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.
Hi @Ryanf55,
Sorry for forgetting to reply.
The overflow test is already in line 133 below.
For the underflow test, please check here: #2419 (comment).
Or let me paraphrase in another way:
I follow what happens when
rclcpp::Duration + msg::Time
.It first becomes
rclcpp::Duration + rclcpp::Time
(implicit conversion).During the conversion, negative
seconds
inmsg::Time
is not allowed.rclcpp/rclcpp/src/rclcpp/time.cpp
Lines 52 to 54 in 99f0fc9
IMO this is a small design flaw since it does not match Unix that uses
int32
to store time.But in practice, who cares about time before 1970, so it should remain fine.
After that, positive
int32
seconds anduint32
nanoseconds will generate positiveint64
full nanoseconds.A positive
int64
nanoseconds add anotherint64
duration nanoseconds always not underflow.That's my current understanding and therefore I do (and can) not test underflow.
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.
Is it written down anywhere that
rclcpp::Time
must use Unix time? I have used it in places to store time since boot, in the case that the embedded device does not have a RTC or network connection, and thus had no idea of any time except boot time. Certain unsafe uses of while loops, with timeouts and such can lead to weird bugs.https://docs.ros2.org/beta3/api/rclcpp/classrclcpp_1_1Time.html
I agree, the likelyhood of underflow while using epoch time is low.
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 don't find such description, maybe my statement earlier is too biased.
RTC or network connection, and thus had no idea of any time except boot time.
Yes, this reminds me that the clock source of
rclcpp::Time
could also be timestamps in rosbag.Both of them are not using current epoch time.
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.
As long as overflow/overflow is tested somewhere, seems like a good approach to me.