AHRS getEstimation

 1'''
 2AHRS - AHRS_getEstimation.py with synchronous 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
24def main():
25    ## Get Python driver version
26    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
27
28    ## Create device handle
29    dev = pywpc.WifiDAQE3AH()
30
31    ## Connect to device
32    try:
33        dev.connect("192.168.5.38")  ## Depend on your device
34    except Exception as err:
35        pywpc.printGenericError(err)
36        ## Release device handle
37        dev.close()
38        return
39
40    try:
41        ## Parameters setting
42        port = 0  ## Depend on your device
43        mode = 6  ## 3-axis of orientation and angular velocity and acceleration
44        timeout = 3  ## [sec]
45
46        ## Get firmware model & version
47        driver_info = dev.Sys_getDriverInfo(timeout)
48        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
49
50        ## Open AHRS and update rate is 333 HZ
51        err = dev.AHRS_open(port, timeout)
52        print(f"AHRS_open in port {port}, status: {err}")
53
54        ## Start AHRS
55        err = dev.AHRS_start(port, timeout)
56        print(f"AHRS_start in port {port}, status: {err}")
57
58        ## Get three axis data by mode
59        while True:
60            ahrs_list = dev.AHRS_getEstimate(port, mode, timeout)
61            print(ahrs_list)
62    except KeyboardInterrupt:
63        print("Press keyboard")
64
65    except Exception as err:
66        pywpc.printGenericError(err)
67
68    finally:
69        ## Stop AHRS
70        err = dev.AHRS_stop(port, timeout)
71        print(f"AHRS_stop in port {port}, status: {err}")
72
73        ## Close AHRS
74        err = dev.AHRS_close(port, timeout)
75        print(f"AHRS_close in port {port}, status: {err}")
76
77        ## Disconnect device
78        dev.disconnect()
79
80        ## Release device handle
81        dev.close()
82
83
84if __name__ == '__main__':
85    main()