Piper SDK
High-performance, cross-platform (Linux/Windows/macOS), zero-abstraction-overhead Rust SDK for AgileX Piper Robot Arm with support for high-frequency force control (500Hz).
β¨ Core Features
- π Zero Abstraction Overhead: Compile-time polymorphism, no virtual function table (vtable) overhead at runtime
- β‘ High-Performance Reads: Lock-free state reading based on
ArcSwap, nanosecond-level response - π Lock-Free Concurrency: RCU (Read-Copy-Update) mechanism for efficient state sharing
- π― Type Safety: Bit-level protocol parsing using
bilge, compile-time data correctness guarantees - π Cross-Platform Support (Linux/Windows/macOS):
- Linux: Based on SocketCAN (kernel-level performance)
- Windows/macOS: User-space GS-USB driver implementation using
rusb(driver-free/universal)
π οΈ Tech Stack
| Module | Crates | Purpose |
|---|---|---|
| CAN Interface | Custom CanAdapter |
Lightweight CAN adapter Trait (no embedded burden) |
| Linux Backend | socketcan |
Native Linux CAN support (planned) |
| USB Backend | rusb |
USB device operations on Windows/macOS, implementing GS-USB protocol |
| Protocol Parsing | bilge |
Bit operations, unaligned data processing, alternative to serde |
| Concurrency Model | crossbeam-channel |
High-performance MPSC channel for sending control commands |
| State Sharing | arc-swap |
RCU mechanism for lock-free reading of latest state |
| Error Handling | thiserror |
Precise error enumeration within SDK |
| Logging | tracing |
Structured logging |
π¦ Installation
Add the dependency to your Cargo.toml:
[]
= "0.0.1"
π Quick Start
Basic Usage
use PiperBuilder;
ποΈ Architecture Design
Hot/Cold Data Splitting
For performance optimization, state data is divided into three categories:
-
Hot Data (500Hz):
CoreMotionState: Core motion state (joint positions, end-effector pose)JointDynamicState: Joint dynamic state (joint velocities, currents)- Uses
ArcSwapfor lock-free reading, Frame Commit mechanism ensures atomicity
-
Warm Data (100Hz):
ControlStatusState: Control status (control mode, robot status, fault codes, etc.)- Uses
ArcSwapfor read/write operations, medium update frequency
-
Cold Data (10Hz or on-demand):
DiagnosticState: Diagnostic information (motor temperature, bus voltage, error codes, etc.)ConfigState: Configuration information (firmware version, joint limits, PID parameters, etc.)- Uses
RwLockfor read/write operations, low update frequency
Core Components
piper-rs/
βββ src/
β βββ lib.rs # Library entry, module exports
β βββ can/ # CAN communication adapter layer
β β βββ mod.rs # CAN adapter Trait and common types
β β βββ gs_usb/ # [Win/Mac] GS-USB protocol implementation
β β βββ mod.rs # GS-USB CAN adapter
β β βββ device.rs # USB device operations
β β βββ protocol.rs # GS-USB protocol definitions
β β βββ frame.rs # GS-USB frame structure
β βββ protocol/ # Protocol definitions (business-agnostic, pure data)
β β βββ ids.rs # CAN ID constants/enums
β β βββ feedback.rs # Robot arm feedback frames (bilge)
β β βββ control.rs # Control command frames (bilge)
β β βββ config.rs # Configuration frames (bilge)
β βββ robot/ # Core business logic
β βββ mod.rs # Robot module entry
β βββ robot_impl.rs # High-level Piper object (API)
β βββ pipeline.rs # IO Loop, ArcSwap update logic
β βββ state.rs # State structure definitions (hot/cold data splitting)
β βββ builder.rs # PiperBuilder (fluent construction)
β βββ error.rs # RobotError (error types)
Concurrency Model
Adopts asynchronous IO concepts but implemented with synchronous threads (ensuring deterministic latency):
- IO Thread: Responsible for CAN frame transmission/reception and state updates
- Control Thread: Lock-free reading of latest state via
ArcSwap, sending commands viacrossbeam-channel - Frame Commit Mechanism: Ensures the state read by control threads is a consistent snapshot at a specific time point
π Examples
Check the examples/ directory for more examples:
Note: Example code is under development. See examples/ directory for more examples.
Planned examples:
read_state.rs- Simple state reading and printingtorque_control.rs- Force control demonstrationconfigure_can.rs- CAN baud rate configuration tool
π€ Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
π License
This project is licensed under the MIT License. See the LICENSE file for details.
π Documentation
For detailed design documentation, see:
π Related Links
Note: This project is under active development. APIs may change. Please test carefully before using in production.