06. Combiné (Inverse3 + Wireless VerseGrip)
두 대의 기기를 사용하는 튜토리얼: 핸들을 가리키고 버튼을 길게 누르면 커서 Inverse3 가 해당 방향으로 이동합니다. 커서는 구형 작업 공간 내에서만 이동할 수 있습니다.
이 강좌에서 배우게 될 내용:
- 동일한 상태 프레임에서 두 가지 유형의 장치를 읽기 (
inverse3etwireless_verse_grip) - 손잡이의 방향 정보를 그 위치에서 추출하기 쿼터니언 (axe local
+Y) - 사용하기
set_cursor_position계산된 목표물로 커서를 이동하려면 - 대상 범위를 안전한 작업 공간 영역으로 제한 — Minverse 는 다음보다 더 작은 반경을 사용합니다. Inverse3
- 정의하기 작업 공간 사전 설정 (
arm_front_centered) 악보의 시작점이 오선지 중앙에 오도록 하기 위해
진행 과정
- 두 기기를 감지합니다:
- 변형 C++ 의문형
GET /devices시작 시 HTTP를 통해 접속한 후, 보정 요청 메시지를 표시하고 사용자가 Enter 키를 누를 때까지 대기합니다. - 파이썬은 WebSocket의 첫 번째 상태 프레임에서 두 기기의 식별자를 읽어왔습니다.
- 변형 C++ 의문형
- 저장하세요 세션 프로필 그리고 다음을 정의하십시오
configure.preset: arm_front_centered첫 번째 메시지에서 (단 한 번의 연락). - 매 주기마다 다음을 읽어보세요.
orientation손잡이와 상태buttons.{a, b}. - 이동 버튼이 눌려 있는 경우, 월드 공간에서 핸들의 방향을 계산하십시오 (
R(q) · ĵ— (회전된 +Y 단위축)을 곱한 뒤, 이를SPEED그리고 이를 대상 위치에 추가하십시오. - 대상을 작업 공간 영역 내로 제한하고 다음을 통해 전송하십시오.
set_cursor_position. - (파이썬 전용) 다음 조건에 따라 구의 반지름을 조정하십시오.
config.type기기의 —minverse= 0.04 m, 그 외 모두 = 0.10 m.
매개변수
| Nom | 기본값 | 역할 |
|---|---|---|
SPEED | 0.01 m/cycle | 버튼을 누르고 있는 동안에는 이동하지 않습니다 |
RADIUS_INVERSE3 | 0.10 m | Inverse3 /Inverse3x의 작업 공간 제약 반경 |
RADIUS_MINVERSE | 0.04 m | Minverse 의 작업 공간 제약 반경 (Python 전용 — C++ 수정됨) 0.10 (en dur) |
PRINT_EVERY_MS | 200 | 텔레메트리 데이터 전송량 제한 |
| 세션 프로필 이름 | co.haply.inverse.tutorials:combined | Haply Hub에서 이 시뮬레이션을 식별하세요. |
- Inverse3 가 자동으로 보정되도록 두십시오(또는 손잡이를 잉크병 위에 올려놓고 LED가 깜빡임이 멈추고 계속 켜져 있을 때까지 기다리십시오).
- 잉크병에서 손잡이를 분리하십시오.
- A 또는 B 버튼을 누른 상태에서 손잡이를 돌리면, 커서가 손잡이가 가리키는 방향으로 이동합니다.
가장 많이 읽힌 주 챔피언십 기사
각 사이클의 상태 프레임에 기초하여:
data.inverse3[0].state.cursor_position—vec3data.wireless_verse_grip[0].state.orientation—quaterniondata.wireless_verse_grip[0].state.buttons.{a, b, c}— 부울 값- (파이썬, 첫 번째 프레임만)
data.inverse3[0].config.type— Inverse3 의 반지름을 선택하거나 Minverse - (파이썬, 첫 번째 프레임만)
data.inverse3[0].status.calibrated— 값이 잘못된 경우 사용자에게 보정을 요청합니다
발송 및 수신
쿼터니언을 이용한 방향 계산 (회전) +Y par R(q)) 및 구면 제약 조건은 고전 선형 대수학의 영역에 속합니다 — 소스 파일을 참조하십시오. Inverse API 측면에서는 초기 연결 설정과 set_cursor_position 매 주기마다.
- 파이썬
- C++ (nlohmann)
- C++ (Glaze)
비동기식 단일 루프. 파이썬은 첫 번째 상태 프레임에서 두 기기의 식별자를 읽으며, 연결 수립 시 프로필을 첨부하고 configure.preset: arm_front_centered 첫 번째 set_cursor_position.
async with websockets.connect(URI) as websocket:
while True:
msg = await websocket.recv()
data = json.loads(msg)
if first_message:
first_message = False
inverse3_id = data["inverse3"][0]["device_id"]
grip_id = data["wireless_verse_grip"][0]["device_id"]
radius = get_workspace_radius(data["inverse3"][0].get("config", {}))
# Handshake: profile + preset + first position command
request_msg = {
"session": {"configure": {"profile": {"name": SLUG}}},
"inverse3": [{
"device_id": inverse3_id,
"configure": {"preset": {"preset": "arm_front_centered"}},
"commands": {"set_cursor_position": {"position": position}},
}],
}
else:
# Per tick: update position from grip pointing direction (classic math, not shown), send
request_msg = {
"inverse3": [{
"device_id": inverse3_id,
"commands": {"set_cursor_position": {"position": position}},
}],
}
await websocket.send(json.dumps(request_msg))
C++은 다음을 통해 두 기기의 식별자를 파악합니다. GET /devices 시작 시 (HTTP)를 실행한 다음, WebSocket을 엽니다. onmessage libhv의 I/O 스레드에서 실행되며, 메인 스레드는 입력을 기다리는 상태로 차단됩니다.
// Startup (synchronous):
const std::string inv3_device_id = get_first_device_id("inverse3");
const std::string grip_device_id = get_first_device_id("wireless_verse_grip");
// Per tick:
ws.onmessage = [&](const std::string &msg) {
json data = json::parse(msg);
// ... classic math (not shown): update local Inverse3State + WirelessVerseGripState,
// compute new position from grip orientation, clamp to sphere ...
json command;
command["inverse3"] = json::array();
command["inverse3"].push_back({
{"device_id", inv3_device_id},
{"commands", {{"set_cursor_position",
{{"position", {{"x", pos.x}, {"y", pos.y}, {"z", pos.z}}}}}}}
});
if (first_message) {
first_message = false;
command["session"] = {{"configure", {{"profile",
{{"name", "co.haply.inverse.tutorials:combined"}}}}}};
command["inverse3"][0]["configure"] = {
{"preset", {{"preset", "arm_front_centered"}}}};
}
ws.send(command.dump());
};
ws.open("ws://localhost:10001");
while (std::cin.get() != '\n') {} // block main thread
libhv와 동일한 호출 모델입니다. 유형이 지정된 구조체는 상태 프레임과 출력 명령을 모두 모델링합니다 — 이 두 가지 std::vector<> dans devices_message 이를 통해 한 명의 glz::read 두 종류의 기기를 생산하는 것.
// Struct models
struct quat { float w{1.0f}, x{}, y{}, z{}; };
struct button_state { bool a{}, b{}, c{}; };
struct wvg_state { quat orientation{}; uint8_t hall{}; button_state buttons{}; };
struct wvg_device { std::string device_id; wvg_state state; };
struct inverse_state { vec3 cursor_position{}, cursor_velocity{}; };
struct inverse_device { std::string device_id; inverse_state state; };
struct devices_message {
std::vector<inverse_device> inverse3;
std::vector<wvg_device> wireless_verse_grip;
};
struct set_cursor_position_cmd { vec3 position; };
struct commands_message {
std::optional<session_cmd> session;
std::vector<device_commands> inverse3;
};
// Send / receive
ws.onmessage = [&](const std::string &msg) {
devices_message data{};
if (glz::read<glz_settings>(data, msg)) return;
const auto &wvg = data.wireless_verse_grip[0].state;
cursor_pos = data.inverse3[0].state.cursor_position;
// ... classic math (not shown): if (wvg.buttons.a || wvg.buttons.b)
// move in pointing dir; clamp to sphere ...
commands_message out_cmds{};
device_commands dc{ .device_id = inv3_device_id };
dc.commands.set_cursor_position = set_cursor_position_cmd{cursor_pos};
if (first_message) {
first_message = false;
out_cmds.session = session_cmd{ /* profile = combined */ };
dc.configure = device_configure{ .preset = preset_cfg{"arm_front_centered"} };
}
out_cmds.inverse3.push_back(std::move(dc));
std::string out_json;
(void)glz::write_json(out_cmds, out_json);
ws.send(out_json);
};
ws.open("ws://localhost:10001");
while (std::cin.get() != '\n') {} // block main thread
튜토리얼 06도 SDK와 함께 로컬에 설치되어 있습니다 — 다음을 참조하세요 tutorials/06-haply-inverse-combined/ 서비스 설치 디렉터리에서.
관련 항목: 제어 명령 (set_cursor_position) · 유형 (쿼터니언, vec3) · 몽타주 및 작업 공간 (사전 설정) · 튜토리얼 03 (무선 VG) · 튜토리얼 05 (위치 제어)