LNMP-Spatial
Spatial awareness types and hybrid protocol for the LNMP ecosystem, enabling deterministic physical-world interaction in LLM → Machine → Robot → Simulation chains.
Features
- 🎯 Core Spatial Types: Position, Rotation, Velocity, Acceleration, Quaternion, BoundingBox
- 📦 Binary Codec: Efficient encoding/decoding (2-3ns latency)
- 🔄 Delta Encoding: 99% bandwidth reduction for incremental updates
- 🌊 Streaming Support: Continuous telemetry transmission
- 🏗️ Hybrid Protocol: Automatic ABS/DELTA mixing for robustness
- 🔮 Predictive Delta: Dead reckoning for packet loss resilience
- 🛡️ Frame Integrity: CRC32 checksums and nanosecond timestamps
- ⚡ High Frequency: Verified at 1kHz control loops
Quick Start
Add to your Cargo.toml:
[]
= { = "../lnmp-protocol/crates/lnmp-spatial" }
Basic Usage
use *;
// Create a position
let pos = Position3D ;
// Encode to binary
let mut buffer = Vecnew;
encode_spatial?;
// Decode from binary
let decoded = decode_spatial?;
Delta Encoding
use Delta;
let start = Position3D ;
let end = Position3D ;
// Compute delta (only differences)
let delta = compute_delta;
// delta = { dx: 1.0, dy: -1.0, dz: 2.0 }
// Apply delta
let reconstructed = apply_delta;
assert_eq!;
Hybrid Protocol
use ;
let config = SpatialStreamerConfig ;
let mut streamer = with_config;
// Sender
let frame = streamer.next_frame?;
// Receiver
let state = streamer.process_frame?;
Architecture
Protocol Stack
┌─────────────────────────────────────┐
│ Application (Robot Control) │
├─────────────────────────────────────┤
│ Hybrid Protocol (SpatialStreamer) │ ← Phase 3
│ - ABS/DELTA mixing │
│ - Sequence tracking │
│ - Predictive fallback │ ← Phase 5
├─────────────────────────────────────┤
│ Frame Layer │ ← Phase 4
│ - CRC32 checksum │
│ - Nanosecond timestamp │
├─────────────────────────────────────┤
│ Delta Layer │ ← Phase 2
│ - Compute delta │
│ - Apply delta │
├─────────────────────────────────────┤
│ Binary Codec │ ← Phase 1
│ - Encode/Decode │
│ - Type system │
└─────────────────────────────────────┘
Data Flow
Normal Operation (No Packet Loss):
Sender Receiver
│ │
├─[Frame 0: ABS]────────>│ ✓ Reset state
├─[Frame 1: DELTA]──────>│ ✓ Apply delta
├─[Frame 2: DELTA]──────>│ ✓ Apply delta
├─[Frame 3: DELTA]──────>│ ✓ Apply delta
...
├─[Frame 100: ABS]──────>│ ✓ Drift correction
Packet Loss (Predictive Mode):
Sender Receiver
│ │
├─[Frame 97: DELTA]─────>│ ✓ Apply delta
├─[Frame 98: DELTA]─────>│ ✓ Apply delta, Predict: 99
├─[Frame 99: DELTA]─X │ ❌ LOST → 🔮 Use prediction
├─[Frame 100: ABS]──────>│ ✓ Confirm/correct
Performance
Benchmarks on Apple Silicon M-series:
| Operation | Latency | Throughput |
|---|---|---|
| Encode Position3D | ~2.8 ns | ~357 M/s |
| Decode Position3D | ~2.2 ns | ~454 M/s |
| Compute Delta | ~5 ns | ~200 M/s |
| Spatial Transform | ~7.5 ns | ~133 M/s |
| Full Frame (Hybrid) | ~50 ns | ~20 M/s |
Bandwidth Savings:
- DELTA vs ABS: 99% reduction (typical)
- CRC32 overhead: <1%
Examples
Robot Arm Control
Telemetry Streaming
1kHz Control Loop
Prediction vs Non-Prediction
Design Philosophy
Why Hybrid?
"Robot arm moves with small delta steps, but resets with absolute position every breath."
- DELTA for speed and bandwidth efficiency (99% of frames)
- ABS for stability and drift correction (1% of frames)
- Prediction for packet loss resilience (fallback mechanism)
Safety-Critical Mode
For applications where prediction is unsafe (e.g., surgery robots):
let config = SpatialStreamerConfig ;
API Reference
See docs.rs or run:
License
MIT OR Apache-2.0