Simulation Channel
Overview
Simulation Channel 是一个高频、双向的 WebSocket 通道,用于交换设备状态,并发送会话或设备命令。
默认 URL: ws://localhost:10001
端口可在配置中修改。
核心约定(重要):
- 客户端连接时,服务端会发送一条初始清单消息,其中包含完整的设备列表。
- 之后,对于客户端发送的每一条消息,服务端会恰好返回**一条****状态更新(State Update)**消息。
- 每条状态更新都包含所有设备的状态(及运行状态)。
本页介绍核心 Simulation Channel 协议及命令。
其他模块/功能可以注册并扩展系统,添加各自的命令和/或状态字段。这些内容单独记录在 modules 部分。
协议规则
每条客户端消息对应一次响应
对于客户端发送的每一条消息,服务端都会发出一条状态更新消息,其中包含所有设备的状态。
这意味着:
- 如果需要获取最新的设备状态快照,必须发送某些内容(会话命令、探测命令或设备命令)。
- 该通道的行为类似于由客户端消息驱动的"tick"循环。
不施加力的轮询(探测命令)
如果希望在不施加力或修改仿真参数的情况下观察状态变化,请使用探测命令:
inverse3使用probe_position- Verse 抓手使用
probe_orientation
探测命令不包含命令数据,仅强制执行设备信息查询,从而确保下一条状态更新中的位置/姿态数据是最新的。
已在发送控制命令(set_cursor_force、set_cursor_position 等)的仿真会话无需再发送探测命令,因为响应帧中始终包含设备状态。探测命令适用于仅监控的会话(例如 Haply Hub),这类会话需要在不驱动设备的情况下轮询设备状态。
配置与状态
- 初始清单消息包含设备的
config、state和status。 - 常规状态更新消息包含设备的
state和status。
如果需要再次获取包含配置的完整快照,请使用 session.force_render_full_state。
configure 与 commands
设备消息支持两个独立的映射:configure 和 commands。它们用途不同:
| 映射 | 用途 | 发送频率 |
|---|---|---|
configure | 一次性持久配置:预设、基准坐标系、安装方式、滤波器、模块设置 | 发送一次或在变更时发送 |
commands | 每个 tick 生效、非持久:力、位置、扭矩 | 必须在每个 tick 发送 |
commands 中的条目(set_cursor_force、set_cursor_position、set_angular_torques、set_angular_position)按每个 tick 应用一次,且不会保存 —— 如果停止发送,效果会立即消失,设备回到空闲状态。对于需要跨 tick 持续生效而无需重复发送的内容,请使用 configure。
set_transform 是特例set_transform 位于 commands 下,但它是持久的——服务端会保留你最后发送的变换,直到你发送新的变换。你并不需要每个 tick 都发送它。尽管如此,由于其用途是相机/场景导航,因此在持续运动导航中,以 tick 频率持续推送变换(例如用户平移场景时每帧发送一次变换)是预期的用法。
坐标系
Haply 默认使用右手坐标系,Z 轴朝上。
有两个配置条目会影响坐标的解释和返回方式:
session.configure.basis:改变 Haply 坐标与应用程序坐标系之间的映射关系(参见下方的 Basis)。inverse3[*].configure.preset:选择一个命名的出厂配置,用于设定工作空间原点的位置(例如arm_front_centered会将(0, 0, 0)置于工作空间中心)。参见各设备的 Configure 部分。
消息格式
本节介绍高层的消息封装与消息类型。完整示例见本文档后文。
设备分组
初始清单(服务端 → 客户端)
消息在顶层按设备类型分组(例如 inverse3、verse_grip、wireless_verse_grip)。每个设备类型键对应一个由单设备对象组成的数组。
在 WebSocket 连接建立后立即发送一次。
每个条目包含:
device_idconfigstatestatus
参见:示例:初始清单负载
状态更新(服务端 → 客户端)
每条客户端消息发送一次。
每个条目包含:
device_idstatestatus
参见:示例:状态更新负载
会话命令封装(客户端 → 服务端)
会话命令是作用于当前连接/会话的操作,不针对特定设备。
{
"session": {
"<command_name>": {
"...": "..."
}
}
}
设备命令信封(客户端 → 服务器)
设备命令以设备类型键的形式发送,其值为数组,因此可在一条消息中同时向一个或多个设备发送命令。每个设备条目均支持 configure 映射和 commands 映射。
{
"<device_type>": [
{
"device_id": "<id>",
"configure": {
"<config_key>": { "...": "..." }
},
"commands": {
"<command_name>": { "...": "..." }
}
}
]
}
您可以在单条消息中加入多个条目,以同时控制同一类型的多台设备。
请注意,commands 是一个字典,可以为某个设备包含多条命令,但每种命令类型只能有一条。
execute 字段
每个 command 或 configure 条目都接受一个可选的布尔值 "execute"(默认为 true)。设置 "execute": false 可使该条目仅被解析而不被应用。这在基于反射的序列化器(例如 Unity JsonUtility)中很有用,因为这类序列化器总会输出每一个字段。
"set_cursor_force": { "execute": false, "vector": { "x": 0.0, "y": 0.0, "z": 0.0 } }
命令参考
会话
强制渲染完整状态
请求获取所有设备状态和配置的快照。
{
"session": {
"force_render_full_state": {}
}
}
会话配置
会话级持久化配置通过 session.configure 发送。这与设备级 configure 映射的模式一致。
Profile
用于设置会话的 profile 名称,Haply Hub 借此识别仿真并保存每个应用的设备个性化设置。推荐格式:<app id>:<X.Y>[::<sub>],参见 Profile 名称格式。
{
"session": {
"configure": {
"profile": {
"name": "co.mycompany.myapp:1.4::main-scene"
}
}
}
}
基础(会话级)
一种快捷方式,在消息到达时将相同的基础写入会话中所有设备,包括 Inverse3 和 Verse Grips。基础本身是设备级设置:置换格式请参见基础(设备级)。
{
"session": {
"configure": {
"basis": { "permutation": "X-YZ" }
}
}
}
session.configure.basis 不会保存在会话中。在您连接之后才加入的设备(连接之后开启或唤醒的 Verse Grip、会话进行中插入的设备)不会获得该设置,而是以恒等基 XYZ 启动:请在该设备出现时,通过 device-connected 事件,为其单独发送 configure.basis。此快捷方式还会覆盖之前为每个设备发送的基设置。
所有设备命令
探测(所有设备)
使用探测命令可以请求最新的位置/姿态信息,而不会施加力或其他仿真更改。
- inverse3:
probe_position - Verse 握持器(
verse_grip、wireless_verse_grip):probe_orientation
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"probe_position": {}
}
}
],
"verse_grip": [
{
"device_id": "049D",
"commands": {
"probe_orientation": {}
}
}
],
"wireless_verse_grip": [
{
"device_id": "049D",
"commands": {
"probe_orientation": {}
}
}
]
}
设置变换(所有设备)
为设备设置工作空间变换(从设备空间到应用空间)。
与其他 commands 条目不同,set_transform 是持久性的——服务端会一直保留你最后发送的值,直到你发送新的值。你不需要每个周期都发送它,但由于其用途是相机/场景导航,在连续运动时(例如用户平移场景时每帧发送一次变换)按周期速率持续发送是预期的使用方式。
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_transform": {
"transform": {
"position": { "x": 0.0, "y": 0.0, "z": 0.0 },
"rotation": { "x": 0.0, "y": 0.0, "z": 0.0, "w": 1.0 },
"scale": { "x": 1.0, "y": 1.0, "z": 1.0 }
}
}
}
}
]
}
对于 Verse grip 和无线 Verse grip 设备,变换中只有 rotation 分量生效——该握把只上报姿态,因此 position 和 scale 没有可供缩放或平移的内容。position 和 scale 字段虽然被接受(并会在快照中回传),但纯粹是为了与 Inverse3 保持结构一致;将它们保持为单位值(position = {0,0,0}、scale = {1,1,1})是标准做法。
Inverse3 设备配置
配置项通过 configure 映射发送。这些配置是持久生效的——发送一次即可,或在需要变更时再发送。
Preset
{
"inverse3": [
{
"device_id": "049D",
"configure": {
"preset": { "preset": "arm_front_centered" }
}
}
]
}
可用值:device_defaults、arm_front、arm_front_centered、led_front、led_front_centered、custom。
预设只在设备当前所处的位置应用一次。之后转动设备时,工作空间会随之转动,并且自居中预设应用以来,设备转动 1° 或以上时,config.preset 会变为 custom。若要重新居中,请再次发送预设。参见 预设仅应用一次。
基准(设备级)
设置此设备的基准,即 Haply 坐标如何映射到应用程序的坐标系。设置后,设备的状态将以该基准返回,您发送给设备的数值也将按该基准进行解释。请将其发送给您使用的每一台设备(包括 Verse Grips),以及在设备出现时加入的设备(device-connected)。若要同时为当前存在的所有设备写入相同的基准,请使用会话级快捷方式。
排列字符串是相对于 Haply 的右手系 / Z 轴向上坐标系表示的,由 X、Y、Z 的一个排列组成,前面可选加上 + 或 -。示例:
XYZ、ZYX、+Y-Z+X、X-ZYYZX表示您的X对应 Haply 的Y(前方),您的Y对应 Haply 的Z(上方),您的Z对应 Haply 的X(右方)。X-YZ:左手系 Z 轴向上(Unreal)。
{
"inverse3": [
{
"device_id": "049D",
"configure": {
"basis": { "permutation": "ZXY" }
}
}
]
}
session.set_basis 迁移旧版 session.set_basis 对置换字符串的解读是反向的:新字符串是旧字符串的逆(X-ZY 变为 XZ-Y,ZXY 变为 YZX)。请参阅
转换表。
Mount
设置设备安装变换。注意 mount 内部的 transform 包装层。
{
"inverse3": [
{
"device_id": "049D",
"configure": {
"mount": {
"transform": {
"position": { "x": 0.0, "y": 0.0, "z": 0.0 },
"rotation": { "x": 0.0, "y": 0.0, "z": 0.0, "w": 1.0 },
"scale": { "x": 1.0, "y": 1.0, "z": 1.0 }
}
}
}
}
]
}
命令端(客户端到服务端)会将变换包裹一层:"mount": { "transform": { ... } }。
快照端(服务端到客户端)则是扁平结构:"mount": { "position": {...}, "rotation": {...}, "scale": {...} }。
这是有意为之:命令使用统一的包裹结构,而快照直接序列化变换。注意不要把快照的结构复制到命令负载中。
阻尼
用于控制均匀阻尼和/或方向性阻尼。至少需要包含一个字段。
{
"inverse3": [
{
"device_id": "049D",
"configure": {
"damping": { "scalar": 0.5 }
}
}
]
}
您还可以设置方向性阻尼,或同时设置两者:
"damping": { "scalar": 0.5, "vector": { "x": 0.0, "y": 1.0, "z": 0.0 } }
力门控
设置力门控衰减增益(0.0 至 1.0)。
{
"inverse3": [
{
"device_id": "049D",
"configure": {
"force_gate": { "gain": 0.3 }
}
}
]
}
Inverse3 命令
要向 inverse3 设备发送命令,请在 inverse3 键下添加一个 device_id 与之匹配的条目。命令是按 tick 生效的,必须在每个 tick 重新发送才能保持有效。
为单个设备发送命令:
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_cursor_force": {
"vector": {
"x": 1.0,
"y": 2.0,
"z": 3.0
}
}
}
}
]
}
多设备批量发送指令:
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_cursor_force": {
"vector": {
"x": 1.0,
"y": 2.0,
"z": 3.0
}
}
}
},
{
"device_id": "049E",
"commands": {
"set_cursor_force": {
"vector": {
"x": 1.0,
"y": 2.0,
"z": 3.0
}
}
}
}
]
}
设置光标位置
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_cursor_position": {
"position": {
"x": 1.0,
"y": 2.0,
"z": 3.0
}
}
}
}
]
}
设置光标力
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_cursor_force": {
"vector": {
"x": 1.0,
"y": 2.0,
"z": 3.0
}
}
}
}
]
}
设置角度位置
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_angular_position": {
"angles": {
"a0": 1.0,
"a1": 2.0,
"a2": 3.0
}
}
}
}
]
}
设置角扭矩
{
"inverse3": [
{
"device_id": "049D",
"commands": {
"set_angular_torques": {
"torques": {
"a0": 1.0,
"a1": 2.0,
"a2": 3.0
}
}
}
}
]
}
Verse Grip 配置
Verse Grip 和无线 Verse Grip 设备支持与 Inverse3 相同的 configure 键,即 preset、basis 和 mount。
扩展 Verse Grip
set_extension_data 命令是 Verse Grip 扩展协议的一部分,用于实现了板级扩展通信协议的 grip 版本。
设置 Grip 扩展数据
支持的数据长度:
- 上行(客户端 → 设备)最多 20 字节。
- 下行(设备 → 客户端)最多 12 字节,通过 State Update 消息中的
state.extension_data返回。
数据规范:
- 数组长度:20 字节
- 取值范围:每个值为 0–255
{
"wireless_verse_grip": [
{
"device_id": "049D",
"commands": {
"set_extension_data": {
"extension_data": [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
]
}
}
}
]
}
示例
示例:初始库存负载
当 WebSocket 连接时,服务会发送一条包含完整设备列表的消息。初始消息的格式如下 JSON:
{
"inverse3": [
{
"device_id": "04BA",
"config": {
"type": "inverse3",
"port": "COM13",
"device_info": {
"major_version": 7,
"minor_version": 1,
"id": "04BA",
"device_type": 4,
"uuid": "2D35F80DD9005F599B68F49944CB04BA"
},
"extended_device_id": "2D35F80DD9005F599B68F49944CB04BA",
"extended_firmware_version": "8C20FDC8010AA1E15AA133CDA2534874",
"gravity_compensation": {
"enabled": true,
"scaling_factor": 1
},
"handedness": "right",
"streaming_mode": "USB",
"torque_scaling": {
"enabled": true
},
"home_return": {
"enabled": false
},
"filters": {
"force_gate": { "gain": 0.3 },
"damping": { "scalar": 0 }
},
"preset": "defaults",
"basis": { "permutation": "XYZ" },
"mount": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
}
},
"state": {
"cursor_position": {
"x": 0.07842738,
"y": -0.14836666,
"z": 0.14297646
},
"cursor_velocity": {
"x": -0.011969013,
"y": 0.0012009288,
"z": -0.043197
},
"angular_position": {
"x": -69.31704,
"y": 137.62952,
"z": 19.832787
},
"angular_velocity": {
"x": 0,
"y": 0,
"z": 0
},
"body_orientation": {
"x": -0.01940918,
"y": 0.7026367,
"z": 0.00048828125,
"w": 0.7113037
},
"current_cursor_force": { "x": 0, "y": 0, "z": 0 },
"current_cursor_position": { "x": 0, "y": 0, "z": 0 },
"current_angular_torques": { "x": 0, "y": 0, "z": 0 },
"current_angular_position": { "x": 0, "y": 0, "z": 0 },
"control_domain": "cartesian",
"control_mode": "force",
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"calibrated": false,
"in_use": false,
"power_supply": true,
"ready": true,
"started": true
}
}
],
"verse_grip": [
{
"device_id": "61548",
"config": {
"type": "verse_grip",
"port": "COM3",
"preset": "device_defaults",
"basis": { "permutation": "XYZ" },
"mount": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
}
},
"state": {
"button": false,
"hall": 0,
"orientation": {
"x": -0.5019531,
"y": 0.8632202,
"z": -0.048095703,
"w": -0.022338867
},
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"error": 0,
"ready": true
}
}
],
"wireless_verse_grip": [
{
"device_id": "0",
"config": {
"type": "wireless_verse_grip",
"port": "COM6",
"major_version": 1,
"minor_version": 4,
"hardware_version": 1,
"streaming_mode": "Radio",
"preset": "device_defaults",
"basis": { "permutation": "XYZ" },
"mount": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
}
},
"state": {
"battery_level": 0.816,
"battery_voltage": 3.77,
"buttons": {
"a": false,
"b": false,
"c": false
},
"hall": 16,
"orientation": {
"x": -0.019866943,
"y": -0.017486572,
"z": 0.05508423,
"w": -0.9963989
},
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"connected": true,
"awake": true,
"ready": true
}
}
]
}
示例:状态更新负载
服务会针对每条收到的消息发送一条状态更新消息,其中包含所有设备的状态。
如果您想获取设备的状态,必须先向其发送一条消息(例如探测命令或力值,即使数值为零)。当将设备用作输入源(例如跟踪位置)而不施加力时,这一点尤为重要。
状态更新消息采用以下 JSON 格式:
{
"inverse3": [
{
"device_id": "04BA",
"state": {
"cursor_position": {
"x": 0.07842738,
"y": -0.14836666,
"z": 0.14297646
},
"cursor_velocity": {
"x": -0.011969013,
"y": 0.0012009288,
"z": -0.043197
},
"angular_position": {
"x": -69.31704,
"y": 137.62952,
"z": 19.832787
},
"angular_velocity": {
"x": 0,
"y": 0,
"z": 0
},
"body_orientation": {
"x": -0.01940918,
"y": 0.7026367,
"z": 0.00048828125,
"w": 0.7113037
},
"current_cursor_force": { "x": 0, "y": 0, "z": 0 },
"current_cursor_position": { "x": 0, "y": 0, "z": 0 },
"current_angular_torques": { "x": 0, "y": 0, "z": 0 },
"current_angular_position": { "x": 0, "y": 0, "z": 0 },
"control_domain": "cartesian",
"control_mode": "force",
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"calibrated": false,
"in_use": false,
"power_supply": true,
"ready": true,
"started": true
}
}
],
"verse_grip": [
{
"device_id": "61548",
"state": {
"button": false,
"hall": 0,
"orientation": {
"x": -0.5019531,
"y": 0.8632202,
"z": -0.048095703,
"w": -0.022338867
},
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"error": 0,
"ready": true
}
}
],
"wireless_verse_grip": [
{
"device_id": "0",
"state": {
"battery_level": 0.816,
"battery_voltage": 3.77,
"buttons": {
"a": false,
"b": false,
"c": false
},
"hall": 16,
"orientation": {
"x": -0.019866943,
"y": -0.017486572,
"z": 0.05508423,
"w": -0.9963989
},
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"connected": true,
"awake": true,
"ready": true
}
}
],
"custom_verse_grip": [
{
"device_id": "0",
"state": {
"battery_level": 0.816,
"battery_voltage": 3.77,
"buttons": {
"a": false,
"b": false,
"c": false
},
"hall": 16,
"orientation": {
"x": -0.019866943,
"y": -0.017486572,
"z": 0.05508423,
"w": -0.9963989
},
"extension_data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"transform": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 1, "y": 1, "z": 1 }
},
"transform_velocity": {
"position": { "x": 0, "y": 0, "z": 0 },
"rotation": { "x": 0, "y": 0, "z": 0, "w": 1 },
"scale": { "x": 0, "y": 0, "z": 0 }
}
},
"status": {
"ready": true
}
}
]
}