Haply Inverse SDK
Haply 서비스 SDK는 백그라운드에서 실행되며 Haply 장치와 컴퓨터 간의 통신 역할을 하는 서비스입니다. 언어에 구애받지 않는 SDK는 Haply 하드웨어에 웹소켓 인터페이스를 제공합니다. Inverse3, Inverse3X, Minverse 및 버세그립을 포함합니다.
기능은 다음과 같습니다:
- 장치 검색 및 관리: HTTP REST API를 통해 연결된 Haply 장치를 자동으로 나열하고 구성합니다.
- 실시간 상태 스트리밍: 정밀한 제어 및 웹 소켓 통신을 위해 장치 상태에 대한 업데이트를 높은 주파수로 제공합니다.
- 명령 처리: 힘이나 위치에 대한 명령을 높은 충실도로 실행하여 햅틱 피드백을 향상시킵니다.
- 백그라운드 작동: 백그라운드에서 실행되어 사용자 개입 없이 디바이스 준비 상태를 유지합니다.
설치
haply.co에서 최신 인버스 인스톨러를 다운로드하여 실행하고 설치 지침을 따릅니다.
설치가 완료되면 역방향 서비스가 백그라운드에서 자동으로 실행됩니다.
팁
Haply 장치 관리자를 사용하여 서비스를 쉽게 관리하고 연결된 장치를 확인할 수 있습니다.
사용 예
다음 Python 코드 스니펫은 웹소켓 인터페이스를 통해 역방향 서비스와 상호 작용하여 데이터를 읽는 방법을 보여줍니다. Inverse3 및 무선 버즈 그립 장치에서 데이터를 읽는 방법을 보여줍니다.
이 코드는 장치의 위치, 속도, 버튼 및 방향을 읽고 영력 명령을 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
폴더로 이동합니다.