Haply Inverse SDK
Haply Inverse SDK 는 Haply의 촉각 장치(Inverse3,Inverse3x,Minverse,VerseGrip및 Wireless VerseGrip)을 위한 언어 독립적인 WebSocket + HTTP 인터페이스입니다. 이 서비스는 장치 감지, 직렬 통신, 안전성 모니터링, 상태 스트리밍을 처리하는 로컬 서비스로 작동하므로, 애플리케이션은 소켓을 통해 JSON으로 통신하기만 하면 됩니다.
주요 기능은 다음과 같습니다:
- 기기 감지 및 관리 — HTTP REST API를 통해 연결된 Haply 기기를 자동으로 열거하고 설정합니다.
- 실시간 상태 스트리밍 — WebSocket을 통해 촉각 제어 속도(수 kHz)로 장치의 상태를 전송합니다.
- 명령 처리 — 정밀한 촉각 피드백을 위해 힘 및 위치 명령을 높은 정확도로 실행합니다.
- 백그라운드 실행 — 로컬 서비스로 실행되며, 사용자의 조작 없이도 기기의 준비 상태를 유지합니다.
Haply Hub를 통한 설치
가장 쉽게 시작하는 방법은,Haply Hub 를 사용하는 것입니다. 이는 Haply 장치를 설치, 실행, 설정, 테스트 및 모니터링하기 위한 데스크톱 애플리케이션입니다. 펌웨어를 최신 상태로 유지해 주며, Inverse Service를 포함하고 있어 코드를 한 줄도 작성하기 전에 하드웨어를 검증할 수 있는 데모도 제공합니다.

Haply Hub
Haply Hub의 최신 버전 다운로드
Hub를 다운로드하여 설치한 후 기기를 연결해 주세요. Hub에서 펌웨어 업데이트를 안내해 드립니다. 설치가 완료되면 Hub를 실행 중일 때 Inverse Service가 백그라운드에서 자동으로 실행됩니다.
Hub를 사용하지 않고도 Inverse Service의 특정 버전을 시스템 서비스(Windows) 또는 데몬(Linux/macOS)으로 설치할 수 있습니다. 설치 프로그램 링크 및 설치 절차에 대해서는‘서비스 실행’을 참조하십시오.
간단한 예시
서비스에 연결하고, Inverse3의 초기 커서 위치를 읽은 다음, 서비스가 상태 프레임 스트리밍을 계속할 수 있도록 강도가 0인 키프얼라이브를 전송합니다:
- 파이썬
- 자바스크립트 (Node)
- C++ (nlohmann)
- C++ (최적화)
- 러스트
import asyncio, json, websockets
async def main():
# Connect to the Haply Inverse service WebSocket
async with websockets.connect("ws://localhost:10001") as ws:
# Read the first state frame to discover the device id
first_state = json.loads(await ws.recv())
device_id = first_state["inverse3"][0]["device_id"]
# Build a zero-force keepalive command targeting that device
keepalive = {"inverse3": [{
"device_id": device_id,
"commands": {"set_cursor_force": {"vector": {"x": 0, "y": 0, "z": 0}}}
}]}
# Realtime loop: one send per tick, then read the resulting state
while True:
await ws.send(json.dumps(keepalive))
state = json.loads(await ws.recv())
pos = state["inverse3"][0]["state"]["cursor_position"]
print(f"pos: {pos}")
asyncio.run(main())
import WebSocket from 'ws'
// Connect to the Haply Inverse service WebSocket
const ws = new WebSocket('ws://localhost:10001')
let keepalive
ws.on('message', (msg) => {
const state = JSON.parse(msg)
if (!keepalive) {
// Read the first state frame to discover the device id
const deviceId = state.inverse3[0].device_id
// Build a zero-force keepalive command targeting that device
keepalive = JSON.stringify({
inverse3: [
{
device_id: deviceId,
commands: { set_cursor_force: { vector: { x: 0, y: 0, z: 0 } } },
},
],
})
ws.send(keepalive)
return
}
// Realtime loop: one send per tick, then read the resulting state
ws.send(keepalive)
console.log('pos:', state.inverse3[0].state.cursor_position)
})
#include <external/libhv.h>
#include <nlohmann/json.hpp>
int main() {
hv::WebSocketClient ws;
nlohmann::json keepalive;
ws.onmessage = [&](const std::string& msg) {
auto state = nlohmann::json::parse(msg);
if (keepalive.is_null()) {
// Read the first state frame to discover the device id
auto device_id = state["inverse3"][0]["device_id"];
// Build a zero-force keepalive command targeting that device
keepalive = {{"inverse3", nlohmann::json::array({{
{"device_id", device_id},
{"commands", {{"set_cursor_force",
{{"vector", {{"x", 0}, {"y", 0}, {"z", 0}}}}}}}
}})}};
ws.send(keepalive.dump());
return;
}
// Realtime loop: one send per tick, then read the resulting state
ws.send(keepalive.dump());
auto pos = state["inverse3"][0]["state"]["cursor_position"];
std::cout << "pos: " << pos << "\n";
};
// Connect to the Haply Inverse service WebSocket
ws.open("ws://localhost:10001");
std::cin.get();
}
컴파일 시 리플렉션에는Glaze를 사용합니다. 이는 세계에서 가장 빠른 JSON 라이브러리 중 하나입니다. 촉각 속도(수 kHz)에서는 JSON 파싱에 소요되는 1마이크로초가 그대로 제어 루프에서 빼앗기는 1마이크로초가 되므로, 이 점은 중요합니다. 읽기 및 쓰기에 필요한 최소한의 형상만 선언해 주십시오. 그 외의 내용은 무시됩니다.
#include <external/libhv.h>
#include <glaze/glaze.hpp>
struct vec3 { float x{}, y{}, z{}; };
struct inverse_state { vec3 cursor_position; };
struct inverse_device { std::string device_id; inverse_state state; };
struct devices_message { std::vector<inverse_device> inverse3; };
struct set_cursor_force_cmd { vec3 vector; };
struct device_cmd { std::string device_id;
struct { std::optional<set_cursor_force_cmd> set_cursor_force; } commands; };
struct commands_message { std::vector<device_cmd> inverse3; };
int main() {
hv::WebSocketClient ws;
commands_message keepalive;
ws.onmessage = [&](const std::string& msg) {
devices_message state{};
if (glz::read_json(state, msg)) return;
if (keepalive.inverse3.empty()) {
// Read the first state frame to discover the device id
auto device_id = state.inverse3[0].device_id;
// Build a zero-force keepalive command targeting that device
keepalive.inverse3.push_back({device_id});
keepalive.inverse3[0].commands.set_cursor_force = set_cursor_force_cmd{};
std::string out; (void)glz::write_json(keepalive, out);
ws.send(out);
return;
}
// Realtime loop: one send per tick, then read the resulting state
std::string out; (void)glz::write_json(keepalive, out);
ws.send(out);
printf("pos: %f %f %f\n", state.inverse3[0].state.cursor_position.x,
state.inverse3[0].state.cursor_position.y,
state.inverse3[0].state.cursor_position.z);
};
// Connect to the Haply Inverse service WebSocket
ws.open("ws://localhost:10001");
std::cin.get();
}
tokio-tungstenite + serde_json 를 사용한 설명용 예시입니다.
use futures_util::{SinkExt, StreamExt};
use serde_json::json;
use tokio_tungstenite::{connect_async, tungstenite::Message};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Connect to the Haply Inverse service WebSocket
let (mut ws, _) = connect_async("ws://localhost:10001").await?;
// Read the first state frame to discover the device id
let first = match ws.next().await {
Some(Ok(Message::Text(m))) => m,
_ => anyhow::bail!("no initial state frame"),
};
let first_state: serde_json::Value = serde_json::from_str(&first)?;
let device_id = first_state["inverse3"][0]["device_id"].as_str().unwrap();
// Build a zero-force keepalive command targeting that device
let keepalive = json!({
"inverse3": [{
"device_id": device_id,
"commands": { "set_cursor_force": { "vector": { "x": 0, "y": 0, "z": 0 } } }
}]
}).to_string();
// Realtime loop: one send per tick, then read the resulting state
loop {
ws.send(Message::Text(keepalive.clone())).await?;
let msg = match ws.next().await {
Some(Ok(Message::Text(m))) => m,
_ => break,
};
let state: serde_json::Value = serde_json::from_str(&msg)?;
println!("pos: {}", state["inverse3"][0]["state"]["cursor_position"]);
}
Ok(())
}
힘의 값을 변경할 때는 각별히 주의하십시오. 갑자기 너무 큰 힘의 값을 설정하면 장치가 손상되거나 예기치 않은 동작이 발생할 수 있습니다.
메시지의 엔벨로프, 포트, 콘텐츠 유형에 관한 규칙은JSON 사양 페이지를 참조하십시오.
기타 예시
Python, C++(nlohmann), C++(Glaze)로 제작된, 힘 피드백, 위치 제어, 다중 장치 구성, 마운트/베이스 설정, 이벤트 스트리밍을 다루는 고기능 튜토리얼에 대해서는튜토리얼 페이지를 참조하십시오.