nros/guide/getting_started.rs
1//! # Getting Started
2//!
3//! ## Prerequisites
4//!
5//! - [Rust](https://rustup.rs/) nightly toolchain (edition 2024)
6//! - zenohd 1.6.2 router (build from submodule with `just build-zenohd`,
7//! or install from [zenoh releases](https://github.com/eclipse-zenoh/zenoh/releases))
8//! - ROS 2 Humble (optional — only needed for message packages beyond
9//! `std_msgs` and `builtin_interfaces`, which are bundled)
10//!
11//! ## 1. Create a project
12//!
13//! ```bash
14//! cargo new my-talker && cd my-talker
15//! ```
16//!
17//! Add nros and your message crate to `Cargo.toml`:
18//!
19//! ```toml
20//! [package]
21//! name = "my-talker"
22//! version = "0.1.0"
23//! edition = "2024"
24//!
25//! [dependencies]
26//! nros = { git = "https://github.com/jerry73204/nano-ros", default-features = false, features = ["std"] }
27//! std_msgs = { version = "*", default-features = false }
28//! ```
29//!
30//! ## 2. Declare message dependencies
31//!
32//! Create a `package.xml` in the project root:
33//!
34//! ```xml
35//! <?xml version="1.0"?>
36//! <package format="3">
37//! <name>my_talker</name>
38//! <version>0.1.0</version>
39//! <description>My first nros talker</description>
40//! <maintainer email="you@example.com">You</maintainer>
41//! <license>MIT</license>
42//! <depend>std_msgs</depend>
43//! <export><build_type>ament_cargo</build_type></export>
44//! </package>
45//! ```
46//!
47//! ## 3. Generate message bindings
48//!
49//! Build the `nros` tool (one-time, from a nano-ros checkout — in a
50//! checkout the tree's own build is the binary it accepts, RFC-0090;
51//! to just USE nano-ros, install a release with `scripts/install.sh`):
52//!
53//! ```bash
54//! ./scripts/bootstrap.sh # builds packages/cli/target/release/nros
55//! source ./activate.sh # puts it on PATH
56//! ```
57//!
58//! Generate bindings (for packages beyond `std_msgs`/`builtin_interfaces`,
59//! source a ROS 2 environment first):
60//!
61//! ```bash
62//! nros generate-rust --config --nano-ros-git
63//! ```
64//!
65//! This creates:
66//! - `generated/std_msgs/` — Rust types (`Int32`, `String`, etc.)
67//! - `generated/builtin_interfaces/` — `Time`, `Duration`
68//! - `.cargo/config.toml` — `[patch.crates-io]` entries
69//!
70//! Key options: `--force` (overwrite existing), `--nano-ros-path <PATH>`
71//! (local dev instead of git), `-o <DIR>` (output directory, default
72//! `generated`).
73//!
74//! ## 4. Build and run
75//!
76//! ```bash
77//! # Terminal 1: start zenoh router
78//! ZENOH_CONFIG_OVERRIDE='listen/endpoints=["tcp/127.0.0.1:7447"];scouting/multicast/enabled=false' ros2 run rmw_zenoh_cpp rmw_zenohd
79//!
80//! # Terminal 2: run your node
81//! RUST_LOG=info cargo run --features zenoh
82//! ```
83//!
84//! To verify with a ROS 2 listener:
85//!
86//! ```bash
87//! source /opt/ros/humble/setup.bash
88//! export RMW_IMPLEMENTATION=rmw_zenoh_cpp
89//! ros2 topic echo /chatter std_msgs/msg/Int32 --qos-reliability best_effort
90//! ```