Skip to content

Latest commit

 

History

History
80 lines (54 loc) · 2.64 KB

File metadata and controls

80 lines (54 loc) · 2.64 KB

r2r Examples - Learning Path

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.

Prerequisites

Before running examples, ensure you have:

  1. ROS2 Jazzy installed (see setup.md)
  2. Rust toolchain (edition 2024)
  3. Environment sourced: source scripts/dev_env.sh

Examples

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

Usage

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_subscriber

Logging

All 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_publisher

See docs/logging.md for comprehensive documentation including:

  • All configuration options
  • Output format examples
  • Distributed tracing setup
  • Best practices

Learning Path

We recommend following this order:

  1. hello_publisher - Start here to understand basic publishing
  2. hello_subscriber - Learn to receive messages
  3. simple_timer - Explore timer-based patterns
  4. basic_service - Understand request/response communication

Testing Examples

For integration testing of multiple examples:

./scripts/sim_smoke.sh

Further Reading