Skip to content

Commit 9eba93f

Browse files
author
GueLaKais
committed
Spellchecking
1 parent 1365bee commit 9eba93f

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

docs/writing_a_simple_publisher_and_subscriber.md

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Writing a simple publisher and subscriber (RUST)
2-
* Goal: Create and run a publisher and subscriber node using Python.
2+
* Goal: Create and run a publisher and subscriber node using RUST.
33
* Tutorial level: Beginner
44
* Time: 20 minutes
55
<details><summary>Background</summary>
@@ -8,40 +8,42 @@ In this tutorial you will create a pair of
88
[nodes](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Nodes/Understanding-ROS2-Nodes.html) that pass information to each other via a
99
[topic](https://docs.ros.org/en/humble/Tutorials/Beginner-CLI-Tools/Understanding-ROS2-Topics/Understanding-ROS2-Topics.html) in the form of string messages. The example used here is a simple "talker" and "listener" system; one node publishes data and the other subscribes to the topic to receive that data.
1010

11-
Since Rust doesn't have inheritance, it's not possible to inherit from `Node` as is common practice in [`rclcpp`](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html) or [`rclpy`](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html).
11+
Since RUST doesn't have inheritance, it's not possible to inherit from `Node` as is common practice in [`rclcpp`](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html) or [`rclpy`](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html).
1212

13-
The code used in these examples can be found [here](https://gitlab.com/ros21923912/simple_ros2_node)
13+
The code used in these examples can be found [here](https://gitlab.com/ROS21923912/simple_ROS2_node)
1414
<div style="margin-left:20px;">
1515
<details><summary>Side-note on dependencies</summary>
1616

17-
You may be wondering why you can't just add all your ros2-specific dependencies to `cargo.toml` with `cargo add ${dependencie}` and have to edit this file manually. Here is why:
18-
Almost none of the ROS2 dependencies you'll need for your ros2 rust node development currently exist on [crates.io](https://crates.io/), the main source for rust depencies. So the add command simply can't find the dependency targets. What colcon does by compiling the ros2 rust dependencies and your ros2 rust project is redirect the cargo search for dependencies directly into your `workspace/install` folder, where it'll find locally generated rust projects to use as dependencies. In particular, almost all message types will be called as dependencies for your ros2 rust project this way.
17+
You may be wondering why you can't just add all your ROS2-specific dependencies to `Cargo.toml` with `cargo add YOUR_DEPENDENCIES` and have to edit this file manually. Here is why:
18+
Almost none of the ROS2 dependencies you'll need for your ROS2 RUST node development currently exist on [crates.io](https://crates.io/), the main source for RUST depencies. So the add command simply can't find the dependency targets. What colcon does by compiling the ROS2 RUST dependencies and your ROS2 RUST project is redirect the cargo search for dependencies directly into your `workspace/install` folder, where it'll find locally generated RUST projects to use as dependencies. In particular, almost all message types will be called as dependencies for your ROS2 RUST project this way.
1919

2020
</details></div>
2121

2222
</details>
2323

2424
<details><summary>Prerequisites </summary>
2525

26-
In previous tutorials, you learned how to create a [workspace](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html) and [create a package](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html).
26+
Basic concepts of development with ROS2 should be known:
27+
* [workspaces](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-A-Workspace/Creating-A-Workspace.html)
28+
* [packages](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html).
2729

28-
A basic understanding of [RUST](https://www.rust-lang.org/) is recommended, but not entirely necessary.
29-
Before developing ROS2 RUST nodes, you must follow the
30-
[installation instructions](https://github.com/ros2-rust/ros2_rust/blob/main/README.md) for [`rclrs`](https://docs.rs/rclrs/latest/rclrs/).
30+
A basic understanding of [RUST](https://doc.rust-lang.org/book/) is recommended, but not entirely necessary.
31+
Before developing [ros2-rust](https://github.com/ros2-rust/ros2_rust) nodes, you must follow the
32+
[installation instructions](https://github.com/ros2-rust/ros2-rust/blob/main/README.md) for [`rclrs`](https://docs.rs/rclrs/latest/rclrs/).
3133

3234

3335
</details>
3436

3537
<details><summary>Tasks </summary>
3638
<div style="margin-left:20px;"><details><summary>Create a Package</summary>
3739

38-
Currently, building a package for ROS2 RUST is different
39-
from building packages for Python or C/C++.
40+
Currently, building a package for ros2-rust is different
41+
from building packages for [Python](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html) or [C/C++](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html).
4042

4143
First, you'll need to create and go into a standard [cargo](https://doc.rust-lang.org/cargo/)
4244
project as follows:
4345
```
44-
cargo new your_project_name && cd your_project_name
46+
cargo new your_package_name && cd your_package_name
4547
```
4648
In the [`Cargo.toml`](https://doc.rust-lang.org/book/ch01-03-hello-cargo.html) file, add a dependency on `rclrs = "*"` and `std_msgs = "*"` by editing this file. For a full Introduction into RUST, please read the very good [RUST book](https://doc.rust-lang.org/book/title-page.html). Your `Cargo.toml` could now look like this:
4749
```
@@ -61,7 +63,7 @@ std_msgs = "*"
6163
Additionally, create a new `package.xml` if you want your node to be buildable with [`colcon`](https://colcon.readthedocs.io/en/released/user/installation.html). Make sure to change the build type to `ament_cargo` and to include the two packages mentioned above in the dependencies, as such:
6264
```xml
6365
<package format="3">
64-
<name>your_project_name</name>
66+
<name>your_package_name</name>
6567
<version>0.0.0</version>
6668
<description>TODO: Package description.</description>
6769
<maintainer email="user@todo.todo">user</maintainer>
@@ -106,7 +108,7 @@ struct SimplePublisherNode {
106108
node: Arc<Node>,
107109
_publisher: Arc<Publisher<StringMsg>>,
108110
}
109-
/// An impl block in Rust defines methods or associated functions for a specific type.
111+
/// An impl block in RUST defines methods or associated functions for a specific type.
110112
///
111113
/// The `new` function takes a context and returns a Result containing the
112114
/// initialized SimplePublisherNode or an error. It creates a node with the
@@ -170,7 +172,7 @@ fn main() -> Result<(),RclrsError> {
170172

171173
<details><summary>Examining the code in detail:</summary>
172174

173-
#### The first 3 lines of the Rust code imports tools for thread synchronization, time handling, iteration, threading, ROS 2 communication, and string message publishing.
175+
#### The first 3 lines of the RUST code imports tools for thread synchronization, time handling, iteration, threading, ROS 2 communication, and string message publishing.
174176
```
175177
use std::{sync::Arc,time::Duration,iter,thread};
176178
use rclrs::{RclrsError,QOS_PROFILE_DEFAULT,Context,create_node,Node,Publisher};
@@ -283,7 +285,7 @@ fn main() -> Result<(),RclrsError> {
283285

284286
</details>
285287
</details>
286-
<details><summary>Having several Ros2 rust nodes in one Package</summary>
288+
<details><summary>Having several ROS2 RUST nodes in one Package</summary>
287289

288290
Of course, you can write for each node you want to implement its own package, and that can have it's advantages. I implore you to use some cargo tricks and add some binary targets to your `cargo.toml`. That could look like this:
289291
```
@@ -300,7 +302,7 @@ path="src/main.rs"
300302
rclrs = "*"
301303
std_msgs = "*"
302304
```
303-
You'll find the name of your executable and the corresponding file name under the `[[bin]]` tag. As you can see, the filename and the name you want to call your node don't have to match. Please remember to include your executable name with snake_cases. The rust compiler will be a bit grumpy if you don't.
305+
You'll find the name of your executable and the corresponding file name under the `[[bin]]` tag. As you can see, the filename and the name you want to call your node don't have to match. Please remember to include your executable name with snake_cases. The RUST compiler will be a bit grumpy if you don't.
304306
Now, by recompiling the package from the previous chapter and making it usable:
305307
```
306308
cd ${MainFolderOfWorkspace}
@@ -315,7 +317,7 @@ As you can see, you are now calling your node by the name declared in `[[bin]]`
315317
</details>
316318
<details><summary>Write the subscriber node</summary>
317319

318-
Of course, you can implement a new ros2 rust package for this node. You can find out how to do this in the section called 'Create a package'.
320+
Of course, you can implement a new ROS2 RUST package for this node. You can find out how to do this in the section called 'Create a package'.
319321
Or you can add a new binary target to your package. To do so, just add a new `<file>.rs` to your source directory - for simplicity I'll call this file `simple_subscriber.rs` - and add a corresponding binary target to your `Cargo.toml`:
320322
```
321323
[[bin]]
@@ -479,11 +481,11 @@ Once you have implemented the code, you are ready to make it runnable:
479481
cd ${MainFolderOfWorkspace}
480482
colcon build
481483
```
482-
Please note that you'll need to run your nodes in separate terminals. In each terminal, you'll need to source your ros2 installation separately. So for each of the two nodes you've built so far, open a terminal and type the following:
484+
Please note that you'll need to run your nodes in separate terminals. In each terminal, you'll need to source your ROS2 installation separately. So for each of the two nodes you've built so far, open a terminal and type the following:
483485
```
484486
cd ${MainFolderOfWorkspace}
485487
source install/setup.bash
486-
ros2 run your_project_name your_node_name
488+
ros2 run your_package_name your_node_name
487489
```
488490
In my case, the nodes are called `simple_publisher` and `simple_subscriber`. You can name your nodes whatever you like. It is important that the publisher and subscriber use the same topic type and name.
489491
If you haven't had any errors so far and have successfully started the Publisher and Subscriber, you should see something similar in the Subscriber's Terminal window:

0 commit comments

Comments
 (0)