-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
101 lines (82 loc) · 3.51 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import asyncio
import blesensor
import time
import sys
###############################################################################################
####### Notice: 2023-03-24 ###########
####### Author: Bryan He ###########
####### before running this program in Windows ###########
####### please firstly go to Windows Bluetooth, Add device, and connect that DOT!!! ###########
###############################################################################################
async def main():
#scan sensors
scanner = blesensor.Scanner() # Create an instance of Scanner
devices = await scanner.scan_and_filter_xsens_dot(5) # Use the instance to call the method
if not devices:
print("No Xsens DOT, considering turn them on or shake them from sleep mode")
return
sensors = []
for d in devices:
sensors.append(blesensor.BleSensor(d.address))
print("start to connect:")
for s in sensors:
await s.connect()
print("connect finish.")
# print("\nServices and characteristics:")
# for s in sensors:
# await s.get_services()
# await asyncio.sleep(2) # wait for response
# # print("Identify Sensors")
# for s in sensors:
# await s.identifySensor()
# await asyncio.sleep(2) # wait for response
# await asyncio.sleep(2) # wait for response
# # print("Change Device Tag")
# for i in range(len(sensors)):
# sensors[i].name = "dot" + str(i+1)
# await sensors[i].setDeviceTag(sensors[i].name)
# await asyncio.sleep(2) # wait for response
await asyncio.sleep(2) # wait for response
print("Battery Status")
for i in range(len(sensors)):
batteryInfo = await sensors[i].getBatteryInfo()
print(batteryInfo)
await asyncio.sleep(2) # wait for response
print("set sensor output rate, only these values allowed: 1, 4, 10, 12, 15, 20, 30, 60, 120")
for s in sensors:
await s.setOuputRate(30)
#Start Measurement in specific mode, cutomMode1 or orientationEuler or orientationQuaternion
for s in sensors:
s.payloadType = blesensor.PayloadMode.orientationEuler
await s.startMeasurement()
print("\nNotifications enabled. Waiting for data...")
#heading reset
await asyncio.sleep(0.2) # wait for response
print("do heading reset")
for s in sensors:
await s.doHeadingReset()
#default is no recording, here to enable the recording after heading reset
s.fileName = s.create_csvfile()
s.recordFlag = True
# Run within the timeToRunInMinute time range.
startTimeSeconds = int(round(time.time()))
timeToRunInMinute = 1
print(f"run the test for {timeToRunInMinute} minutes")
while int(round(time.time())) - startTimeSeconds < timeToRunInMinute*60:
await asyncio.sleep(0.1)
#stop measurement
for s in sensors:
await s.stopMeasurement()
await asyncio.sleep(0.5)
# print("Power Off Sensors")
# for s in sensors:
# await s.poweroffSensor()
# await asyncio.sleep(2) # wait for response
print("disconnect all sensors")
for s in sensors:
await s.disconnect()
print("exit program")
await sys.exit(0)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(main())