Skip to content

Basic Timer implementation #440

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

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6f9543c
Basic Timer type compiling :).
agalbachicar Nov 28, 2024
7b42c02
Evaluates the Timer::new() againts different clock types.
agalbachicar Nov 29, 2024
a60d9f3
Implement time_until_next_call
agalbachicar Nov 29, 2024
d233b47
Added cancel behavior
JesusSilvaUtrera Nov 29, 2024
3de2bb9
Merge pull request #1 from JesusSilvaUtrera/jsilva/add_cancel
agalbachicar Nov 29, 2024
189606f
Implement rcl_timer_reset
agalbachicar Nov 29, 2024
59ed7e2
Adds Timer::call().
agalbachicar Nov 29, 2024
9af9dd9
Added timer_period_ns (#2)
JesusSilvaUtrera Nov 29, 2024
e46224f
Adds Timer::is_ready().
agalbachicar Nov 29, 2024
501439d
WIP Timer callback implementation.
agalbachicar Nov 29, 2024
132c9db
Preliminary callback.
agalbachicar Nov 29, 2024
1095351
Added comments to avoid warnings (#3)
JesusSilvaUtrera Nov 29, 2024
965ca22
Integrated the Timer into the WaitSet.
agalbachicar Nov 29, 2024
f503c84
Add create_timer to node (WIP) (#4)
JesusSilvaUtrera Nov 29, 2024
ed78b35
Makes it work with the integration demo.
agalbachicar Nov 29, 2024
214a991
Working E2E timer with node.
agalbachicar Nov 29, 2024
1eb1acc
Format fix.
agalbachicar Nov 29, 2024
91756ca
Fix a TODO for peace of mind.
agalbachicar Nov 29, 2024
fbb8629
Adds an example.
agalbachicar Dec 1, 2024
ab3d63a
Fix format for the example.
agalbachicar Dec 1, 2024
4515e9a
Adds tests, documentation and removes dead code in node.rs.
agalbachicar Dec 1, 2024
85930a3
Fix documentation style in clock.rs.
agalbachicar Dec 1, 2024
1563895
Removes duplicated test in node.rs
agalbachicar Dec 1, 2024
08acef5
Fix warnings while running tests in node.rs.
agalbachicar Dec 1, 2024
a4c1a97
Fix missing documentation in wait.rs.
agalbachicar Dec 1, 2024
655185d
Improvements to timer.
agalbachicar Dec 1, 2024
30a6717
Makes rustdoc pass in the examples.
agalbachicar Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds Timer::call().
Signed-off-by: Agustin Alba Chicar <ag.albachicar@gmail.com>
  • Loading branch information
agalbachicar committed Nov 29, 2024
commit 59ed7e21c9ee9a59e03357917be1350ccdfc3d88
28 changes: 27 additions & 1 deletion rclrs/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ impl Timer {
to_rclrs_result(unsafe {rcl_timer_reset(&mut *rcl_timer)})
}

pub fn call(&mut self) -> Result<(), RclrsError>
{
let mut rcl_timer = self.rcl_timer.lock().unwrap();
to_rclrs_result(unsafe {rcl_timer_call(&mut *rcl_timer)})
}

// handle() -> RCLC Timer Type

// clock() -> Clock ?
Expand Down Expand Up @@ -222,7 +228,7 @@ mod tests {

#[test]
fn test_reset() {
let tolerance = 1e4 as i64;
let tolerance = 20e4 as i64;
let clock = Clock::steady();
let context = Context::new(vec![]).unwrap();
let period_ns: i64 = 2e6 as i64; // 2 milliseconds.
Expand All @@ -235,4 +241,24 @@ mod tests {
assert!(elapsed < tolerance , "elapsed after reset: {}", elapsed);
}

#[test]
fn test_call() {
let tolerance = 20e4 as i64;
let clock = Clock::steady();
let context = Context::new(vec![]).unwrap();
let period_ns: i64 = 1e6 as i64; // 1 millisecond.
let mut dut = Timer::new(&clock, &context, period_ns).unwrap();
let elapsed = period_ns - dut.time_until_next_call().unwrap();
assert!(elapsed < tolerance , "elapsed before reset: {}", elapsed);

thread::sleep(time::Duration::from_micros(1500));

let elapsed = period_ns - dut.time_until_next_call().unwrap();
assert!(elapsed > 1500000i64, "time_until_next_call before call: {}", elapsed);

assert!(dut.call().is_ok());

let elapsed = dut.time_until_next_call().unwrap();
assert!(elapsed < 500000i64, "time_until_next_call after call: {}", elapsed);
}
}