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