-
Notifications
You must be signed in to change notification settings - Fork 163
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
initialize timer with clock #272
Changes from all commits
252bdaf
e8f2e34
0c97207
28e6ba1
e1a400e
de691c4
83d96cb
433d0c0
9e7737c
0eda193
1c73377
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ extern "C" | |
#include "rcl/types.h" | ||
#include "rmw/rmw.h" | ||
|
||
struct rcl_clock_t; | ||
struct rcl_timer_impl_t; | ||
|
||
/// Structure which encapsulates a ROS Timer. | ||
|
@@ -60,7 +61,7 @@ rcl_get_zero_initialized_timer(void); | |
|
||
/// Initialize a timer. | ||
/** | ||
* A timer consists of a callback function and a period. | ||
* A timer consists of a clock, a callback function and a period. | ||
* A timer can be added to a wait set and waited on, such that the wait set | ||
* will wake up when a timer is ready to be executed. | ||
* | ||
|
@@ -77,6 +78,9 @@ rcl_get_zero_initialized_timer(void); | |
* Calling this function on a timer struct which has been allocated but not | ||
* zero initialized is undefined behavior. | ||
* | ||
* The clock handle must be a pointer to an initialized rcl_clock_t struct. | ||
* The life time of the clock must exceed the life time of the timer. | ||
* | ||
* The period is a duration (rather an absolute time in the future). | ||
* If the period is `0` then it will always be ready. | ||
* | ||
|
@@ -101,9 +105,14 @@ rcl_get_zero_initialized_timer(void); | |
* // Optionally reconfigure, cancel, or reset the timer... | ||
* } | ||
* | ||
* rcl_clock_t clock; | ||
* rcl_allocator_t allocator = rcl_get_default_allocator(); | ||
* rcl_ret_t ret = rcl_clock_init(RCL_STEADY_TIME, &clock, &allocator); | ||
* // ... error handling | ||
* | ||
* rcl_timer_t timer = rcl_get_zero_initialized_timer(); | ||
* rcl_ret_t ret = rcl_timer_init( | ||
* &timer, RCL_MS_TO_NS(100), my_timer_callback, rcl_get_default_allocator()); | ||
* ret = rcl_timer_init( | ||
* &timer, &clock, RCL_MS_TO_NS(100), my_timer_callback, allocator); | ||
* // ... error handling, use the timer with a wait set, or poll it manually, then cleanup | ||
* ret = rcl_timer_fini(&timer); | ||
* // ... error handling | ||
|
@@ -123,6 +132,7 @@ rcl_get_zero_initialized_timer(void); | |
* <i>[3] if `atomic_is_lock_free()` returns true for `atomic_bool`</i> | ||
* | ||
* \param[inout] timer the timer handle to be initialized | ||
* \param[in] clock the clock providing the current time | ||
* \param[in] period the duration between calls to the callback in nanoseconds | ||
* \param[in] callback the user defined function to be called every period | ||
* \param[in] allocator the allocator to use for allocations | ||
|
@@ -137,6 +147,7 @@ RCL_WARN_UNUSED | |
rcl_ret_t | ||
rcl_timer_init( | ||
rcl_timer_t * timer, | ||
rcl_clock_t * clock, | ||
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. docblock for this function needs to be updated 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. Absolutely, packages on-top of 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. Updated the docblock in e1a400e. |
||
int64_t period, | ||
const rcl_timer_callback_t callback, | ||
rcl_allocator_t allocator); | ||
|
@@ -216,6 +227,32 @@ RCL_WARN_UNUSED | |
rcl_ret_t | ||
rcl_timer_call(rcl_timer_t * timer); | ||
|
||
/// Retrieve the clock of the timer. | ||
/** | ||
* This function retrieves the clock pointer and copies it into the given variable. | ||
* | ||
* The clock argument must be a pointer to an already allocated rcl_clock_t *. | ||
* | ||
* <hr> | ||
* Attribute | Adherence | ||
* ------------------ | ------------- | ||
* Allocates Memory | No | ||
* Thread-Safe | Yes | ||
* Uses Atomics | No | ||
* Lock-Free | Yes | ||
* | ||
* \param[in] timer the handle to the timer which is being queried | ||
* \param[out] clock the rcl_clock_t * in which the clock is stored | ||
* \return `RCL_RET_OK` if the period was retrieved successfully, or | ||
* \return `RCL_RET_INVALID_ARGUMENT` if any arguments are invalid, or | ||
* \return `RCL_RET_TIMER_INVALID` if the timer is invalid, or | ||
* \return `RCL_RET_ERROR` an unspecified error occur. | ||
*/ | ||
RCL_PUBLIC | ||
RCL_WARN_UNUSED | ||
rcl_ret_t | ||
rcl_timer_clock(rcl_timer_t * timer, rcl_clock_t ** clock); | ||
|
||
/// Calculates whether or not the timer should be called. | ||
/** | ||
* The result is true if the time until next call is less than, or equal to, 0 | ||
|
@@ -315,7 +352,7 @@ rcl_timer_get_time_since_last_call(const rcl_timer_t * timer, int64_t * time_sin | |
|
||
/// Retrieve the period of the timer. | ||
/** | ||
* This function retrieves the period and copies it into the give variable. | ||
* This function retrieves the period and copies it into the given variable. | ||
* | ||
* The period argument must be a pointer to an already allocated int64_t. | ||
* | ||
|
@@ -343,7 +380,7 @@ rcl_timer_get_period(const rcl_timer_t * timer, int64_t * period); | |
/// Exchange the period of the timer and return the previous period. | ||
/** | ||
* This function exchanges the period in the timer and copies the old one into | ||
* the give variable. | ||
* the given variable. | ||
* | ||
* Exchanging (changing) the period will not affect already waiting wait sets. | ||
* | ||
|
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.
new functionality in rclpy is relying on the existing signature: https://github.com/ros2/rclpy/pull/209/files#diff-80dda03110b5be606b823d6b0558b5c2R3218 (CI wouldn't have picked up on that because the PR was merged after it). Sorry about that, I didn't realise that merge would cause conflict here (I understood we were going to add a new signature rather than modifying the existing one). I would make a PR for it but ros2/rclpy#211 is already connected and needs to be rebased first
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.
Thanks for pointing it out - no problem. I rebased the
rclpy
PR and updated it in ros2/rclpy@f938bac to use the modified API.