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 — nano-ros
50//! is a source distribution; there is no prebuilt `nros`):
51//!
52//! ```bash
53//! ./scripts/bootstrap.sh # builds packages/cli/target/release/nros
54//! source ./activate.sh # puts it on PATH
55//! ```
56//!
57//! Generate bindings (for packages beyond `std_msgs`/`builtin_interfaces`,
58//! source a ROS 2 environment first):
59//!
60//! ```bash
61//! nros generate-rust --config --nano-ros-git
62//! ```
63//!
64//! This creates:
65//! - `generated/std_msgs/` — Rust types (`Int32`, `String`, etc.)
66//! - `generated/builtin_interfaces/` — `Time`, `Duration`
67//! - `.cargo/config.toml` — `[patch.crates-io]` entries
68//!
69//! Key options: `--force` (overwrite existing), `--nano-ros-path <PATH>`
70//! (local dev instead of git), `-o <DIR>` (output directory, default
71//! `generated`).
72//!
73//! ## 4. Build and run
74//!
75//! ```bash
76//! # Terminal 1: start zenoh router
77//! zenohd --listen tcp/127.0.0.1:7447
78//!
79//! # Terminal 2: run your node
80//! RUST_LOG=info cargo run --features zenoh
81//! ```
82//!
83//! To verify with a ROS 2 listener:
84//!
85//! ```bash
86//! source /opt/ros/humble/setup.bash
87//! export RMW_IMPLEMENTATION=rmw_zenoh_cpp
88//! ros2 topic echo /chatter std_msgs/msg/Int32 --qos-reliability best_effort
89//! ```