Compare commits
4 Commits
cb1f1c047e
...
22bcbecab8
Author | SHA1 | Date |
---|---|---|
Sebastien Bourdeauducq | 22bcbecab8 | |
Sebastien Bourdeauducq | 2c05dda88a | |
Sebastien Bourdeauducq | 946eb113bb | |
Sebastien Bourdeauducq | 702ee463dd |
9
dmi.py
9
dmi.py
|
@ -35,6 +35,8 @@ def main():
|
||||||
buf_sdr.start()
|
buf_sdr.start()
|
||||||
try:
|
try:
|
||||||
throttle = 0
|
throttle = 0
|
||||||
|
throttle_factor = 8
|
||||||
|
position_acc = 0.0
|
||||||
while True:
|
while True:
|
||||||
buffers = buf_sdr.get()
|
buffers = buf_sdr.get()
|
||||||
try:
|
try:
|
||||||
|
@ -43,7 +45,7 @@ def main():
|
||||||
# Throttle certain things to avoid overflows due to the limited speed of
|
# Throttle certain things to avoid overflows due to the limited speed of
|
||||||
# the MHS5200A serial interface and GUI plotting.
|
# the MHS5200A serial interface and GUI plotting.
|
||||||
throttle += 1
|
throttle += 1
|
||||||
if throttle == 8:
|
if throttle == throttle_factor:
|
||||||
throttle = 0
|
throttle = 0
|
||||||
|
|
||||||
if throttle == 0:
|
if throttle == 0:
|
||||||
|
@ -52,10 +54,13 @@ def main():
|
||||||
|
|
||||||
if stabilizer.locked():
|
if stabilizer.locked():
|
||||||
position = position_tracker.input(samples_ref, samples_meas)
|
position = position_tracker.input(samples_ref, samples_meas)
|
||||||
|
position_acc += np.sum(position)/len(position)
|
||||||
if throttle == 0:
|
if throttle == 0:
|
||||||
gui.update_position(np.sum(position)/len(position))
|
gui.update_position(position_acc/throttle_factor)
|
||||||
|
position_acc = 0.0
|
||||||
else:
|
else:
|
||||||
position_tracker.reset()
|
position_tracker.reset()
|
||||||
|
position_acc = 0.0
|
||||||
finally:
|
finally:
|
||||||
buf_sdr.dispose(buffers)
|
buf_sdr.dispose(buffers)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -42,15 +42,15 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
self.addItem(self.text_locked, row=0, col=1)
|
self.addItem(self.text_locked, row=0, col=1)
|
||||||
self.update_ref(None, None, False)
|
self.update_ref(None, None, False)
|
||||||
|
|
||||||
p1 = self.addPlot(row=1, col=0, colspan=2)
|
p1 = self.addPlot(row=1, col=0, colspan=2, title="REF spectrum")
|
||||||
self.ref_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
self.ref_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
||||||
p1.addItem(self.ref_spectrum)
|
p1.addItem(self.ref_spectrum)
|
||||||
|
|
||||||
p2 = self.addPlot(row=2, col=0, colspan=2)
|
p2 = self.addPlot(row=2, col=0, colspan=2, title="MEAS spectrum")
|
||||||
self.meas_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
self.meas_spectrum = SpectrogramItem(freq_sample, freq_base, block_size)
|
||||||
p2.addItem(self.meas_spectrum)
|
p2.addItem(self.meas_spectrum)
|
||||||
|
|
||||||
self.position = self.addPlot(row=3, col=0, colspan=2)
|
self.position = self.addPlot(row=3, col=0, colspan=2, title="Position (nm)")
|
||||||
self.position_history = np.zeros(300)
|
self.position_history = np.zeros(300)
|
||||||
|
|
||||||
def update_ref(self, block, peak_freq, locked):
|
def update_ref(self, block, peak_freq, locked):
|
||||||
|
@ -72,7 +72,7 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
|
|
||||||
def update_position(self, position):
|
def update_position(self, position):
|
||||||
self.position_history = np.roll(self.position_history, -1)
|
self.position_history = np.roll(self.position_history, -1)
|
||||||
self.position_history[-1] = position
|
self.position_history[-1] = position*632.816/2
|
||||||
self.position.clear()
|
self.position.clear()
|
||||||
self.position.plot(self.position_history)
|
self.position.plot(self.position_history)
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,7 @@ class InductionHeater:
|
||||||
self.queue.put(amount, block=False)
|
self.queue.put(amount, block=False)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
self.queue.put(0.0, block=True)
|
||||||
self.queue.put(None, block=True)
|
self.queue.put(None, block=True)
|
||||||
self.thread.join()
|
self.thread.join()
|
||||||
self.serial.close()
|
self.serial.close()
|
||||||
|
@ -113,14 +114,14 @@ class Stabilizer:
|
||||||
|
|
||||||
self.lock_counter = 0
|
self.lock_counter = 0
|
||||||
self.unlock_counter = 0
|
self.unlock_counter = 0
|
||||||
self.wiggle_direction = 1
|
self.wiggle = 0.0
|
||||||
|
|
||||||
self.amp_threshold = 80.0
|
self.amp_threshold = 80.0
|
||||||
self.k = 30.0e-6
|
self.k = 30.0e-6
|
||||||
self.tolerance = 10e3
|
self.tolerance = 10e3
|
||||||
self.lock_counter_threshold = 60
|
self.lock_counter_threshold = 60
|
||||||
self.unlock_counter_threshold = 500
|
self.unlock_counter_threshold = 500
|
||||||
self.wiggle = 0.15
|
self.wiggle_amplitude = 0.15
|
||||||
|
|
||||||
def input(self, samples):
|
def input(self, samples):
|
||||||
spectrum = np.abs(np.fft.fft(samples*blackmanharris(len(samples))))
|
spectrum = np.abs(np.fft.fft(samples*blackmanharris(len(samples))))
|
||||||
|
@ -151,10 +152,10 @@ class Stabilizer:
|
||||||
self.unlock_counter += 1
|
self.unlock_counter += 1
|
||||||
if not success and (self.unlock_counter > self.unlock_counter_threshold):
|
if not success and (self.unlock_counter > self.unlock_counter_threshold):
|
||||||
print("wiggle")
|
print("wiggle")
|
||||||
self.wiggle_direction = -self.wiggle_direction
|
self.wiggle = self.wiggle_amplitude*(np.random.random() - 0.5)
|
||||||
self.unlock_counter = 0
|
self.unlock_counter = 0
|
||||||
|
|
||||||
self.cb(spectrum, freq, self.locked(), tuning + self.wiggle_direction*self.wiggle)
|
self.cb(spectrum, freq, self.locked(), tuning + self.wiggle)
|
||||||
|
|
||||||
def locked(self):
|
def locked(self):
|
||||||
return self.lock_counter > self.lock_counter_threshold
|
return self.lock_counter > self.lock_counter_threshold
|
||||||
|
|
Loading…
Reference in New Issue