plot position
This commit is contained in:
parent
da5676b2c7
commit
cb1f1c047e
24
dmi.py
24
dmi.py
|
@ -24,34 +24,36 @@ def main():
|
||||||
induction.set(tuning)
|
induction.set(tuning)
|
||||||
|
|
||||||
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
|
stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
|
||||||
position_tracker = PositionTracker(int(0.1*freq_sample/block_size))
|
position_tracker = PositionTracker()
|
||||||
|
|
||||||
sdr = SoapySDR.Device()
|
sdr = SoapySDR.Device()
|
||||||
for channel in range(2):
|
for channel in range(2):
|
||||||
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
|
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
|
||||||
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
|
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
|
||||||
|
|
||||||
buf_sdr = BufferedSDR(sdr, [0, 1], block_size, 256)
|
buf_sdr = BufferedSDR(sdr, [0, 1], block_size, 32)
|
||||||
buf_sdr.start()
|
buf_sdr.start()
|
||||||
try:
|
try:
|
||||||
stabilizer_throttle = 0
|
throttle = 0
|
||||||
while True:
|
while True:
|
||||||
buffers = buf_sdr.get()
|
buffers = buf_sdr.get()
|
||||||
try:
|
try:
|
||||||
samples_ref, samples_meas = buffers
|
samples_ref, samples_meas = buffers
|
||||||
|
|
||||||
# We can't update faster than the MHS5200A serial interface
|
# Throttle certain things to avoid overflows due to the limited speed of
|
||||||
stabilizer_throttle += 1
|
# the MHS5200A serial interface and GUI plotting.
|
||||||
if stabilizer_throttle == 8:
|
throttle += 1
|
||||||
stabilizer.input(samples_ref)
|
if throttle == 8:
|
||||||
stabilizer_throttle = 0
|
throttle = 0
|
||||||
|
|
||||||
# Update the MEAS GUI at the same time so it's synchronized
|
if throttle == 0:
|
||||||
|
stabilizer.input(samples_ref)
|
||||||
gui.update_meas(samples_meas)
|
gui.update_meas(samples_meas)
|
||||||
|
|
||||||
if stabilizer.locked():
|
if stabilizer.locked():
|
||||||
position, leakage = position_tracker.input(samples_ref, samples_meas)
|
position = position_tracker.input(samples_ref, samples_meas)
|
||||||
print(np.sum(position)/len(position), leakage)
|
if throttle == 0:
|
||||||
|
gui.update_position(np.sum(position)/len(position))
|
||||||
else:
|
else:
|
||||||
position_tracker.reset()
|
position_tracker.reset()
|
||||||
finally:
|
finally:
|
||||||
|
|
4
gui.py
4
gui.py
|
@ -62,6 +62,10 @@ class GUI:
|
||||||
obj = {"action": "update_meas", "block": block}
|
obj = {"action": "update_meas", "block": block}
|
||||||
self.impl.write_pyon(obj)
|
self.impl.write_pyon(obj)
|
||||||
|
|
||||||
|
def update_position(self, position):
|
||||||
|
obj = {"action": "update_position", "position": position}
|
||||||
|
self.impl.write_pyon(obj)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
obj = {"action": "terminate"}
|
obj = {"action": "terminate"}
|
||||||
self.impl.write_pyon(obj)
|
self.impl.write_pyon(obj)
|
||||||
|
|
|
@ -50,6 +50,9 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
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_history = np.zeros(300)
|
||||||
|
|
||||||
def update_ref(self, block, peak_freq, locked):
|
def update_ref(self, block, peak_freq, locked):
|
||||||
if block is not None:
|
if block is not None:
|
||||||
self.ref_spectrum.add_block(block)
|
self.ref_spectrum.add_block(block)
|
||||||
|
@ -67,6 +70,12 @@ class MainWindow(pg.GraphicsLayoutWidget):
|
||||||
spectrum = np.abs(np.fft.fft(block*blackmanharris(self.block_size)))
|
spectrum = np.abs(np.fft.fft(block*blackmanharris(self.block_size)))
|
||||||
self.meas_spectrum.add_block(spectrum)
|
self.meas_spectrum.add_block(spectrum)
|
||||||
|
|
||||||
|
def update_position(self, position):
|
||||||
|
self.position_history = np.roll(self.position_history, -1)
|
||||||
|
self.position_history[-1] = position
|
||||||
|
self.position.clear()
|
||||||
|
self.position.plot(self.position_history)
|
||||||
|
|
||||||
|
|
||||||
class IPCClient(AsyncioChildComm):
|
class IPCClient(AsyncioChildComm):
|
||||||
def set_close_cb(self, close_cb):
|
def set_close_cb(self, close_cb):
|
||||||
|
|
14
noptica.py
14
noptica.py
|
@ -169,25 +169,17 @@ def continuous_unwrap(last_phase, last_phase_unwrapped, p):
|
||||||
|
|
||||||
|
|
||||||
class PositionTracker:
|
class PositionTracker:
|
||||||
def __init__(self, leakage_avg):
|
def __init__(self):
|
||||||
self.leakage_avg = leakage_avg
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.last_phase = 0.0
|
self.last_phase = 0.0
|
||||||
self.last_position = 0.0
|
self.last_position = 0.0
|
||||||
self.leakage = np.zeros(self.leakage_avg)
|
|
||||||
self.leakage_ptr = 0
|
|
||||||
|
|
||||||
def input(self, ref, meas):
|
def input(self, ref, meas):
|
||||||
demod = np.conjugate(ref)*meas
|
demod = np.conjugate(ref)*meas
|
||||||
|
phase = np.angle(demod)
|
||||||
self.leakage[self.leakage_ptr] = np.real(np.sum(demod)/len(demod))
|
|
||||||
self.leakage_ptr = (self.leakage_ptr + 1) % len(self.leakage)
|
|
||||||
leakage = np.sum(self.leakage)/len(self.leakage)
|
|
||||||
|
|
||||||
phase = np.angle(demod - leakage)
|
|
||||||
position = continuous_unwrap(self.last_phase, self.last_position, phase)/(2.0*np.pi)
|
position = continuous_unwrap(self.last_phase, self.last_position, phase)/(2.0*np.pi)
|
||||||
self.last_phase = phase[-1]
|
self.last_phase = phase[-1]
|
||||||
self.last_position = position[-1]
|
self.last_position = position[-1]
|
||||||
return position, leakage
|
return position
|
||||||
|
|
Loading…
Reference in New Issue