Add TIME_MAX and DURATION_MAX functions (#538)
* Add TIME_MAX and DURATION_MAX functions * Fix Linting Errors * change funtion name as per coding style * change function name as per coding style * Update duration.cpp * Update time.cpp * Update test_duration.cpp * Update time.hpp * remove extra empty line
This commit is contained in:
parent
354d933870
commit
18ad26e654
5 changed files with 27 additions and 0 deletions
|
@ -89,6 +89,10 @@ public:
|
|||
Duration
|
||||
operator-(const rclcpp::Duration & rhs) const;
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
static Duration
|
||||
max();
|
||||
|
||||
RCLCPP_PUBLIC
|
||||
Duration
|
||||
operator*(double scale) const;
|
||||
|
|
|
@ -102,6 +102,10 @@ public:
|
|||
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.
|
||||
|
|
|
@ -214,6 +214,12 @@ Duration::nanoseconds() const
|
|||
return rcl_duration_.nanoseconds;
|
||||
}
|
||||
|
||||
Duration
|
||||
Duration::max()
|
||||
{
|
||||
return Duration(std::numeric_limits<int32_t>::max(), 999999999);
|
||||
}
|
||||
|
||||
double
|
||||
Duration::seconds() const
|
||||
{
|
||||
|
|
|
@ -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<int32_t>::max(), 999999999);
|
||||
}
|
||||
|
||||
|
||||
} // namespace rclcpp
|
||||
|
|
|
@ -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<int32_t>::max(), 999999999);
|
||||
|
||||
EXPECT_EQ(max_duration, max);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue