1'''
2AHRS - AHRS_getOrientation.py with synchronous mode.
3
4This example demonstrates the process of getting AHRS three axis orientation 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 orientation 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 time
22
23## WPC
24
25from wpcsys import pywpc
26
27
28def 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 timeout = 3 ## second
48
49 ## Get firmware model & version
50 driver_info = dev.Sys_getDriverInfo(timeout)
51 print("Model name: " + driver_info[0])
52 print("Firmware version: " + driver_info[-1])
53
54 ## Open AHRS and update rate is 333 HZ
55 err = dev.AHRS_open(port, timeout)
56 print(f"AHRS_open in port {port}, status: {err}")
57
58 ## Start AHRS
59 err = dev.AHRS_start(port, timeout)
60 print(f"AHRS_start in port {port}, status: {err}")
61
62 ## Get three axis orientation
63 while True:
64 data = dev.AHRS_getOrientation(port, timeout)
65 print(data)
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 = dev.AHRS_stop(port, timeout)
75 print(f"AHRS_stop in port {port}, status: {err}")
76
77 ## Close AHRS
78 err = dev.AHRS_close(port, timeout)
79 print(f"AHRS_close in port {port}, status: {err}")
80
81 ## Disconnect device
82 dev.disconnect()
83
84 ## Release device handle
85 dev.close()
86
87 return
88if __name__ == '__main__':
89 main()