diff --git a/rclcpp/include/rclcpp/duration.hpp b/rclcpp/include/rclcpp/duration.hpp index 11fc2e298f..b92ea42aec 100644 --- a/rclcpp/include/rclcpp/duration.hpp +++ b/rclcpp/include/rclcpp/duration.hpp @@ -89,6 +89,10 @@ class Duration Duration operator-(const rclcpp::Duration & rhs) const; + RCLCPP_PUBLIC + static Duration + max(); + RCLCPP_PUBLIC Duration operator*(double scale) const; diff --git a/rclcpp/include/rclcpp/time.hpp b/rclcpp/include/rclcpp/time.hpp index e93cb64909..c10b6ce23f 100644 --- a/rclcpp/include/rclcpp/time.hpp +++ b/rclcpp/include/rclcpp/time.hpp @@ -102,6 +102,10 @@ class Time rcl_time_point_value_t nanoseconds() const; + RCLCPP_PUBLIC + static Time + max(); + /// \return the seconds since epoch as a floating point number. /// \warning Depending on sizeof(double) there could be significant precision loss. /// When an exact time is required use nanoseconds() instead. diff --git a/rclcpp/src/rclcpp/duration.cpp b/rclcpp/src/rclcpp/duration.cpp index 0455abecd2..cb84e05d89 100644 --- a/rclcpp/src/rclcpp/duration.cpp +++ b/rclcpp/src/rclcpp/duration.cpp @@ -214,6 +214,12 @@ Duration::nanoseconds() const return rcl_duration_.nanoseconds; } +Duration +Duration::max() +{ + return Duration(std::numeric_limits::max(), 999999999); +} + double Duration::seconds() const { diff --git a/rclcpp/src/rclcpp/time.cpp b/rclcpp/src/rclcpp/time.cpp index 9ab924a8b6..980b6a5b3c 100644 --- a/rclcpp/src/rclcpp/time.cpp +++ b/rclcpp/src/rclcpp/time.cpp @@ -251,5 +251,11 @@ operator+(const rclcpp::Duration & lhs, const rclcpp::Time & rhs) return Time(lhs.nanoseconds() + rhs.nanoseconds(), rhs.get_clock_type()); } +Time +Time::max() +{ + return Time(std::numeric_limits::max(), 999999999); +} + } // namespace rclcpp diff --git a/rclcpp/test/test_duration.cpp b/rclcpp/test/test_duration.cpp index a6d099ff20..7d61c68a6d 100644 --- a/rclcpp/test/test_duration.cpp +++ b/rclcpp/test/test_duration.cpp @@ -120,3 +120,10 @@ TEST(TestDuration, negative_duration) { EXPECT_EQ(expected_value, assignable_duration.nanoseconds()); } } + +TEST(TestDuration, maximum_duration) { + rclcpp::Duration max_duration = rclcpp::Duration::max(); + rclcpp::Duration max(std::numeric_limits::max(), 999999999); + + EXPECT_EQ(max_duration, max); +}