Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final version of the real-time receiver #5

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
cb7357d
Remove redundant files.
Dimitar2000 Jun 15, 2022
3ea1663
Receiver: Refactor into Finite State Machine.
Dimitar2000 Jun 16, 2022
cb3922a
Receiver: Add LI regulator.
Dimitar2000 Jun 16, 2022
5cd32b5
Receiver: Use LI regulator.
Dimitar2000 Jun 16, 2022
2261e9b
Receiver: Divide threshold adjustment into 2 states.
Dimitar2000 Jun 16, 2022
e56c106
Receiver: Refactor - remove usage of pointer buffers.
Dimitar2000 Jun 16, 2022
112a84e
Receiver: Comments and renaming.
Dimitar2000 Jun 16, 2022
dcd27ba
Receiver: Document FSM.
Dimitar2000 Jun 16, 2022
094ae42
Add timer restart.
Dimitar2000 Jun 16, 2022
6d5c5a5
BugFix: Reset counter.
Dimitar2000 Jun 16, 2022
4703d5c
BugFix: Actually run timer.
Dimitar2000 Jun 17, 2022
cacd7c2
Calibration: Include only once.
Dimitar2000 Jun 17, 2022
3366435
Receiver: Use hardware adjustment.
Dimitar2000 Jun 17, 2022
8682f60
Receiver: Add comments.
Dimitar2000 Jun 17, 2022
1567586
Receiver: Refactor GDDiodeReader and others.
Dimitar2000 Jun 17, 2022
59f0b29
Receiver: Refactor - extract hardware adjustment in a function.
Dimitar2000 Jun 17, 2022
128573a
Receiver: Refactor - use externally passed functions for hardware adj…
Dimitar2000 Jun 17, 2022
d033134
Receiver: Add trimming after FFT to real-time receiver.
Dimitar2000 Jun 19, 2022
a3887f8
BugFix: Change fn invoke parameter.
Dimitar2000 Jun 21, 2022
3f3a397
Receiver: Add feature selection macro that disables hardware adjustment.
Dimitar2000 Jun 21, 2022
9b54760
Receiver: Add README.
Dimitar2000 Jun 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/diode_calibration/diode_calibration.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#ifndef CALIBRATION
#define CALIBRATION

#include "Arduino.h"
#include <vector>
#include <algorithm>
Expand Down Expand Up @@ -186,4 +189,6 @@ class LightIntensityRegulator {
}
return read_sum / window;
}
};
};

#endif
25 changes: 20 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,37 @@ void plotter() {

void setup() {
Serial.begin(9600);
//while(!Serial);
while(!Serial);

// Start visualization thread. Comment out if no visualization/data_collection is required
plotter_thread.start(plotter);
// plotter_thread.start(plotter);

// Setup the lightintensity regulator.
regulator = new LightIntensityRegulator();

//tensorflowSetup();
//receiverSetup();
// tensorflowSetup();
receiverSetup([]{regulator->resistorDown();}, []{regulator->resistorUp();});

// pinMode(A0, ANALOG);
// pinMode(A1, INPUT);
// pinMode(A2, INPUT);
}


void loop() {


//receiverLoop();
// int r0 = analogRead(A0);
// int r1 = analogRead(A1);
// int r2 = analogRead(A2);

// Serial.print(r0);
// Serial.print(", ");
// Serial.print(r1);
// Serial.print(", ");
// Serial.println(r2);
// delay(10);

receiverLoop();

}
10 changes: 10 additions & 0 deletions src/receiver/GRDiodeReader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include<inttypes.h>

#include "receiver-parameters.h"

/**
* @brief A class abstracting the reading of sensors and storing their input.
*
Expand All @@ -12,4 +14,12 @@ class GRDiodeReader {
void read(uint8_t d, uint16_t * dest) {
*dest = analogRead(d);
}

template<int size>
void readAll(uint16_t dest[NUM_PDs][size],int index) {
for (size_t i = 0; i < NUM_PDs; i++)
{
this->read(pds[i], &dest[i][index]);
}
}
};
21 changes: 18 additions & 3 deletions src/receiver/GRPreprocessingPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class GRPreprocessingPipeline {
bool trimmed = false;
int trimCount = 0;
int i = gestureSignalLength;
while(i-- >= 0 && trimCount++ < DETECTION_END_WINDOW_LENGTH * DETECTION_END_WINDOW_TRIM) {
while(i-- >= 0) {
bool zero = true;
for (size_t di = 0; di < NUM_PDs; di++)
zero = zero && (rawData[di][i] <= 1);
zero = zero && (rawData[di][i] == 0);

if (zero) {
trimmed = true;
Expand All @@ -72,7 +72,7 @@ class GRPreprocessingPipeline {
for (size_t i = 0; i < NUM_PDs; i++)
{
fftFilter[i].ZeroImag();
fftFilter[i].Filter(rawData[i], gestureSignalLength, 5, 1000 / READ_PERIOD);
fftFilter[i].Filter(rawData[i], gestureSignalLength, 10, 1000 / READ_PERIOD);
fftFilter[i].MoveDataToBufferF(photodiodeDataFFTFiltered[i]);
}

Expand All @@ -81,6 +81,21 @@ class GRPreprocessingPipeline {
FOR(di, i, NUM_PDs, gestureSignalLength,
photodiodeDataFFTFiltered[di][i] = max(0, photodiodeDataFFTFiltered[di][i] - thresholds[di] * CUTT_OFF_THRESHOLD_COEFF_POST_FFT);
);

trimmed = false;
trimCount = 0;
i = gestureSignalLength;
while(i-- >= 0) {
bool zero = true;
for (size_t di = 0; di < NUM_PDs; di++)
zero = zero && (photodiodeDataFFTFiltered[di][i] == 0);

if (zero) {
trimmed = true;
gestureSignalLength--;
}
}
if(trimmed) gestureSignalLength++;

#ifdef PLOT_RECEIVER
sendSignal(photodiodeDataFFTFiltered, FFT_SIGNAL_LENGTH);
Expand Down
32 changes: 32 additions & 0 deletions src/receiver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Real-time Photodiode (PD) - based Gesture Receiver

## Directory Structure
- [receiver.hpp](receiver.hpp) : receiver main file, containing its FSM architecture

- [receiver-parameters.h](receiver-parameters.h) : various macros and photodiode pins setups for use by the rest of the files

- [receiver-util.h](receiver-util.h) : auxiliary utility macros and functions

- [GRDiodeReader.h](GRDiodeReader.h) : abstraction over PD reading. Used in [receiver.hpp](receiver.hpp).

- [GREdgeDetector.h](GREdgeDetector.h) : abstraction over checking for gesture start and end using an adjustable threshold. Used in [receiver.hpp](receiver.hpp).

- [GRPreprocessingPipeline.h](GRPreprocessingPipeline.h) + [pipeline-stages/](pipeline-stages/) : pipeline for noise reduction and normalisation of gesture data. Used in [receiver.hpp](receiver.hpp).

- [plotting/](plotting/) : auxiliary files for plotting the output of the preprocessing pipeline stages.


## Plotting the receiver pipeline stages' outputs:

* Go to `receiver-parameters.h` and uncomment the `PLOT_RECEIVER` macro.
* After starting the system on the Arduino connected via a serial port, run the Python script [plotter.py](plotting/plotter.py).

## Debugging the receiver main FSM:

* Go to `receiver-parameters.h` and uncomment the `DEBUG_RECEIVER` macro.
* Start the system on the Arduino connected via a serial port and monitor the port input.

## Turning off hardware adjustment and only using software threshold adjustment

* Go to `receiver-parameters.h` and uncomment the `NO_HARDWARE_ADJUSTMENT` macro.

2 changes: 2 additions & 0 deletions src/receiver/receiver-parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define GESTURE_BUFFER_LENGTH 500
// Buffer for threshold adjustment
#define THRESHOLD_ADJ_BUFFER_LENGTH 100
#define THRESHOLD_UPD_BUFFER_LENGTH 20

// Sampling period and minimum expected gesture duration
#define READ_PERIOD 10
Expand Down Expand Up @@ -53,6 +54,7 @@
};

// #define DEBUG_RECEIVER
// #define NO_HARDWARE_ADJUSTMENT
// #define PLOT_RECEIVER

#endif
Expand Down
Loading