├── MotorDriverDiagram.fzz ├── README.md └── haptic_server.py /MotorDriverDiagram.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PointlesslyUseful/VRVest/2516a506f4683602c5a5f74deef1c57589300b2f/MotorDriverDiagram.fzz -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VRVest 2 | This is a simple websocket server which listens for the messages VR games send to the bhpatics player 3 | and then sends them to my DIY VRVest. 4 | 5 | Check the video out here: 6 | https://youtu.be/LS-Bk7RuzB0 7 | -------------------------------------------------------------------------------- /haptic_server.py: -------------------------------------------------------------------------------- 1 | import asyncio 2 | import websockets 3 | from websocket import create_connection 4 | import json 5 | from time import sleep 6 | 7 | # For more information check out 8 | # https://github.com/bhaptics/tact-python 9 | 10 | 11 | # Create a websocket on the same port games use to connect 12 | # to the bhaptics player 13 | ws = create_connection("ws://192.168.1.53:80/ws") 14 | 15 | # Map bhaptics vest motor ids to my vests vr motors, 16 | # thier vest has 12 motors on each side when mine has 4. 17 | def map_front_motors(index): 18 | if index in [0,1,4,5]: 19 | return [1, 2] 20 | if index in [2,3,6,7]: 21 | return [4,3] 22 | if index in [8,9,12,13,16,17]: 23 | return [5,6] 24 | if index in [10,11,14,15,18,19]: 25 | return [7,8] 26 | 27 | async def server(websocket, path): 28 | while True: 29 | try: 30 | # Get received data from websocket 31 | data = await websocket.recv() 32 | 33 | 34 | data = json.loads(data.replace("'", "\"")) 35 | # Check the json sent has the correct attributes. 36 | if 'Submit' in data: 37 | if 'Frame' in data['Submit'][0]: 38 | # Grab the duration to turn the motors on for 39 | duration = data['Submit'][0]['Frame']['DurationMillis'] 40 | # each frame can have multiple motors so map each to our ids 41 | motors = [] 42 | for point in data['Submit'][0]['Frame']['DotPoints']: 43 | motors += map_front_motors(point['Index']) 44 | 45 | # Turn the relevant motors on 46 | for motor in set(motors): 47 | ws.send("on_" + str(motor)) 48 | # Sleep for the duration in milliseconds 49 | sleep(duration/1000) 50 | # Then turn all the motors off 51 | for motor in set(motors): 52 | ws.send("off_" + str(motor)) 53 | 54 | except Exception as e: 55 | print(e) 56 | 57 | 58 | # Create the websocket server 59 | start_server = websockets.serve(server, "localhost", 15881) 60 | 61 | # Start and run websocket server forever 62 | asyncio.get_event_loop().run_until_complete(start_server) 63 | asyncio.get_event_loop().run_forever() 64 | --------------------------------------------------------------------------------