Skip to content

Commit 2d20c4e

Browse files
committed
Fix merge conflicts with main
Signed-off-by: Michael X. Grey <[email protected]>
1 parent eca3f9a commit 2d20c4e

File tree

14 files changed

+1670
-36
lines changed

14 files changed

+1670
-36
lines changed

examples/timer_demo/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "timer_demo"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rclrs = "0.4"
8+
example_interfaces = "*"

examples/timer_demo/package.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<?xml-model
3+
href="http://download.ros.org/schema/package_format3.xsd"
4+
schematypens="http://www.w3.org/2001/XMLSchema"?>
5+
<package format="3">
6+
<name>examples_timer_demo</name>
7+
<maintainer email="[email protected]">Esteve Fernandez</maintainer>
8+
<!-- This project is not military-sponsored, Jacob's employment contract just requires him to use this email address -->
9+
<maintainer email="[email protected]">Jacob Hassold</maintainer>
10+
<version>0.4.1</version>
11+
<description>Package containing an example of how to use a worker in rclrs.</description>
12+
<license>Apache License 2.0</license>
13+
14+
<depend>rclrs</depend>
15+
<depend>rosidl_runtime_rs</depend>
16+
<depend>example_interfaces</depend>
17+
18+
<export>
19+
<build_type>ament_cargo</build_type>
20+
</export>
21+
</package>

examples/timer_demo/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// Creates a SimpleTimerNode, initializes a node and the timer with a callback
2+
/// that prints the timer callback execution iteration. The callback is executed
3+
/// thanks to the spin, which is in charge of executing the timer's events among
4+
/// other entities' events.
5+
use rclrs::*;
6+
use std::time::Duration;
7+
8+
fn main() -> Result<(), RclrsError> {
9+
let mut executor = Context::default_from_env()?.create_basic_executor();
10+
let node = executor.create_node("timer_demo")?;
11+
let worker = node.create_worker::<usize>(0);
12+
let timer_period = Duration::from_secs(1);
13+
let _timer = worker.create_timer_repeating(timer_period, move |count: &mut usize| {
14+
*count += 1;
15+
println!(
16+
"Drinking 🧉 for the {}th time every {:?}.",
17+
*count, timer_period,
18+
);
19+
})?;
20+
21+
executor.spin(SpinOptions::default()).first_error()
22+
}

examples/worker_demo/src/main.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rclrs::*;
2-
use std::sync::Arc;
2+
use std::time::Duration;
33

44
fn main() -> Result<(), RclrsError> {
55
let mut executor = Context::default_from_env()?.create_basic_executor();
@@ -15,27 +15,12 @@ fn main() -> Result<(), RclrsError> {
1515
},
1616
)?;
1717

18-
// // Use this timer-based implementation when timers are available instead
19-
// // of using std::thread::spawn.
20-
// let _timer = worker.create_timer_repeating(
21-
// Duration::from_secs(1),
22-
// move |data: &mut String| {
23-
// let msg = example_interfaces::msg::String {
24-
// data: data.clone()
25-
// };
26-
27-
// publisher.publish(msg).ok();
28-
// }
29-
// )?;
30-
31-
std::thread::spawn(move || loop {
32-
std::thread::sleep(std::time::Duration::from_secs(1));
33-
let publisher = Arc::clone(&publisher);
34-
let _ = worker.run(move |data: &mut String| {
18+
let _timer =
19+
worker.create_timer_repeating(Duration::from_secs(1), move |data: &mut String| {
3520
let msg = example_interfaces::msg::String { data: data.clone() };
36-
publisher.publish(msg).unwrap();
37-
});
38-
});
21+
22+
publisher.publish(msg).ok();
23+
})?;
3924

4025
println!(
4126
"Beginning repeater... \n >> \

0 commit comments

Comments
 (0)