2023-11-29 22:56:01 +08:00
|
|
|
|
# Triad OpenVR Python封装库
|
2023-11-29 13:21:56 +08:00
|
|
|
|
|
2023-11-29 22:56:01 +08:00
|
|
|
|
这是一个增强的OpenVR的封装库,对比现有的一些较为完善的库如 [cmbruns](https://github.com/cmbruns)开发的 [pyopenvr library](https://github.com/cmbruns/pyopenvr)。Triad OpenVR Python 封装库是为了更加简便的方式去使用python处理SteamVR跟踪系统的数据。
|
2023-11-29 13:21:56 +08:00
|
|
|
|
|
2023-11-29 22:56:01 +08:00
|
|
|
|
## 一、使用样例
|
|
|
|
|
|
|
|
|
|
通过python获取SteamVR的手柄的位置,并绘制在Figure上,示例代码如下:
|
2023-11-29 13:21:56 +08:00
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
import triad_openvr as vr
|
|
|
|
|
import pylab as plt
|
|
|
|
|
v = vr.triad_openvr()
|
|
|
|
|
data = v.devices["controller_1"].sample(1000,250)
|
|
|
|
|
plt.plot(data.time,data.x)
|
|
|
|
|
plt.title('Controller X Coordinate')
|
|
|
|
|
plt.xlabel('Time (seconds)')
|
|
|
|
|
plt.ylabel('X Coordinate (meters)')
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![Example plot of captured data](images/simple_xcoord_plot.png "Example Plot")
|
|
|
|
|
|
2023-11-29 22:56:01 +08:00
|
|
|
|
## 二、配置文件
|
2023-11-29 13:21:56 +08:00
|
|
|
|
|
2023-11-29 22:56:01 +08:00
|
|
|
|
config.json的作用是通过序列号识别设备,以便为同一物理设备保持相同的名称。为了使其正常工作,只需在'config.json'文件中更改序列号和名称。以下是一个配置文件的示例:
|
2023-11-29 13:21:56 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
{
|
|
|
|
|
"devices":[
|
|
|
|
|
{
|
|
|
|
|
"name": "hmd",
|
|
|
|
|
"type": "HMD",
|
|
|
|
|
"serial":"XXX-XXXXXXXX"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "tracking_reference_1",
|
|
|
|
|
"type": "Tracking Reference",
|
|
|
|
|
"serial":"LHB-XXXXXXXX"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "controller_1",
|
|
|
|
|
"type": "Controller",
|
|
|
|
|
"serial":"XXX-XXXXXXXX"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"name": "tracker_1",
|
|
|
|
|
"type": "Tracker",
|
|
|
|
|
"serial":"LHR-XXXXXXXX"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|