Skip to content

Commit 1d8c468

Browse files
committed
Add more documentation for Worker
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 402a9c9 commit 1d8c468

16 files changed

+273
-53
lines changed

examples/minimal_pub_sub/Cargo.toml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,9 @@ path = "src/zero_copy_publisher.rs"
2727

2828
[dependencies]
2929
anyhow = {version = "1", features = ["backtrace"]}
30-
31-
[dependencies.rclrs]
32-
version = "0.4"
33-
34-
[dependencies.rosidl_runtime_rs]
35-
version = "0.4"
36-
37-
[dependencies.std_msgs]
38-
version = "*"
30+
rclrs = "0.4"
31+
rosidl_runtime_rs = "0.4"
32+
example_interfaces = "*"
3933

4034
[package.metadata.ros]
4135
install_to_share = ["launch"]

examples/minimal_pub_sub/package.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
<build_depend>rclrs</build_depend>
1616
<build_depend>rosidl_runtime_rs</build_depend>
17-
<build_depend>std_msgs</build_depend>
17+
<build_depend>example_interfaces</build_depend>
1818

1919
<exec_depend>rclrs</exec_depend>
2020
<exec_depend>rosidl_runtime_rs</exec_depend>
21-
<exec_depend>std_msgs</exec_depend>
21+
<exec_depend>example_interfaces</exec_depend>
2222

2323
<export>
2424
<build_type>ament_cargo</build_type>

examples/minimal_pub_sub/src/minimal_publisher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ fn main() -> Result<(), Error> {
77

88
let node = executor.create_node("minimal_publisher")?;
99

10-
let publisher = node.create_publisher::<std_msgs::msg::String>("topic")?;
10+
let publisher = node.create_publisher::<example_interfaces::msg::String>("topic")?;
1111

12-
let mut message = std_msgs::msg::String::default();
12+
let mut message = example_interfaces::msg::String::default();
1313

1414
let mut publish_count: u32 = 1;
1515

examples/minimal_pub_sub/src/minimal_subscriber.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ fn main() -> Result<(), Error> {
88
let node = executor.create_node("minimal_subscriber")?;
99

1010
let worker = node.create_worker::<usize>(0);
11-
let _subscription = worker.create_subscription::<std_msgs::msg::String, _>(
11+
let _subscription = worker.create_subscription::<example_interfaces::msg::String, _>(
1212
"topic",
13-
move |num_messages: &mut usize, msg: std_msgs::msg::String| {
13+
move |num_messages: &mut usize, msg: example_interfaces::msg::String| {
1414
*num_messages += 1;
15-
println!("I heard: '{}'", msg.data);
16-
println!("(Got {} messages so far)", *num_messages);
15+
println!("#{} | I heard: '{}'", *num_messages, msg.data);
1716
},
1817
)?;
1918

examples/minimal_pub_sub/src/minimal_two_nodes.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use anyhow::{Error, Result};
55

66
struct MinimalSubscriberNode {
77
#[allow(unused)]
8-
subscription: WorkerSubscription<std_msgs::msg::String, SubscriptionData>,
8+
subscription: WorkerSubscription<example_interfaces::msg::String, SubscriptionData>,
99
}
1010

1111
struct SubscriptionData {
@@ -26,7 +26,7 @@ impl MinimalSubscriberNode {
2626

2727
let subscription = worker.create_subscription(
2828
topic,
29-
|data: &mut SubscriptionData, msg: std_msgs::msg::String| {
29+
|data: &mut SubscriptionData, msg: example_interfaces::msg::String| {
3030
data.num_messages += 1;
3131
println!("[{}] I heard: '{}'", data.node.name(), msg.data);
3232
println!(
@@ -50,12 +50,12 @@ fn main() -> Result<(), Error> {
5050
let _subscriber_node_two =
5151
MinimalSubscriberNode::new(&executor, "minimal_subscriber_two", "topic")?;
5252

53-
let publisher = publisher_node.create_publisher::<std_msgs::msg::String>("topic")?;
53+
let publisher = publisher_node.create_publisher::<example_interfaces::msg::String>("topic")?;
5454

5555
// TODO(@mxgrey): Replace this with a timer once we have the Timer feature
5656
// merged in.
5757
std::thread::spawn(move || -> Result<(), rclrs::RclrsError> {
58-
let mut message = std_msgs::msg::String::default();
58+
let mut message = example_interfaces::msg::String::default();
5959
let mut publish_count: u32 = 1;
6060
loop {
6161
message.data = format!("Hello, world! {}", publish_count);

examples/minimal_pub_sub/src/zero_copy_publisher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<(), Error> {
77

88
let node = executor.create_node("minimal_publisher")?;
99

10-
let publisher = node.create_publisher::<std_msgs::msg::rmw::UInt32>("topic")?;
10+
let publisher = node.create_publisher::<example_interfaces::msg::rmw::UInt32>("topic")?;
1111

1212
let mut publish_count: u32 = 1;
1313

examples/minimal_pub_sub/src/zero_copy_subscriber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ fn main() -> Result<(), Error> {
77
let node = executor.create_node("minimal_subscriber")?;
88

99
let worker = node.create_worker::<usize>(0);
10-
let _subscription = worker.create_subscription::<std_msgs::msg::UInt32, _>(
10+
let _subscription = worker.create_subscription::<example_interfaces::msg::UInt32, _>(
1111
"topic",
12-
move |num_messages: &mut usize, msg: ReadOnlyLoanedMessage<std_msgs::msg::UInt32>| {
12+
move |num_messages: &mut usize, msg: ReadOnlyLoanedMessage<example_interfaces::msg::UInt32>| {
1313
*num_messages += 1;
1414
println!("I heard: '{}'", msg.data);
1515
println!("(Got {} messages so far)", *num_messages);

rclrs/src/client.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,19 @@ where
105105
/// when the response is finished being processed, but otherwise you can
106106
/// safely discard it.
107107
///
108-
/// # Usage
108+
/// # Client Callbacks
109109
///
110110
/// Three callback signatures are supported:
111111
/// - [`FnOnce`] ( `Response` )
112112
/// - [`FnOnce`] ( `Response`, [`RequestId`][1] )
113113
/// - [`FnOnce`] ( `Response`, [`ServiceInfo`] )
114114
///
115115
/// [1]: crate::RequestId
116+
///
117+
/// Note that all of these are [`FnOnce`] which grants the greatest amount
118+
/// of freedom for what kind of operations you can perform within the
119+
/// callback. Just remember that this also means the callbacks are strictly
120+
/// one-time-use.
116121
pub fn call_then<'a, Req, Args>(
117122
&self,
118123
request: Req,
@@ -134,7 +139,7 @@ where
134139
/// when the response is finished being processed, but otherwise you can
135140
/// safely discard it.
136141
///
137-
/// # Usage
142+
/// # Async Client Callbacks
138143
///
139144
/// Three callback signatures are supported:
140145
/// - [`FnOnce`] ( `Response` ) -> impl [`Future`][1]<Output=()>

rclrs/src/client/client_async_callback.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ use crate::{RequestId, ServiceInfo};
77
/// A trait to deduce async callbacks of service clients.
88
///
99
/// Users of rclrs never need to use this trait directly.
10-
//
11-
// TODO(@mxgrey): Add a description of what callback signatures are supported
10+
///
11+
/// Three callback signatures are supported:
12+
/// - [`FnOnce`] ( `Response` ) -> impl [`Future`]<Output=()>
13+
/// - [`FnOnce`] ( `Response`, [`RequestId`] ) -> impl [`Future`]<Output=()>
14+
/// - [`FnOnce`] ( `Response`, [`ServiceInfo`] ) -> impl [`Future`]<Output=()>
1215
pub trait ClientAsyncCallback<T, Args>: Send + 'static
1316
where
1417
T: Service,

rclrs/src/client/client_callback.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ use crate::{RequestId, ServiceInfo};
55
/// A trait to deduce regular callbacks of service clients.
66
///
77
/// Users of rclrs never need to use this trait directly.
8-
//
9-
// TODO(@mxgrey): Add a description of what callback signatures are supported
8+
///
9+
/// Three callback signatures are supported:
10+
/// - [`FnOnce`] ( `Response` )
11+
/// - [`FnOnce`] ( `Response`, [`RequestId`] )
12+
/// - [`FnOnce`] ( `Response`, [`ServiceInfo`] )
1013
pub trait ClientCallback<T, Args>: Send + 'static
1114
where
1215
T: Service,

0 commit comments

Comments
 (0)