Haply Inverse SDK
Haply Service SDKは、バックグラウンドで実行され、Haply デバイスとコンピュータ間の通信として機能するサービスです。 言語にとらわれないSDKは、Haply ハードウェアへのウェブソケット・インターフェースを提供します。 Inverse3Inverse3Xを含むHaplyハードウェアへのウェブソケットインターフェースを提供します、 MinverseおよびVersegripを含みます。
その機能には以下のようなものがある:
- デバイスの発見と管理:接続されたHaply デバイスをHTTP RESTapiで自動的にリストアップし、設定します。
- リアルタイム・ステート・ストリーミング:正確な制御とWebSocket通信のために、デバイスの状態を高頻度で更新します。
- コマンド処理:力や位置のコマンドを忠実に実行し、触覚フィードバックを強化する。
- バックグラウンド動作:バックグラウンドで実行され、ユーザーの介入なしにデバイスの準備状態を維持します。
インストール
最新のInverse Installerをdevelop.haply.coからダウンロードして実行し、インストール手順に従ってください。
インストールが完了すると、インバース・サービスは自動的にバックグラウンドで実行されます。
Haply Device Managerを使用して、サービスを簡単に管理し、接続されたデバイスを確認できます。
使用例
次のPythonコード・スニペットは、WebSocketインターフェイスを介してInverse Serviceと対話し、データを Inverse3とWireless Verse Gripデバイスからデータを読み取る方法を示します。
このコードは、デバイスの位置、速度、ボタン、向きを読み取り、ゼロフォースコマンドを Inverse3デバイスにゼロフォースコマンドを送信する。
import asyncio # To run async loops
import websockets # Required for device communication
import orjson # JSON reader for fast processing
# Main asynchronous loop
async def main():
uri = 'ws://localhost:10001' # WebSocket port for Inverse Service 3.1 json format
first_message = True
inverse3_device_id = None
force = {"x": 0, "y": 0, "z": 0} # Forces to send to the Inverse3 device.
# Haptic loop
async with websockets.connect(uri) as ws:
while True:
# Receive data from the device
response = await ws.recv()
data = orjson.loads(response)
# Get devices list from the data
inverse3_devices = data.get("inverse3", [])
verse_grip_devices = data.get("wireless_verse_grip", [])
# Get the first device from the list
inverse3_data = inverse3_devices[0] if inverse3_devices else {}
verse_grip_data = verse_grip_devices[0] if verse_grip_devices else {}
# Handle the first message to get device IDs and extra information
if first_message:
first_message = False
if not inverse3_data:
print("No Inverse3 device found.")
break
if not verse_grip_data:
print("No Wireless Verse Grip device found.")
# Store device ID for sending forces
inverse3_device_id = inverse3_data.get("device_id")
# Get handedness from Inverse3 device config data (only available in the first message)
handedness = inverse3_devices[0].get("config", {}).get("handedness")
print(f"Inverse3 device ID: {inverse3_device_id}, Handedness: {handedness}")
if verse_grip_data:
print(f"Wireless Verse Grip device ID: {verse_grip_data.get("device_id")}")
# Extract position, velocity from Inverse3 device state
position = inverse3_data["state"].get("cursor_position", {})
velocity = inverse3_data["state"].get("cursor_velocity", {})
# Extract buttons and orientation from Wireless Verse Grip device state (or default if not found)
buttons = verse_grip_data.get("state", {}).get("buttons", {})
orientation = verse_grip_data.get("state", {}).get("orientation", {})
print(f"Position: {position} Velocity: {velocity} Orientation: {orientation} Buttons: {buttons}")
# Prepare the force command message to send
# Must send forces to receive state updates (even if forces are 0)
request_msg = {
"inverse3": [
{
"device_id": inverse3_device_id,
"commands": {
"set_cursor_force": {
"values": force
}
}
}
]
}
# Send the force command message to the server
await ws.send(orjson.dumps(request_msg))
# Run the asynchronous main function
if __name__ == "__main__":
asyncio.run(main())
に力を加えるために力の値を変更する。 Inverse3デバイスに力を加える際は、注意してください。急激に大きな力を加えると、デバイスが破損したり、予期せぬ動作を引き起こす可能性があります。
インバース・サービス・ウェブソケットのjsonフォーマットの詳細については、こちらをご覧ください。
その他の例
ベーシック C++の例 はインストール・ディレクトリ(%programfiles%\Haply\Inverse
).
ソースは
tutorial
フォルダにあり、コンパイルされたサンプルはbin
フォルダー