-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcr_example3_callback.py
46 lines (32 loc) · 1.17 KB
/
cr_example3_callback.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
#!/usr/bin/env python3
# whill module example package
# Copyright (c) 2018 WHILL, Inc.
# This software is released under the MIT License.
import time
from whill import ComWHILL
request_speed_mode = 0
whill = ComWHILL(port='COM4')
def callback0():
global request_speed_mode, whill
print('callback 0')
print(whill.speed_profile[request_speed_mode])
whill.start_data_stream(1000, 1, request_speed_mode)
def callback1():
global request_speed_mode, whill
print('callback 1')
level, current = whill.battery.values()
print(whill.joy)
print('Battery Status: remaining capacity {level}%, current draiwng {current}mA'.format(level=level,
current=current))
print('Motor Status')
request_speed_mode = (request_speed_mode + 1) % 6
whill.start_data_stream(1000, 0, request_speed_mode)
def main():
whill.register_callback('data_set_0', callback0)
whill.register_callback('data_set_1', callback1)
whill.start_data_stream(1000, 0, request_speed_mode)
while True:
time.sleep(0.1)
whill.refresh()
if __name__ == "__main__":
main()