06. 조합형 (Inverse3 + Wireless VerseGrip)
두 대의 기기를 사용하는 튜토리얼: 조종기를 정렬한 후 버튼을 길게 눌러 ‘ Inverse3 ’의 커서를 해당 방향으로 이동시키세요. 커서는 구형의 작업 공간 내에서만 움직일 수 있습니다.
학습 내용:
- 동일한 상태 프레임에서 두 가지 장치 유형 읽기 (
inverse3그리고wireless_verse_grip) - 손잡이의 방향에 따라 그 방향을 파악하기 쿼터니언 (지역
+Y-축) - 사용 방법
set_cursor_position, 커서를 계산된 목표 지점으로 이동하기 위해 - 작업 지점을 안전한 작업 공간 구로 제한 – Minverse 은 다음보다 더 작은 반경을 사용합니다. Inverse3
- ~ 설정하기 작업 공간 사전 설정 (
arm_front_centered), 범위의 중앙에 기점이 오도록
진행 절차
- 두 기기 모두 다음을 인식합니다:
- C++-시작 시 HTTP를 통해 변형을 조회합니다
GET /devicesab, 그런 다음 보정 요청을 표시하고 ENTER 키를 누를 때까지 대기합니다. - 파이썬은 WebSocket의 첫 번째 상태 프레임에서 두 장치 ID를 모두 읽어옵니다.
- C++-시작 시 HTTP를 통해 변형을 조회합니다
- 다음에 등록하세요 회의 개요 그리고 첫 번째 메시지에 다음 내용을 입력하세요
configure.preset: arm_front_centered(일회성 악수). - 매월 생리 주기마다: 다음 내용을 읽어보세요.
orientation손잡이와 다음의 상태buttons.{a, b}. - 이동 키를 누르고 있는 경우, 월드 좌표계에서 그립의 방향을 계산하십시오 (
R(q) · ĵ– 회전된 기준축 (+Y)를 구한 다음, 이를 다음 값으로 스케일링하여 더하십시오.SPEED, 목표 위치로. - 작업 공간 구 내의 목표 지점을 지정하고 다음을 통해 전송하십시오.
set_cursor_position. - (Python 전용) 다음을 기준으로 구의 반지름을 조정하십시오.
config.type기기의 –minverse= 0.04 m, 그 외 모두 = 0.10 m.
매개변수
| 이름 | 표준값 | Zweck |
|---|---|---|
SPEED | 0.01 m/tick | 키를 누르고 있는 동안의 단계 크기 |
RADIUS_INVERSE3 | 0.10 m | Inverse3 /Inverse3x의 작업 영역 경계 반경 |
RADIUS_MINVERSE | 0.04 m | Minverse 의 작업 공간 경계 반경 (Python 전용 – C++은 고정되어 있음) 0.10 (인코딩됨) |
PRINT_EVERY_MS | 200 | 텔레메트리 제한 |
| 세션 프로필 이름 | co.haply.inverse.tutorials:combined | Haply 허브에서 이 시뮬레이션을 표시합니다. |
- 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— 값이 false일 경우 사용자에게 다음을 요청합니다
보내기 / 받기
쿼터니언을 이용한 방향 계산 (회전) +Y MIT R(q)) 및 구에 대한 제한은 고전적인 선형 대수학의 내용입니다 – 소스 파일을 참조하십시오. 역 API 페이지는 핸드셰이크와 주기당 전송되는 set_cursor_position.
- 파이썬
- C++ (nlohmann)
- C++ (Glaze)
단 하나의 비동기 루프입니다. 파이썬은 첫 번째 상태 프레임에서 두 장치 ID를 모두 읽어오며, 핸드셰이크는 프로필과 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++는 시작 시 다음을 통해 두 장치 ID를 모두 확인합니다. GET /devices (HTTP)를 열고, 그 다음 WebSocket을 엽니다. onmessage libhv의 I/O 스레드에서 실행되며, ENTER 키를 누를 때까지 메인 스레드는 차단됩니다.
// 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와 동일한 콜백 모델입니다. 타입이 지정된 구조체(Struct)는 상태 프레임과 발신 명령을 모두 표현합니다 – 두 가지 std::vector<> 에서 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 (위치 제어)