Skip to content

Commit

Permalink
add Time::is_zero and Duration::seconds (#536)
Browse files Browse the repository at this point in the history
add Duration::seconds
  • Loading branch information
dirk-thomas committed Aug 20, 2018
1 parent 45d74ba commit 25a9b4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rclcpp/include/rclcpp/duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Duration
rcl_duration_value_t
nanoseconds() const;

/// \return the duration in seconds 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.
RCLCPP_PUBLIC
double
seconds() const;

private:
rcl_duration_t rcl_duration_;
};
Expand Down
6 changes: 6 additions & 0 deletions rclcpp/src/rclcpp/duration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,10 @@ Duration::nanoseconds() const
return rcl_duration_.nanoseconds;
}

double
Duration::seconds() const
{
return std::chrono::duration<double>(std::chrono::nanoseconds(rcl_duration_.nanoseconds)).count();
}

} // namespace rclcpp

0 comments on commit 25a9b4e

Please sign in to comment.