1'''
2AHRS - AHRS_getAngularVelocity.py with asynchronous mode.
3
4This example demonstrates the process of getting AHRS three axis angular velocity data from WifiDAQE3AH.
5
6To begin with, it demonstrates the steps to open the AHRS and configure the AHRS parameters.
7Next, it outlines the procedure for the AHRS angular velocity data.
8Finally, it concludes by explaining how to close the AHRS.
9
10-------------------------------------------------------------------------------------
11Please change correct serial number or IP and port number BEFORE you run example code.
12
13For other examples please check:
14 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
15See README.md file to get detailed usage of this example.
16
17Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
18'''
19
20## Python
21import asyncio
22
23## WPC
24
25from wpcsys import pywpc
26
27
28async def main():
29 ## Get Python driver version
30 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
31
32 ## Create device handle
33 dev = pywpc.WifiDAQE3AH()
34
35 ## Connect to device
36 try:
37 dev.connect("192.168.5.38") ## Depend on your device
38 except Exception as err:
39 pywpc.printGenericError(err)
40 ## Release device handle
41 dev.close()
42 return
43
44 try:
45 ## Parameters setting
46 port = 0 ## Depend on your device
47
48 ## Get firmware model & version
49 driver_info = await dev.Sys_getDriverInfo_async()
50 print("Model name: " + driver_info[0])
51 print("Firmware version: " + driver_info[-1])
52
53 ## Open AHRS and update rate is 333 HZ
54 err = await dev.AHRS_open_async(port)
55 print(f"AHRS_open_async in port {port}, status: {err}")
56
57 ## Start AHRS
58 err = await dev.AHRS_start_async(port)
59 print(f"AHRS_start_async in port {port}, status: {err}")
60
61 ## Get three axis angular velocity
62 while True:
63 ahrs_list = await dev.AHRS_getAngularVelocity_async(port)
64 print(ahrs_list)
65 except KeyboardInterrupt:
66 print("Press keyboard")
67
68 except Exception as err:
69 pywpc.printGenericError(err)
70
71 finally:
72 ## Stop AHRS
73 err = await dev.AHRS_stop_async(port)
74 print(f"AHRS_stop_async in port {port}, status: {err}")
75
76 ## Close AHRS
77 err = await dev.AHRS_close_async(port)
78 print(f"AHRS_close_async in port {port}, status: {err}")
79
80 ## Disconnect device
81 dev.disconnect()
82
83 ## Release device handle
84 dev.close()
85 return
86def main_for_spyder(*args):
87 if asyncio.get_event_loop().is_running():
88 return asyncio.create_task(main(*args)).result()
89 else:
90 return asyncio.run(main(*args))
91if __name__ == '__main__':
92 asyncio.run(main()) ## Use terminal
93 # await main() ## Use Jupyter or IPython(>=7.0)
94 # main_for_spyder() ## Use Spyder