-
Notifications
You must be signed in to change notification settings - Fork 412
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
Add TIME_MAX and DURATION_MAX functions #538
Changes from 3 commits
e00cad1
50f0412
5bebeee
64c83f7
7231fad
37d793b
1e03154
ee4bdd9
ddc03e7
8fb0124
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,6 +214,13 @@ Duration::nanoseconds() const | |
return rcl_duration_.nanoseconds; | ||
} | ||
|
||
Duration | ||
Duration::DURATION_MAX() | ||
{ | ||
Duration duration_max(std::numeric_limits<int32_t>::max(), 999999999); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tfoote This PR and #524 say a duration is limited by the max value that can be given to the constructor accepting seconds and nanoseconds, but there is another constructor taking nanoseconds directly, and that seems to accept a number of nanoseconds as large as the 64bit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the nanoseconds constructor should limit it to this representation. Otherwise we'll overflow the message datastructure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it would be easier to read as a one line function. No need to name the temporary variable, it could just be returned. |
||
return duration_max; | ||
} | ||
|
||
double | ||
Duration::seconds() const | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,5 +251,12 @@ operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs) | |
return Time(lhs.nanoseconds() + rhs.nanoseconds(), rhs.get_clock_type()); | ||
} | ||
|
||
Time | ||
TIME_MAX() | ||
{ | ||
Time time_max(std::numeric_limits<int32_t>::max(), 999999999); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it would be easier to read as a one line function. No need to name the temporary variable, it could just be returned. |
||
return time_max; | ||
} | ||
|
||
|
||
} // namespace rclcpp |
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.
Please rename the method to use lowercase (as per code style). Also since it is defined in the class
Duration
I don't think it needs to be part of the name. So I would suggest just calling itmax()
which will be used asDuration::max()
.Same for time below.