diff --git a/DopplerSignal/DopplerSignal.ino b/DopplerSignal/DopplerSignal.ino new file mode 100644 index 0000000..356288e --- /dev/null +++ b/DopplerSignal/DopplerSignal.ino @@ -0,0 +1,30 @@ + + +const int DOPPLER_0_PIN = A0; +const int DOPPLER_1_PIN = A1; +const int MEAN_SIZE = 10; +int gDoppler0 = 0; // value read from the doppler 0 +int gDoppler1 = 0; // value read from the doppler 1 +int gSum0 = 0; +int gSum1 = 0; + +void setup() { + Serial.begin(115200); +} + +void loop() { + gSum0 = 0; + gSum1 = 0; + for (int i = 0; i < MEAN_SIZE; i++){ + gDoppler0 = analogRead(DOPPLER_0_PIN); + gDoppler1 = analogRead(DOPPLER_1_PIN); + gSum0 += gDoppler0; + gSum1 += gDoppler1; + delay(1); + } + + // print the results to the Serial Monitor: + Serial.print((float)gSum0 / MEAN_SIZE); + Serial.print(","); + Serial.println((float)gSum1 / MEAN_SIZE); +} diff --git a/measurement.py b/measurement.py index 58984c2..277b9df 100644 --- a/measurement.py +++ b/measurement.py @@ -13,12 +13,15 @@ class DataWorker(threading.Thread): - def __init__(self, out_filename): + def __init__(self, out_filename=""): threading.Thread.__init__(self) self._running = False self._start_time = 0 - self._f = open(out_filename, "w", newline="") - self._writer = csv.writer(self._f) + self._f = None + self._writer = None + if out_filename: + self._f = open(out_filename, "w", newline="") + self._writer = csv.writer(self._f) @abstractmethod def preprocess(self): @@ -41,7 +44,8 @@ measurements = self.read() current_time = time.perf_counter() - self._start_time measurements.insert(0, current_time) - self._writer.writerow(measurements) + if self._writer: + self._writer.writerow(measurements) if len(measurements) == self._cols: self._data = np.vstack([self._data, measurements]) # print(measurements) @@ -50,7 +54,8 @@ self._running = False self.join(1.0) self.postprocess() - self._f.close() + if self._f: + self._f.close() self._data = self._data[1:, :] @@ -66,7 +71,8 @@ def preprocess(self): self._gdx.start(50) - self._writer.writerow(["time", "force"]) + if self._writer: + self._writer.writerow(["time", "force"]) def read(self): return self._gdx.read() @@ -84,7 +90,8 @@ print("Seiral port connected on ", port) def preprocess(self): - self._writer.writerow(["time", "IF-I", "IF-Q"]) + if self._writer: + self._writer.writerow(["time", "IF-I", "IF-Q"]) def read(self): if not self._serial.is_open: @@ -107,8 +114,8 @@ if len(ports) < 1: print("Can't find serial port") sys.exit() - serial_worker = SerialWorker("Doppler.csv", ports[0].device) - godirect_worker = GoDirectWorker("RespBand.csv") + serial_worker = SerialWorker("", ports[0].device) + godirect_worker = GoDirectWorker("") # Launch worker threads and start measurements serial_worker.start() @@ -116,7 +123,7 @@ # Wait for stop print("measurement start.") - recode_dulation = 15 # sec + recode_dulation = 2 # sec for i in range(recode_dulation): time.sleep(1) print(i + 1, "/", recode_dulation, "sec")