This directory contains minimal, well-documented examples demonstrating core r2r patterns for ROS2 in Rust. Each example is a standalone binary designed to teach specific concepts.
Before running examples, ensure you have:
- ROS2 Jazzy installed (see setup.md)
- Rust toolchain (edition 2024)
- Environment sourced:
source scripts/dev_env.sh
| Example | What You'll Learn |
|---|---|
hello_publisher |
• Creating a ROS2 node with r2r • Publishing messages to topics • Configuring QoS profiles • Using tokio intervals for periodic tasks |
hello_subscriber |
• Subscribing to ROS2 topics • Async message handling with r2r • Processing incoming messages |
simple_timer |
• Timer-based periodic publishing • Using tokio::select! for concurrent operations• Timeout detection patterns • Multi-task coordination |
basic_service |
• Creating service servers • Calling services as a client • Request/response communication • Running server and client in one binary |
Run any example with:
# Source ROS2 environment
source scripts/dev_env.sh
# Run an example
cargo run --example hello_publisher
# In another terminal (for subscriber/service examples)
cargo run --example hello_subscriberAll examples use structured logging with OpenTelemetry support. Configure via environment variables:
# Show debug logs
RUST_LOG=debug cargo run --example hello_publisher
# JSON output (for log aggregation)
LOG_FORMAT=json cargo run --example hello_publisher
# OpenTelemetry export (requires collector)
LOG_FORMAT=otlp OTLP_ENDPOINT=http://localhost:4317 cargo run --example hello_publisherSee docs/logging.md for comprehensive documentation including:
- All configuration options
- Output format examples
- Distributed tracing setup
- Best practices
We recommend following this order:
- hello_publisher - Start here to understand basic publishing
- hello_subscriber - Learn to receive messages
- simple_timer - Explore timer-based patterns
- basic_service - Understand request/response communication
For integration testing of multiple examples:
./scripts/sim_smoke.sh