forked from rtitmuss/splitflap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalibrate.py
More file actions
118 lines (89 loc) · 3.48 KB
/
Copy pathCalibrate.py
File metadata and controls
118 lines (89 loc) · 3.48 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import time
from math import ceil
from typing import List, Union
from Message import Message
from Panel import Panel
from primary.Display import Display
from StepperMotor import STEPS_PER_REVOLUTION
from Message import _STEPS_PER_LETTER, LETTERS, _letter_position
from ElementGpio import ElementGpio
"""
Split-Flap Display Calibration
This script helps you calculate per-flap mechanical offsets for a split-flap display.
# Background
Each character (e.g., 'A', '3') corresponds to a specific step range on the stepper motor.
However, mechanical variances cause each flap to "tick" into view at slightly different positions.
To correct this, we compute an offset per flap by comparing the actual tick-in position with the theoretical one.
# How It Works
You measure and record:
1. The step number where each flap *starts showing* the letter 'A'
2. The step number where each flap *starts showing* the digit '3'
e.g.
from Calibrate import calibrate, calculate_offsets
step = calibrate(panel, num_elements=24)
step()
# write down position when letter is A
step(1340)
# all letters should show 2
step()
# write down position when letter is 3
We then:
- Compare these with their theoretical tick-in positions:
- 'A' starts at step 45
- '3' starts at step 1366
- Compute the per-flap error for both A and 3
- Average them for a robust calibration offset
# Usage Steps
1. Run the `calibrate()` function to manually step your flaps and find:
- When each flap first shows 'A'
- When each flap first shows '3'
2. Fill in the `a_steps` and `three_steps` lists below.
3. Run `calculate_offsets()` to generate `display_offsets`.
"""
# Constants based on your system
EXPECTED_TICK_IN_A = _letter_position('A') - _STEPS_PER_LETTER / 2
EXPECTED_TICK_IN_3 = _letter_position('3') - _STEPS_PER_LETTER / 2
def calibrate(panel: Panel, num_elements: int):
position = 0
print(f"STEPS_PER_REVOLUTION: {STEPS_PER_REVOLUTION}")
print(f"STEPS_PER_LETTER: {_STEPS_PER_LETTER}")
print(f"A: {_letter_position('A')}")
print(f"3: {_letter_position('3')}")
def step(new_position: Union[int, None] = None):
nonlocal position
if new_position:
position = new_position
print(position)
message = Message(15, [0] * num_elements, [position] * num_elements)
panel.set_message(message)
while not panel.is_stopped():
interval_us = panel.step()
time.sleep_us(interval_us)
return step
def calculate_offsets():
a_steps = [
35, 20, 8, 13, 1, 8, 11, 27
]
three_steps = [
1500, 1479, 1462, 1467, 1469, 1475, 1461, 1506
]
assert len(a_steps) == len(three_steps), "Mismatch in input lengths."
offsets = []
for a, t in zip(a_steps, three_steps):
offset_a = a - EXPECTED_TICK_IN_A
offset_3 = t - EXPECTED_TICK_IN_3
average = round((offset_a + offset_3) / 2)
offsets.append(average)
print("display_offsets =", offsets)
# Define panel and element(s)
panel = Panel([
#ElementGpio(2, 18, 19, 20, 21, reverse_direction=True), # Motor B with sensor B
ElementGpio(1, 9, 8, 7, 6, reverse_direction=True), # Motor D with sensor C
])
# Specify number of elements to calibrate in the panel with num_elements. The current panel has 2 elements, so both can be calibrated
# at once. But it's advisable to focus on one at a time
step = calibrate(panel, num_elements=1)
# Specify number of steps for the stepper motor to run
step(1520)
# Calculate offsets
calculate_offsets()