forked from robotics-4-all/tektrain-robot-sw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_df_robot_wheel_encoder_mcp23017.py
64 lines (50 loc) · 1.71 KB
/
test_df_robot_wheel_encoder_mcp23017.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
import unittest
import time
from pidevices import DfRobotWheelEncoderMcp23017
class TestDfRobotWheelEncoderMcp23017(unittest.TestCase):
def test_read(self):
encoder = DfRobotWheelEncoderMcp23017(pin='B_6', bus=3, address=0x22)
counter = 0
print("Five measurments with positive edge")
f = True
while f:
val = encoder.read()
print("Encoder value: {}".format(val))
if val:
counter += 1
if counter > 4:
f = False
time.sleep(0.1)
self.assertEqual(f, False, "Should be False")
print("Five measurments with negative edge")
while not f:
val = encoder.read()
print("Encoder value: {}".format(val))
if not val:
counter -= 1
if counter < 1:
f = True
time.sleep(0.1)
self.assertEqual(f, True, "Should be True")
encoder.stop()
def test_counter(self):
encoder = DfRobotWheelEncoderMcp23017(pin='B_6', bus=3, address=0x22)
value = 0
limit = 10
while True:
value = encoder._counter
print("Counter: {}".format(value))
if (value > (limit - 1)):
break
time.sleep(0.1)
self.assertEqual(value, limit, "Should be {}".format(limit))
encoder.stop()
def test_rpm(self):
encoder = DfRobotWheelEncoderMcp23017(pin='B_6', bus=3, address=0x22)
t_s = time.time()
while time.time() - t_s < 60:
print("RPM: {}".format(encoder.read_rpm()))
time.sleep(1)
encoder.stop()
if __name__ == "__main__":
unittest.main()