Skip to content
Snippets Groups Projects
Commit e97f9d62 authored by Merlo, Jason's avatar Merlo, Jason
Browse files

Updated to be more general

parent 9ce2c5e6
No related branches found
No related tags found
No related merge requests found
......@@ -121,24 +121,21 @@ class nidaq(DAQ):
time.sleep(sleep_time)
def run(self):
if self.running == False:
# Spawn sampling thread
self.running = True
self.t_sampling = threading.Thread(target=self.sample_loop)
# Trigger DAQ to start running
self.start()
try:
if not self.t_sampling.is_alive():
print('Staring sampling thread')
self.t_sampling.start()
self.paused = False
except RuntimeError as e:
print('Error starting sampling thread: ', e)
else:
print('Warning: Not starting new sampling thread; sampling thread already running!')
def run(self):
if self.running == False:
# Spawn sampling thread
self.running = True
self.t_sampling = threading.Thread(target=self.sample_loop)
try:
if not self.t_sampling.is_alive():
print('Staring sampling thread')
self.t_sampling.start()
self.paused = False
except RuntimeError as e:
print('Error starting sampling thread: ', e)
else:
print('Warning: Not starting new sampling thread; sampling thread already running!')
def start(self):
self.run()
......@@ -153,5 +150,5 @@ class nidaq(DAQ):
self.t_sampling.join()
except Exception as e:
print("Error closing sampling thread: ", e)
super().close()
......@@ -19,6 +19,7 @@ from pyqtgraph import QtCore
from pyratk.formatting import warning
from profilehooks import profile
# CONSTANTS
POWER_THRESHOLD = 4 # dBm
......@@ -36,7 +37,7 @@ class Radar(object):
"""
# === INITIALIZATION METHODS ==============================================
def __init__(self, data_mgr, data_idx, loc=Point(),
def __init__(self, data_mgr, index, loc=Point(),
f0=24.150e9, fft_size=2**16, fft_win_size=2**12,
cluda_thread=None):
super(Radar, self).__init__()
......@@ -55,7 +56,7 @@ class Radar(object):
# Data stream parameters
# TODO: create DataStream object representing I or I/Q data
self.data_mgr = data_mgr
self.index = data_idx
self.index = index
# Physical parameters
self.f0 = f0
......@@ -128,8 +129,7 @@ class Radar(object):
# === CONTROL METHODS =====================================================
def update(self, data):
# Get data from data_mgr
channel_slice = 2 * self.index
data_slice = data[channel_slice:channel_slice + 2]
data_slice = np.array((data[self.index[0]], data[self.index[1]]))
# TODO remove ts_data, use data_mgr.ts_buffer instead
self.ts_data.append(data_slice)
......@@ -156,11 +156,10 @@ class Radar(object):
# self.fmax = self.bin_to_freq(vmax_bin)
self.drho = self.freq_to_vel(self.fmax)
print('(radar.py) radar', self.index, 'drho:', self.drho)
# print('(radar.py) radar', self.index, 'drho:', self.drho)
def reset(self):
"""Reset all radar data."""
print("(radar.py) Resetting radar {:}...".format(self.index))
self.ts_data.clear()
......@@ -210,12 +209,13 @@ class RadarArray(QtCore.QObject):
radar.reset()
self.last_sample_index = -1
# @profile(immediate=True)
def update(self, data_tuple):
"""Update all radars in array."""
# start_time = time.time()
data, sample_index = data_tuple
print('(radar.py) sample_num:', sample_index)
# print('(radar.py) sample_num:', sample_index)
if sample_index == self.last_sample_index + 1:
self.reset_flag = False
......
......@@ -14,7 +14,7 @@ import time # Used for FPS calculations
class FftWidget(pg.GraphicsLayoutWidget):
def __init__(self, radar, vmax_len=100, show_max_plot=False,
fft_yrange=[-100,100], fft_xrange=[-5000,5000]):
fft_yrange=[-100,100], fft_xrange=[-50000,50000]):
super(FftWidget, self).__init__()
# Copy arguments to member variables
......@@ -24,7 +24,7 @@ class FftWidget(pg.GraphicsLayoutWidget):
self.vmax_len = vmax_len
self.update_period = \
self.source.sample_chunk_size / self.source.sample_rate
self.show_max_plot = show_max_plot and False
self.show_max_plot = show_max_plot
# Add FFT max plot to layout
if show_max_plot:
......@@ -38,8 +38,8 @@ class FftWidget(pg.GraphicsLayoutWidget):
xMax=0, yMax=20, yMin=-20)
self.vmax_pw = self.vmax_plot.plot()
self.vmax_line = pg.InfiniteLine(angle=0, movable=False)
self.vmax_plot.addItem(self.vmax_line)
# self.vmax_line = pg.InfiniteLine(angle=0, movable=False)
# self.vmax_plot.addItem(self.vmax_line)
# self.a_pw = self.vmax_plot.plot()
self.vmax_plot.setLabel('left', text="Radial Velocity", units="m/s")
......@@ -54,6 +54,9 @@ class FftWidget(pg.GraphicsLayoutWidget):
# fft_xrange = [-50 / self.radar.bin_size, 50 / self.radar.bin_size]
# fft_yrange = [-100, 0]
for r in fft_xrange:
r /= self.radar.bin_size
# Add FFT plot
self.fft_plot = self.addPlot()
......@@ -74,7 +77,7 @@ class FftWidget(pg.GraphicsLayoutWidget):
self.fft_ax_bottom = self.fft_plot.getAxis('bottom')
self.fft_ax_bottom.setScale(self.radar.bin_size)
self.fft_plot.setLabel('bottom', text="Frequency", units="Hz")
self.fft_plot.setLabel('left', text="Power", units="dBm")
self.fft_plot.setLabel('left', text="PSD", units="dBv")
# FPS ticker data
self.lastTime = time.time()
......@@ -87,7 +90,7 @@ class FftWidget(pg.GraphicsLayoutWidget):
self.vmax_pw.setData(vmax_data, pen=pg.mkPen({'color': "FFF"}))
self.vmax_pw.setPos(-vmax_ptr, 0)
self.vmax_line.setValue(vmax_data[-1])
# self.vmax_line.setValue(vmax_data[-1])
# a_data = self.radar.ts_a.data
# a_ptr = self.radar.ts_a.head_ptr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment