Skip to content

Commit fa080f7

Browse files
committed
tests/pup/motors: Read logged data in script.
1 parent b593e73 commit fa080f7

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

tests/pup/motors/log_servo.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,29 @@
2727
motor.run_target(500, 360)
2828

2929
# Wait so we can also log hold capability, then turn off the motor completely.
30-
wait(1000)
30+
wait(100)
3131
motor.stop()
3232

3333
# Save the data by printing it. Pybricksdev will capture the printed
3434
# data and save it to the given path relative to this script.
35-
motor.log.save('build/servo_data.txt')
36-
motor.control.log.save('build/control_data.txt')
35+
motor.log.save("build/servo_data.txt")
36+
motor.control.log.save("build/control_data.txt")
37+
38+
# The log can also be read from the user script. For fun, let's print the
39+
# position and the estimated speed in a rotated plot. We show only 1 in 3
40+
# samples here and scale the speed and angle values for better visibility.
41+
for i in range(len(motor.log) / 3):
42+
43+
# Read the (i * 3)th row in the data log.
44+
values = motor.log.get(i * 3)
45+
speed = values[7]
46+
angle = values[2]
47+
48+
# Turn it into a line of spaces with * for speed and + for angle.
49+
line = [ord(" ")] * 100
50+
line[speed // 6] = ord("*")
51+
line[angle // 5] = ord("+")
52+
53+
# Print it. Looked at it sideways, you should see a trapezoidal graph
54+
# for speed and a gradual ramp for the angle.
55+
print(bytes(line))

0 commit comments

Comments
 (0)