跳转至主要内容

04. 哈洛·博登

其首个触觉效果:一个虚拟的水平地面,当光标进入其中时,地面会产生反作用力。该力由一个简单的惩罚弹簧模型(stiffness × penetration_depth),沿Z轴方向通过 set_cursor_force 被应用。

您将学到:

  • 使用 set_cursor_force,以应用惩罚弹簧力
  • 从……中读取 cursor_position 以及实时计算力
  • (Python) 设置一个 工作区预设 (arm_front_centered),从而使原点位于工作区域的中心
  • (Python) 通过该包使用键盘对底盘高度和刚度进行交互式微调 keyboard

流程​

  1. 建立与的 WebSocket 连接 ws://localhost:10001 然后等待第一个状态帧。
  2. 在第一个帧中注册 会话概况. Python 版本还会额外发送 configure.preset: arm_front_centered,从而使原点位于工作区域的中心;C++ 版本则使用设备上已启用的配置。
  3. 在每个帧中,您会看到 cursor_position.z aus, 计算 force_z = max(0, (floor_pos - z) * stiffness) 并将结果作为命令发送 set_cursor_force 返回。
  4. 在接下来的几个时钟周期中,仅发送力量指令——会话配置文件仅进行一次握手。
  5. (Python) 此外,在每个时钟周期都会检测键盘上的方向键,并且 floor_pos / stiffness 将实时更新。

参数​

名称标准Zweck
floor_pos0.10 m虚拟地面平面的Z坐标
stiffness1000 不适用弹簧常数(1 毫米压入深度 → 1 牛顿)
PRINT_EVERY_MS100–200遥测数据限流
会话配置文件名称co.haply.inverse.tutorials:hello-floor在Haply Hub中标记此模拟
交互式(仅限 Python)

Python 版本使用该包 keyboard (在 Linux 系统上需要提升权限):

  • ↑ / ↓ — 升降底板
  • ← / → — 降低/提高刚度
  • R — 恢复为默认值
力量的扩展

在“服务 tick”中,力是可累加的——它们会从所有来源汇总后,再发送至设备。像这样的教程可以与其他力源并存,且彼此不会相互干扰。

已读取的状态字段​

Aus data.inverse3[i].state:

  • cursor_position.z — vec3, 用于计算穿透深度
  • current_cursor_force — 将作为遥测数据上报

发送 / 接收​

每次时钟脉冲:读取光标的Z值, force_z = max(0, (floor_pos - z) * stiffness) 计算并执行一条命令 set_cursor_force 发送。第一条发出的消息还包含会话配置文件(所有变体),而在 Python 中还额外包含 configure.preset: arm_front_centered.

一个异步循环。第一个帧中的握手过程包含配置文件和 configure.preset,因此 floor_pos = 0.1 与工作区中心的坐标一致。

async with websockets.connect(URI) as websocket:
while True:
msg = await websocket.recv()
data = json.loads(msg)

if first_message:
first_message = False
device_id = data["inverse3"][0]["device_id"]
# Handshake: profile + preset (one-shot)
request_msg = {
"session": {"configure": {"profile": {"name": "co.haply.inverse.tutorials:hello-floor"}}},
"inverse3": [{
"device_id": device_id,
"configure": {"preset": {"preset": "arm_front_centered"}}
}]
}
else:
# Per tick: compute force along Z, send set_cursor_force
z = data["inverse3"][0]["state"]["cursor_position"]["z"]
force_z = 0.0 if z > floor_pos else (floor_pos - z) * stiffness
request_msg = {
"inverse3": [{
"device_id": device_id,
"commands": {"set_cursor_force":
{"vector": {"x": 0.0, "y": 0.0, "z": force_z}}}
}]
}

await websocket.send(json.dumps(request_msg))
随 SDK 安装程序一并提供

此外,教程 04 会随 SDK 一起本地安装——可在以下位置找到: tutorials/04-haply-inverse-hello-floor/ 位于该服务的安装目录中。

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

相关主题: 控制命令 (set_cursor_force) · 剪辑与工作区(预设) · 类型 (vec3) · 会议 · 教程 07(基础与蒙太奇)