-
Notifications
You must be signed in to change notification settings - Fork 418
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
construct TimerBase/GenericTimer with Clock #523
Merged
Merged
Changes from 1 commit
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
#include <type_traits> | ||
#include <utility> | ||
|
||
#include "rclcpp/clock.hpp" | ||
#include "rclcpp/function_traits.hpp" | ||
#include "rclcpp/macros.hpp" | ||
#include "rclcpp/rate.hpp" | ||
|
@@ -44,7 +45,7 @@ class TimerBase | |
RCLCPP_SMART_PTR_DEFINITIONS_NOT_COPYABLE(TimerBase) | ||
|
||
RCLCPP_PUBLIC | ||
explicit TimerBase(std::chrono::nanoseconds period); | ||
explicit TimerBase(Clock::SharedPtr clock, std::chrono::nanoseconds period); | ||
|
||
RCLCPP_PUBLIC | ||
~TimerBase(); | ||
|
@@ -85,6 +86,7 @@ class TimerBase | |
bool is_ready(); | ||
|
||
protected: | ||
Clock::SharedPtr clock_; | ||
std::shared_ptr<rcl_timer_t> timer_handle_; | ||
}; | ||
|
||
|
@@ -95,11 +97,9 @@ using TimerCallbackType = std::function<void (TimerBase &)>; | |
/// Generic timer templated on the clock type. Periodically executes a user-specified callback. | ||
template< | ||
typename FunctorT, | ||
class Clock, | ||
typename std::enable_if< | ||
(rclcpp::function_traits::same_arguments<FunctorT, VoidCallbackType>::value || | ||
rclcpp::function_traits::same_arguments<FunctorT, TimerCallbackType>::value) && | ||
Clock::is_steady | ||
rclcpp::function_traits::same_arguments<FunctorT, VoidCallbackType>::value || | ||
rclcpp::function_traits::same_arguments<FunctorT, TimerCallbackType>::value | ||
>::type * = nullptr | ||
> | ||
class GenericTimer : public TimerBase | ||
|
@@ -112,8 +112,10 @@ class GenericTimer : public TimerBase | |
* \param[in] period The interval at which the timer fires. | ||
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. missing parameter doc 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. Added in 0462196. |
||
* \param[in] callback User-specified callback function. | ||
*/ | ||
GenericTimer(std::chrono::nanoseconds period, FunctorT && callback) | ||
: TimerBase(period), callback_(std::forward<FunctorT>(callback)) | ||
explicit GenericTimer( | ||
Clock::SharedPtr clock, std::chrono::nanoseconds period, FunctorT && callback | ||
) | ||
: TimerBase(clock, period), callback_(std::forward<FunctorT>(callback)) | ||
{ | ||
} | ||
|
||
|
@@ -165,7 +167,7 @@ class GenericTimer : public TimerBase | |
virtual bool | ||
is_steady() | ||
{ | ||
return Clock::is_steady; | ||
return clock_->get_clock_type() == RCL_STEADY_TIME; | ||
} | ||
|
||
protected: | ||
|
@@ -174,8 +176,26 @@ class GenericTimer : public TimerBase | |
FunctorT callback_; | ||
}; | ||
|
||
template<typename CallbackType> | ||
using WallTimer = GenericTimer<CallbackType, std::chrono::steady_clock>; | ||
template< | ||
typename FunctorT, | ||
typename std::enable_if< | ||
rclcpp::function_traits::same_arguments<FunctorT, VoidCallbackType>::value || | ||
rclcpp::function_traits::same_arguments<FunctorT, TimerCallbackType>::value | ||
>::type * = nullptr | ||
> | ||
class WallTimer : public GenericTimer<FunctorT> | ||
{ | ||
public: | ||
RCLCPP_SMART_PTR_DEFINITIONS(WallTimer) | ||
|
||
explicit WallTimer(std::chrono::nanoseconds period, FunctorT && callback) | ||
: GenericTimer<FunctorT>( | ||
std::make_shared<Clock>(RCL_STEADY_TIME), period, std::move(callback)) | ||
{} | ||
|
||
protected: | ||
RCLCPP_DISABLE_COPY(WallTimer) | ||
}; | ||
|
||
} // namespace rclcpp | ||
|
||
|
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.
doc needs update
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.
Updated in 0462196.