Browse Source

first ver of step counter method, may be some unstable work

master
Никита 7 years ago
parent
commit
ed1512726f
  1. 40
      src/main.cpp

40
src/main.cpp

@ -7,14 +7,13 @@
#include <WebSocketsServer.h> #include <WebSocketsServer.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include "CpuLoad.h" #include "CpuLoad.h"
#include <Ticker.h>
#include "arduinoFFT.h" #include "arduinoFFT.h"
bool fftMode = true;
arduinoFFT FFT = arduinoFFT(); arduinoFFT FFT = arduinoFFT();
const char *ssid = "LabWork_1"; const char *ssid = "LabWork_1";
ESP8266WebServer server(80); ESP8266WebServer server(80);
Sensor accelerometer = Sensor(); Sensor accelerometer = Sensor();
Graph graphAcc = Graph(256, 50); Graph graphAcc = Graph(256, 50);
@ -44,14 +43,8 @@ void handleAccelerometer()
const int arr_size = 7000; const int arr_size = 7000;
char *html_code = new char[arr_size]; char *html_code = new char[arr_size];
memset(html_code, '\0', sizeof(char) * arr_size); memset(html_code, '\0', sizeof(char) * arr_size);
bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0); bias += getHtml(HTML_BEGIN, *html_code, arr_size, 0);
// bias += getHtml(STYLE, *html_code, arr_size, bias);
// bias += getHtml(SCRIPT, *html_code, arr_size, bias);
// bias += getHtml(HTML_END, *html_code, arr_size, bias);
server.send(200, "text/html", html_code); server.send(200, "text/html", html_code);
delete[] html_code; delete[] html_code;
} }
@ -82,14 +75,11 @@ int lowFreqFilter(int inputValue, int lastFilteredValue, int alpha) {
void updateAccelerometer() void updateAccelerometer()
{ {
if ((millis() - accelerometer.lastUpdate) > (1000 / graphAcc.updateRate))
{
int filteredSignal = 0; int filteredSignal = 0;
int sourceSignal = analogRead(A0); int sourceSignal = analogRead(A0);
accelerometer.lastValue = map(sourceSignal, 0, 1023, graphAcc.size-1, 0); accelerometer.lastValue = map(sourceSignal, 0, 1023, graphAcc.size-1, 0);
if (graphAcc.counter != 0) { if (graphAcc.counter != 0) {
//filteredSignal = lowFreqFilter(accelerometer.lastValue, graphAcc.array[acc.graphCounter - 1], 0.5);
filteredSignal = graphAcc.array[graphAcc.counter - 1] + 0.5 * (accelerometer.lastValue - graphAcc.array[graphAcc.counter - 1]); filteredSignal = graphAcc.array[graphAcc.counter - 1] + 0.5 * (accelerometer.lastValue - graphAcc.array[graphAcc.counter - 1]);
} }
@ -108,6 +98,7 @@ void updateAccelerometer()
} }
graphAcc.array[graphAcc.counter] = filteredSignal; graphAcc.array[graphAcc.counter] = filteredSignal;
graphAcc.source[graphAcc.counter] = sourceSignal; graphAcc.source[graphAcc.counter] = sourceSignal;
graphAcc.peakFreqArray[graphAcc.counter] = peakFreq;
//start fft //start fft
for (int i = 0; i < graphAcc.size; i++) { for (int i = 0; i < graphAcc.size; i++) {
@ -123,13 +114,36 @@ void updateAccelerometer()
peakFreq = FFT.MajorPeak(vReal, graphAcc.size, 30); peakFreq = FFT.MajorPeak(vReal, graphAcc.size, 30);
for (int i = 0; i != 127; i++) {
graphAcc.peakFreqArray[i] = graphAcc.peakFreqArray[i + 1];
} }
graphAcc.peakFreqArray[127] = peakFreq;
accelerometer.lastUpdate = millis();
} }
} }
void stepUpdater () {
int sensorsUpdateRate = 15; // samples/sec
double slidingWindow = 1.2; //secs
double fftWindow = 8.5; //secs
for (int i = 0; i < sensorsUpdateRate * fftWindow; i = i + sensorsUpdateRate * slidingWindow) {
int amplCounter = 0;
int cycleCounter = 0;
double stepCounter = 0;
for (int j = i; (j < (sensorsUpdateRate * slidingWindow + i)) && (j < sensorsUpdateRate * fftWindow); j++) {
if ((0.7 < graphAcc.peakFreqArray[j]) && (graphAcc.peakFreqArray[j] < 2.2)) {
amplCounter++;
stepCounter = stepCounter + (graphAcc.peakFreqArray[j] / (sensorsUpdateRate * slidingWindow));
}
cycleCounter++;
}
if ((amplCounter / cycleCounter) > 0.7) {
steps = steps + (int)(stepCounter);
}
ESP.wdtFeed();
}
}
void handleNotFound() void handleNotFound()
{ {

Loading…
Cancel
Save