noptica2-sdr/dmi.py

54 lines
1.6 KiB
Python
Raw Normal View History

import SoapySDR
import numpy as np
2020-01-27 17:24:59 +08:00
import gc
2020-01-05 19:31:07 +08:00
2020-01-27 17:24:59 +08:00
from noptica import *
2020-01-05 19:31:07 +08:00
def main():
2020-01-27 17:24:59 +08:00
# For this PoC code, a small memory leak is less harmful than random overflows.
gc.disable()
2020-01-11 16:06:54 +08:00
freq_sample = 5e6
freq_base = 1086e6
2020-01-11 18:41:18 +08:00
bufsize = 4096
2020-01-11 16:06:54 +08:00
2020-01-25 15:26:43 +08:00
induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
2020-01-05 19:31:07 +08:00
induction.start()
try:
2020-01-25 15:26:43 +08:00
stabilizer = Stabilizer(freq_sample, 0.4, 1088.1e6 - freq_base, 50e-6, induction)
2020-01-11 18:41:18 +08:00
position_tracker = PositionTracker(int(0.1*freq_sample/bufsize))
2020-01-05 19:31:07 +08:00
2020-01-11 16:06:54 +08:00
sdr = SoapySDR.Device()
2020-01-11 18:41:18 +08:00
for channel in range(2):
sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
2020-01-05 19:31:07 +08:00
2020-01-27 17:24:59 +08:00
buf_sdr = BufferedSDR(sdr, [0, 1], bufsize, 256)
buf_sdr.start()
2020-01-05 19:31:07 +08:00
try:
2020-01-27 17:24:59 +08:00
stabilizer_throttle = 0
while True:
buffers = buf_sdr.get()
try:
samples_ref, samples_meas = buffers
2020-01-11 16:06:54 +08:00
2020-01-11 18:41:18 +08:00
# We can't update faster than the MHS5200A serial interface
2020-01-11 16:06:54 +08:00
stabilizer_throttle += 1
2020-01-27 17:24:59 +08:00
if stabilizer_throttle == 40:
2020-01-11 18:41:18 +08:00
stabilizer.input(samples_ref)
2020-01-11 16:06:54 +08:00
stabilizer_throttle = 0
2020-01-11 18:41:18 +08:00
position, leakage = position_tracker.input(samples_ref, samples_meas)
print(np.sum(position)/len(position), leakage)
2020-01-27 17:24:59 +08:00
finally:
buf_sdr.dispose(buffers)
2020-01-05 19:31:07 +08:00
finally:
2020-01-27 17:24:59 +08:00
buf_sdr.stop()
2020-01-05 19:31:07 +08:00
finally:
induction.stop()
if __name__ == "__main__":
main()