跳转至主要内容

06. Combiné(Inverse3 + 无线 VerseGrip)

双设备教程:将手柄指向某个方向并按住按钮,即可将光标Inverse3 沿该方向移动。光标移动范围限定在球形工作空间内。

您将学到:

  • 在同一状态帧中读取两种类型的设备(inverse3 et wireless_verse_grip)
  • 根据其声音确定手柄的指向方向 四元数 (axe local +Y)
  • 使用 set_cursor_position 将光标移动到计算出的目标位置
  • 将目标限制在安全的工作空间范围内——Minverse 使用的半径小于Inverse3
  • 定义一个 工作区预设 (arm_front_centered) 以便原点位于五线谱的中央

流程​

  1. 检测这两台设备:
    • 变体 C++ interrogent简体中文(大陆) GET /devices 启动时通过 HTTP 连接,随后显示校准提示,并等待用户按下回车键。
    • Python从 WebSocket 的第一个状态帧中读取了这两台设备的标识符。
  2. 保存 会话配置文件 并设置 configure.preset: arm_front_centered 在第一条消息中(仅此一次的联系)。
  3. 每个周期,请阅读orientation 把手及状态 buttons.{a, b}.
  4. 如果按下了移动按钮,请计算手柄在世界空间中的方向(R(q) · ĵ — 旋转后的+Y单位轴),将其乘以 SPEED 并将它添加到目标位置。
  5. 将目标限制在工作空间球体范围内,并通过 set_cursor_position.
  6. (仅限 Python)根据……调整球体的半径 config.type 设备 — minverse = 0.04 米,其余部分均为 0.10 米。

参数​

Nom默认值角色
SPEED0.01 摩托车按下按钮期间不移动
RADIUS_INVERSE30.10 mInverse3 /Inverse3x 工作空间的约束半径
RADIUS_MINVERSE0.04 mMinverse 的工作区约束半径(仅限 Python — C++ 已修复) 0.10 (en dur)
PRINT_EVERY_MS200遥测数据速率的限制
会话配置文件名称co.haply.inverse.tutorials:combined在Haply Hub中识别此模拟
执行前请进行校准
  • 让Inverse3 自动校准(或将笔杆放在墨水瓶上,等待LED指示灯变为常亮状态)。
  • 将墨水瓶的把手取下。
  • 按住 A 或 B 键不放,同时旋转手柄——光标将朝手柄指向的方向移动。

阅读过的州冠军​

基于每个周期的状态帧:

  • data.inverse3[0].state.cursor_position — vec3
  • data.wireless_verse_grip[0].state.orientation — quaternion
  • data.wireless_verse_grip[0].state.buttons.{a, b, c} — 布尔值
  • (Python,仅限第一帧) data.inverse3[0].config.type — 选择Inverse3 的半径,还是Minverse
  • (Python,仅限第一帧) data.inverse3[0].status.calibrated — 如果该值不正确,则提示用户进行校准

发送与接收​

基于四元数的航向计算(旋转) +Y par R(q)) 以及球面约束属于经典线性代数范畴——请参阅源文件。就 Inverse API 而言,这涉及初始接触以及 set_cursor_position 每个周期。

唯一的异步循环。Python 从第一个状态帧中读取两台设备的标识符;建立连接时,会附加配置文件并 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))
随SDK安装程序一起提供

教程 06 也随 SDK 一起安装在本地了——请参阅 tutorials/06-haply-inverse-combined/ 在服务安装目录中。

来源: Python·C++·C++ Glaze

另请参阅: 控制命令(set_cursor_position) · 类型 (四元数, vec3) · 剪辑与工作区(预设) · 教程 03(无线 VG) · 教程 05(位置控制)