Compare commits
3 Commits
e3ed301252
...
22b899e723
Author | SHA1 | Date | |
---|---|---|---|
22b899e723 | |||
3ca48d11fe | |||
32c79ff47b |
@ -18,8 +18,7 @@ class SinProducer:
|
||||
buffer: CircBuffer,
|
||||
) -> None:
|
||||
self.buffer = buffer
|
||||
|
||||
# self.stopbutton = stopbutton
|
||||
self.stop = False
|
||||
|
||||
def produce_sin(
|
||||
self,
|
||||
@ -32,20 +31,27 @@ class SinProducer:
|
||||
log.debug("producing Sin")
|
||||
start_time = time.time()
|
||||
t = 0
|
||||
while time.time() - start_time < 20:
|
||||
while not self.stop:
|
||||
s = AMPLITUDE * np.sin(2 * np.pi * FREQUENCY * t)
|
||||
self.buffer.append(s)
|
||||
t += 1 / self.buffer.samplerate
|
||||
time.sleep(1 / self.buffer.samplerate)
|
||||
|
||||
end_time = time.time()
|
||||
|
||||
data = self.buffer.get_all()
|
||||
log.debug(data.shape[0])
|
||||
log.debug(data.shape[0] / self.buffer.samplerate)
|
||||
log.debug(f"duration sinus {end_time-start_time}")
|
||||
log.debug(f"Stimulation time {t}")
|
||||
# log.debug(data.shape[0])
|
||||
# log.debug(data.shape[0] / self.buffer.samplerate)
|
||||
# plt.plot(np.arange(data.size) / self.buffer.samplerate, data)
|
||||
# plt.show()
|
||||
|
||||
def stop_request(self):
|
||||
self.stop = True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
buf = CircBuffer(1_000_000, 1, samplerate=10000)
|
||||
buf = CircBuffer(1_000_000, 1, samplerate=10_000)
|
||||
pro_sin = SinProducer(buf)
|
||||
pro_sin.produce_sin()
|
||||
|
@ -78,14 +78,15 @@ class PyRelacs(QMainWindow):
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
|
||||
SAMPLERATE = 1000
|
||||
BUFFERSIZE = 1_000
|
||||
SAMPLERATE = 1_000
|
||||
BUFFERSIZE = 1_0000
|
||||
self.buffer = CircBuffer(size=BUFFERSIZE, samplerate=SAMPLERATE)
|
||||
# self.connect_dac()
|
||||
|
||||
# self.daq_producer = DaqProducer(self.buffer, self.daq_device, [1, 1])
|
||||
self.sin_producer = SinProducer(self.buffer)
|
||||
self.continously_plot = Continously(self.figure, self.buffer)
|
||||
self.continously_plot.plot_daq()
|
||||
|
||||
def create_actions(self):
|
||||
self._rlx_exitaction = QAction(QIcon(":/icons/exit.png"), "Exit", self)
|
||||
@ -125,7 +126,7 @@ class PyRelacs(QMainWindow):
|
||||
self._run_sinus_action = QAction(QIcon(":/icons/record.png"), "Sinus", self)
|
||||
self._run_sinus_action.triggered.connect(self.run_sinus)
|
||||
|
||||
self._stop_recording = QAction("Stop", self)
|
||||
self._stop_recording = QAction(QIcon(":/icons/stop.png"), "Stop", self)
|
||||
self._stop_recording.triggered.connect(self.stop_recording)
|
||||
|
||||
self.create_menu()
|
||||
@ -211,12 +212,19 @@ class PyRelacs(QMainWindow):
|
||||
sinus_pro.signals.progress.connect(self.progress_fn)
|
||||
self.threadpool.start(sinus_pro)
|
||||
|
||||
# time.sleep(0.05)
|
||||
self.continously_plot.plot_daq()
|
||||
# plot_daq = Worker(self.continously_plot.plot_daq)
|
||||
# plot_daq.signals.result.connect(self.print_output)
|
||||
# plot_daq.signals.finished.connect(self.thread_complete)
|
||||
# plot_daq.signals.progress.connect(self.progress_fn)
|
||||
# self.threadpool.start(plot_daq)
|
||||
|
||||
# self.continously_plot.plot_daq()
|
||||
|
||||
def stop_recording(self):
|
||||
self.add_to_textfield("pressed")
|
||||
self._stop_recording.setEnabled(False)
|
||||
self.sin_producer.stop_request()
|
||||
self.continously_plot.stop_plotting()
|
||||
|
||||
def connect_dac(self):
|
||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||
@ -257,6 +265,7 @@ class PyRelacs(QMainWindow):
|
||||
|
||||
def on_exit(self):
|
||||
log.info("exit button!")
|
||||
self.stop_recording()
|
||||
self.add_to_textfield("exiting")
|
||||
self.disconnect_dac()
|
||||
self.close()
|
||||
|
@ -19,49 +19,77 @@ class Continously:
|
||||
self.figure.setBackground("w")
|
||||
self.daq_plot = self.figure.addPlot(row=0, col=0)
|
||||
pen = pg.mkPen("red")
|
||||
self.time = np.zeros(self.buffer.size)
|
||||
self.data = np.zeros(self.buffer.size)
|
||||
log.debug(self.data.size)
|
||||
log.debug(self.time.size)
|
||||
# self.time = np.zeros(self.buffer.size)
|
||||
# self.data = np.zeros(self.buffer.size)
|
||||
self.line = self.daq_plot.plot(
|
||||
self.time,
|
||||
self.data,
|
||||
# self.time,
|
||||
[0],
|
||||
pen=pen,
|
||||
setCliptoView=True,
|
||||
symbol="o",
|
||||
)
|
||||
|
||||
while self.buffer.totalcount() < 4000:
|
||||
# self.item = 0
|
||||
# while self.buffer.totalcount() < 3_000_000:
|
||||
# log.debug(self.buffer.totalcount())
|
||||
# self.time = np.roll(self.time, -1)
|
||||
# self.data = np.roll(self.data, -1)
|
||||
# try:
|
||||
# item, time_index = self.buffer.get(self.item)
|
||||
# except IndexError:
|
||||
# item = 0
|
||||
# time_index = 0
|
||||
# self.time[-1] = time_index
|
||||
# self.data[-1] = item
|
||||
# self.line.setData(self.time, self.data)
|
||||
# self.item += 1
|
||||
|
||||
self.plot_index = 0
|
||||
self.CHUNK_PLOT = 1000
|
||||
self.timer = QTimer()
|
||||
self.timer.setInterval(200)
|
||||
self.timer.timeout.connect(self.update_plot)
|
||||
self.timer.start()
|
||||
|
||||
# self.update_plot()
|
||||
|
||||
def update_plot(self):
|
||||
log.debug(self.buffer.totalcount())
|
||||
|
||||
if self.buffer.totalcount() > self.CHUNK_PLOT:
|
||||
|
||||
log.debug(self.buffer.totalcount())
|
||||
self.time = np.roll(self.time, -1)
|
||||
self.data = np.roll(self.data, -1)
|
||||
try:
|
||||
item, time_index = self.buffer.get(self.buffer.write_index() - 1)
|
||||
# item, time_index = self.buffer.get(self.buffer.write_index() - 1)
|
||||
items = self.buffer.read(
|
||||
self.buffer.write_index() - self.CHUNK_PLOT, count=self.CHUNK_PLOT
|
||||
)
|
||||
# times = (np.arange(len(items)) / self.buffer.samplerate) + self.time[-1]
|
||||
|
||||
except IndexError:
|
||||
item = 0
|
||||
items = np.zeros(self.CHUNK_PLOT)
|
||||
times = np.zeros(self.CHUNK_PLOT)
|
||||
# log.debug("Stopping the timer")
|
||||
# self.timer.stop()
|
||||
time_index = 0
|
||||
self.time[-1] = time_index
|
||||
self.data[-1] = item
|
||||
self.line.setData(self.time, self.data)
|
||||
log.debug("No Data Available")
|
||||
# self.time = np.roll(self.time, -len(items))
|
||||
# self.data = np.roll(self.data, -len(items))
|
||||
#
|
||||
# # self.time[-len(times) :] = times
|
||||
# self.data[-len(items) :] = items
|
||||
|
||||
# self.timer = QTimer()
|
||||
# self.timer.setInterval(1)
|
||||
# self.timer.timeout.connect(self.update_plot)
|
||||
# self.timer.start()
|
||||
self.line.setData(
|
||||
# self.time,
|
||||
items,
|
||||
)
|
||||
self.plot_index += len(items)
|
||||
else:
|
||||
# self.timer.stop()
|
||||
# embed()
|
||||
# exit()
|
||||
pass
|
||||
|
||||
# self.update_plot()
|
||||
#
|
||||
# def update_plot(self):
|
||||
# log.debug(self.buffer.totalcount())
|
||||
# while self.buffer.totalcount() < 4000:
|
||||
# log.debug(self.buffer.totalcount())
|
||||
# self.time = np.roll(self.time, -1)
|
||||
# self.data = np.roll(self.data, -1)
|
||||
# try:
|
||||
# item, time_index = self.buffer.get(self.buffer.write_index() - 1)
|
||||
# except IndexError:
|
||||
# item = 0
|
||||
# time_index = 0
|
||||
# self.time[-1] = time_index
|
||||
# self.data[-1] = item
|
||||
# self.line.setData(self.time, self.data)
|
||||
def stop_plotting(self):
|
||||
self.timer.stop()
|
||||
|
Loading…
Reference in New Issue
Block a user