| Crates.io | haply |
| lib.rs | haply |
| version | 0.7.1 |
| created_at | 2025-02-05 21:37:56.409527+00 |
| updated_at | 2025-10-21 16:07:51.028271+00 |
| description | Haply Robotics Client Library for the Inverse Service |
| homepage | |
| repository | https://gitlab.com/Haply/public/haply_rust |
| max_upload_size | |
| id | 1544748 |
| size | 223,678 |
Haply is a Rust client library for connecting to and controlling Haply Robotics devices via the Haply Inverse Service. It provides:
HaplyDevice) that talks HTTP and WebSocketThis README gives you a quick tour of the architecture, setup, and examples.
src/device.rs — High-level API. HaplyDevice manages:
interfaces::http::InverseHttpClient) for device lists and versioninterfaces::websocket::InverseWebSocketClient) for state and commandsTimestampedServiceData)ServiceMsg, always includes a session-level force_render_full_state marker)src/interfaces/ — Transport adapters
http.rs — REST endpoints (e.g., GET /version, GET /3.1/devices)websocket.rs — Real-time simulation/control channelevents.rs — Optional event channel client for device/session eventssrc/device_model/ — All request/response types used over HTTP/WS (device configs, states, commands, enums)src/physics.rs — Minimal physics helpers (e.g., Sphere, Cube, compute_total_force) used by demosCompanion mock service for local development:
haply-service-mock/ (separate crate inside this repo)
http://localhost:10000ws://localhost:10001ws://localhost:10020Prerequisites:
Install dependencies (Cargo will handle this on first build):
cd .\haply-service-mock
cargo run
cd ..
cargo run --example device_basics -- --http-only
Tip: enable logs for examples that rely on env_logger (e.g., haptic_sample):
$env:RUST_LOG = 'info'
use haply::HaplyDevice;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
// Defaults for the mock service
let http_base = "http://localhost:10000";
let ws_url = "ws://localhost:10001";
let mut device = HaplyDevice::new(http_base, ws_url).await?;
// List device configs via HTTP
let configs = device.list_devices().await?;
println!("Configs: {:?}", configs);
// Read the latest cached state
let state = device.read_state().await?;
println!("State: {:?}", state);
Ok(())
}
Examples live in the examples/ folder. Run any of them with:
cargo run --example <example_name>
Available examples and what they show:
device_basics — Multi-purpose starter. Use --http-only for REST discovery, --stream to print device IDs, --zero-force to keep zero forces applied, and optionally --probe <ID> to issue probe commands.events_demo — Connects to the Events WS and polls new events (set POLL_RATE env var to control interval).haptic_sample — Demonstrates a haptics loop that reads device state and applies forces derived from virtual objects.If you’re not using real hardware, start the mock service first (see Getting started).
The mock service emulates device configuration and real‑time data:
GET /version, GET /3.1/devices, GET /3.1/devices/:idset_cursor_force)Start it with:
cd .\haply-service-mock
cargo run
Then point your app/examples to:
http://localhost:10000ws://localhost:10001 (simulation/state/control)ws://localhost:10020 (events)src/
device.rs # HaplyDevice high-level API
interfaces/ # HTTP, WebSocket, and Events clients
device_model/ # Wire types shared with the service
physics.rs # Minimal physics helpers for demos
haply-service-mock/ # Local mock service (HTTP+WS)
examples/ # Example apps demonstrating common flows
$env:RUST_LOG = 'info'Dual-licensed under MIT or Apache-2.0 — see Cargo.toml for details.
See CHANGELOG.md.