Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

77 wiersze
2.6KB

  1. import SoapySDR
  2. import numpy as np
  3. import gc
  4. from noptica import *
  5. from gui import GUI
  6. def main():
  7. # For this PoC code, a small memory leak is less harmful than random overflows.
  8. gc.disable()
  9. freq_sample = 1e6
  10. freq_base = 1088230e3
  11. block_size = 4096
  12. gui = GUI(freq_sample, freq_base, block_size)
  13. try:
  14. induction = InductionHeater("/dev/ttyUSB0", 350e3, 445e3)
  15. induction.start()
  16. try:
  17. def stabilizer_cb(spectrum, peak_freq, locked, tuning):
  18. gui.update_ref(spectrum, peak_freq, locked)
  19. induction.set(tuning)
  20. stabilizer = Stabilizer(freq_sample, block_size, 1088.1e6 - freq_base, stabilizer_cb)
  21. position_tracker = PositionTracker()
  22. sdr = SoapySDR.Device()
  23. for channel in range(2):
  24. sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, channel, freq_sample)
  25. sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, channel, freq_base)
  26. sdr.setGain(SoapySDR.SOAPY_SDR_RX, channel, 55.0)
  27. buf_sdr = BufferedSDR(sdr, [0, 1], block_size, 32)
  28. buf_sdr.start()
  29. try:
  30. throttle = 0
  31. throttle_factor = 8
  32. position_acc = 0.0
  33. while True:
  34. buffers = buf_sdr.get()
  35. try:
  36. samples_ref, samples_meas = buffers
  37. # Throttle certain things to avoid overflows due to the limited speed of
  38. # the MHS5200A serial interface and GUI plotting.
  39. throttle += 1
  40. if throttle == throttle_factor:
  41. throttle = 0
  42. if throttle == 0:
  43. stabilizer.input(samples_ref)
  44. gui.update_meas(samples_meas)
  45. if stabilizer.locked():
  46. position = position_tracker.input(samples_ref, samples_meas)
  47. position_acc += np.mean(position)
  48. if throttle == 0:
  49. gui.update_position(position_acc/throttle_factor)
  50. position_acc = 0.0
  51. else:
  52. position_tracker.reset()
  53. position_acc = 0.0
  54. finally:
  55. buf_sdr.dispose(buffers)
  56. finally:
  57. buf_sdr.stop()
  58. finally:
  59. induction.stop()
  60. finally:
  61. gui.close()
  62. if __name__ == "__main__":
  63. main()