Compare commits

...

4 Commits

Author SHA1 Message Date
Sebastien Bourdeauducq 22bcbecab8 random wiggle 2020-08-11 18:36:25 +08:00
Sebastien Bourdeauducq 2c05dda88a reset induction heater on exit 2020-08-11 18:36:17 +08:00
Sebastien Bourdeauducq 946eb113bb improve GUI 2020-08-11 18:35:49 +08:00
Sebastien Bourdeauducq 702ee463dd average position 2020-08-11 18:35:30 +08:00
3 changed files with 16 additions and 10 deletions

9
dmi.py
View File

@ -35,6 +35,8 @@ def main():
buf_sdr.start()
try:
throttle = 0
throttle_factor = 8
position_acc = 0.0
while True:
buffers = buf_sdr.get()
try:
@ -43,7 +45,7 @@ def main():
# Throttle certain things to avoid overflows due to the limited speed of
# the MHS5200A serial interface and GUI plotting.
throttle += 1
if throttle == 8:
if throttle == throttle_factor:
throttle = 0
if throttle == 0:
@ -52,10 +54,13 @@ def main():
if stabilizer.locked():
position = position_tracker.input(samples_ref, samples_meas)
position_acc += np.sum(position)/len(position)
if throttle == 0:
gui.update_position(np.sum(position)/len(position))
gui.update_position(position_acc/throttle_factor)
position_acc = 0.0
else:
position_tracker.reset()
position_acc = 0.0
finally:
buf_sdr.dispose(buffers)
finally:

View File

@ -42,15 +42,15 @@ class MainWindow(pg.GraphicsLayoutWidget):
self.addItem(self.text_locked, row=0, col=1)
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)
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)
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)
def update_ref(self, block, peak_freq, locked):
@ -72,7 +72,7 @@ class MainWindow(pg.GraphicsLayoutWidget):
def update_position(self, position):
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.plot(self.position_history)

View File

@ -100,6 +100,7 @@ class InductionHeater:
self.queue.put(amount, block=False)
def stop(self):
self.queue.put(0.0, block=True)
self.queue.put(None, block=True)
self.thread.join()
self.serial.close()
@ -113,14 +114,14 @@ class Stabilizer:
self.lock_counter = 0
self.unlock_counter = 0
self.wiggle_direction = 1
self.wiggle = 0.0
self.amp_threshold = 80.0
self.k = 30.0e-6
self.tolerance = 10e3
self.lock_counter_threshold = 60
self.unlock_counter_threshold = 500
self.wiggle = 0.15
self.wiggle_amplitude = 0.15
def input(self, samples):
spectrum = np.abs(np.fft.fft(samples*blackmanharris(len(samples))))
@ -151,10 +152,10 @@ class Stabilizer:
self.unlock_counter += 1
if not success and (self.unlock_counter > self.unlock_counter_threshold):
print("wiggle")
self.wiggle_direction = -self.wiggle_direction
self.wiggle = self.wiggle_amplitude*(np.random.random() - 0.5)
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):
return self.lock_counter > self.lock_counter_threshold