-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraph.py
More file actions
44 lines (39 loc) · 1.07 KB
/
graph.py
File metadata and controls
44 lines (39 loc) · 1.07 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
servo_hz = 1000.
def compute(freq):
fsys = 125000000
#divisor = 128
if freq < 100:
divisor = (1<<16)-1
elif freq < 200:
divisor = (1<<15)-1
else:
divisor = int(fsys / (freq * (15 + 1)))
if divisor >= 1<<16:
raise ValueError(f"Frequency too low for servo {freq} divisor {divisor}")
delay = (fsys // divisor) / freq - 15
if delay < 1: delay = 1
delay = int(delay) /16.
period = 1./(fsys // divisor) * (15 + delay)
true_freq = 1./period
rel_error = (true_freq - freq) / freq
return (rel_error), period, delay
freqs = []
err = []
delays = []
delay_counts = []
minfreq, maxfreq = 1, 1000
for freq in range(minfreq, maxfreq):
e = compute(freq)
freqs.append(freq)
err.append(e[0])
delays.append(e[1])
delay_counts.append(e[2])
import matplotlib.pyplot as plt
plt.subplot(3,1,1)
plt.plot(freqs, delays, '-', [minfreq, maxfreq], [1./servo_hz, 1./servo_hz],'-')
plt.subplot(3,1,2)
plt.plot(freqs, err)
plt.subplot(3,1,3)
plt.plot(freqs, delay_counts)
print(freqs, err)
plt.show()