1'''
2AHRS - AHRS_getEstimation.py with asynchronous mode.
3
4This example demonstrates the process of getting AHRS data by mode 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 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-2025 WPC Systems Ltd. All rights reserved.
18'''
19
20## WPC
21from wpcsys import pywpc
22
23## Python
24import asyncio
25import sys
26sys.path.insert(0, 'src/')
27
28
29async def main():
30 ## Get Python driver version
31 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
32
33 ## Create device handle
34 dev = pywpc.WifiDAQE3AH()
35
36 ## Connect to device
37 try:
38 dev.connect("192.168.5.38") ## Depend on your device
39 except Exception as err:
40 pywpc.printGenericError(err)
41 ## Release device handle
42 dev.close()
43 return
44
45 try:
46 ## Parameters setting
47 port = 0 ## Depend on your device
48 mode = 6 ## 3-axis of orientation and angular velocity and acceleration
49
50 ## Get firmware model & version
51 driver_info = await dev.Sys_getDriverInfo_async()
52 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
53
54 ## Open AHRS and update rate is 333 HZ
55 err = await dev.AHRS_open_async(port)
56 print(f"AHRS_open_async in port {port}, status: {err}")
57
58 ## Start AHRS
59 err = await dev.AHRS_start_async(port)
60 print(f"AHRS_start_async in port {port}, status: {err}")
61
62 ## Get three axis data by mode
63 while True:
64 ahrs_list = await dev.AHRS_getEstimate_async(port, mode)
65 print(ahrs_list)
66 except KeyboardInterrupt:
67 print("Press keyboard")
68
69 except Exception as err:
70 pywpc.printGenericError(err)
71
72 finally:
73 ## Stop AHRS
74 err = await dev.AHRS_stop_async(port)
75 print(f"AHRS_stop_async in port {port}, status: {err}")
76
77 ## Close AHRS
78 err = await dev.AHRS_close_async(port)
79 print(f"AHRS_close_async in port {port}, status: {err}")
80
81 ## Disconnect device
82 dev.disconnect()
83
84 ## Release device handle
85 dev.close()
86
87
88def main_for_spyder(*args):
89 if asyncio.get_event_loop().is_running():
90 return asyncio.create_task(main(*args)).result()
91 else:
92 return asyncio.run(main(*args))
93
94
95if __name__ == '__main__':
96 asyncio.run(main()) ## Use terminal
97 # await main() ## Use Jupyter or IPython(>=7.0)
98 # main_for_spyder() ## Use Spyder