|
12 | 12 | from pybricks.tools import wait, StopWatch |
13 | 13 |
|
14 | 14 | # Initialize devices. |
15 | | -motor = Motor(Port.A) |
16 | 15 | motor = Motor(port=Port.A, positive_direction=Direction.CLOCKWISE, gears=[]) |
17 | 16 | ultrasonic_sensor = UltrasonicSensor(Port.C) |
18 | 17 |
|
|
43 | 42 | # Test absolute angle for sign change by putting it at +90 degrees clockwise. |
44 | 43 | motor.run_target(500, 90) |
45 | 44 | assert 85 <= motor.angle() <= 95, "Unable to put motor in +90 position." |
46 | | -motor = Motor(Port.A, Direction.COUNTERCLOCKWISE) |
47 | | -assert -85 >= motor.angle() >= -95, "Unexpected angle after CCW init." |
48 | 45 |
|
49 | 46 | # Test angle reset during hold. |
50 | 47 | motor.reset_angle() |
|
56 | 53 | assert motor.speed() < 10, "Motor moved during reset" |
57 | 54 | wait(10) |
58 | 55 |
|
59 | | -# Test DC positive direction signs. |
60 | | -for direction in (Direction.CLOCKWISE, Direction.COUNTERCLOCKWISE, "default"): |
61 | | - |
62 | | - # Initialize the motor with given sign. |
63 | | - if direction == "default": |
64 | | - motor = Motor(Port.A) |
65 | | - else: |
66 | | - motor = Motor(Port.A, direction) |
67 | | - |
68 | | - old_angle = motor.angle() |
69 | | - motor.dc(100) |
70 | | - wait(1000) |
71 | | - assert motor.angle() > old_angle + 90 |
72 | | - motor.dc(0) |
73 | | - wait(500) |
74 | | - |
75 | 56 | # The motor is now in positive orientation. Test DC forward. |
76 | 57 | old_angle = motor.angle() |
77 | 58 | motor.dc(50) |
|
111 | 92 |
|
112 | 93 | # Compare with reported speed. |
113 | 94 | for value in reported_speed: |
114 | | - assert abs(value - real_speed) <= 100 |
| 95 | + assert abs(value - real_speed) <= 150 |
0 commit comments