worked on synthetic sensors

worked on grid-walker
minor changes/fixes/improvements
This commit is contained in:
k-a-z-u
2017-10-18 16:54:57 +02:00
parent 72f083d32a
commit 3e31f6da53
8 changed files with 522 additions and 71 deletions

View File

@@ -1,11 +1,16 @@
#ifndef SYNTHETICSTEPS_H
#define SYNTHETICSTEPS_H
#include "../sensors/imu/AccelerometerData.h"
#include "SyntheticWalker.h"
#include "../sensors/imu/AccelerometerData.h"
#include "../math/distribution/Normal.h"
/** fakes accelerometer-data based on synthetic walking data */
/**
* fakes accelerometer-data
* based on synthetic walking data
*/
class SyntheticSteps : SyntheticWalker::Listener {
public:
@@ -25,9 +30,14 @@ private:
float lastStepAtDistance = 0;
Distribution::Normal<float> dX = Distribution::Normal<float>(0, 1);
Distribution::Normal<float> dY = Distribution::Normal<float>(0, 1);
Distribution::Normal<float> dZ = Distribution::Normal<float>(0, 1);
Timestamp refStepPattern;
Interpolator<Timestamp, AccelerometerData> stepPattern;
Distribution::Normal<float> dX = Distribution::Normal<float>(0, 0.2);
Distribution::Normal<float> dY = Distribution::Normal<float>(0, 0.3);
Distribution::Normal<float> dZ = Distribution::Normal<float>(0, 0.4);
int stepPatternPos = -1;
std::vector<Listener*> listeners;
@@ -35,9 +45,33 @@ public:
/** ctor with the walker to follow */
SyntheticSteps(SyntheticWalker* walker) {
walker->addListener(this);
dX.setSeed(1);
dY.setSeed(3);
dZ.setSeed(5);
// build the step-pattern (how does a step look-like on the accelerometer)
// TODO: switch to MS?! use interpolator?
// int duration_ms = 350;
// for (int i = 0; i < duration_ms; i += 10) {
// float z = std::sin(i*M_PI*2/duration_ms) * 3.0;
// if (z < 0) {z *= 0.75;} // less pronounced in the negative part
// float y = std::cos(i*M_PI*2/duration_ms) * 0.5;
// const float x = dO.draw();
// z += dO.draw()*2;
// y += dO.draw();
// AccelerometerData acc(x,y,z);
// stepPattern.add(Timestamp::fromMS(i), acc);
// }
stepPattern.add(Timestamp::fromMS(0), AccelerometerData(0, 0, 0));
stepPattern.add(Timestamp::fromMS(250), AccelerometerData(0, 0.6, 3));
stepPattern.add(Timestamp::fromMS(350), AccelerometerData(0.5, -0.6, -1.8));
stepPattern.add(Timestamp::fromMS(450), AccelerometerData(0, 0, 0));
}
/** attach a listener to this provider */
void addListener(Listener* l) {
this->listeners.push_back(l);
}
@@ -47,15 +81,32 @@ protected:
void onWalk(const Timestamp walkedTime, float walkedDistance, const Point3 curPos) override {
(void) curPos;
const float nextStepAt = (lastStepAtDistance + stepSize_m);
// 1st, start with random noise on the accelerometer
const float x = dX.draw();
const float y = dY.draw();
const float z = dZ.draw();
AccelerometerData acc(x, y, z);
const AccelerometerData base(0, 4, 9.7);
const AccelerometerData noise(x, y, z);
AccelerometerData acc = base + noise;
// is it time to inject a "step" into the accelerometer data?
if (walkedDistance > nextStepAt) {
lastStepAtDistance = walkedDistance;
refStepPattern = walkedTime;
}
// overlay the noise with a step-pattern (see ctor)
if (refStepPattern.ms() > 0) {
Timestamp curPatPos = walkedTime - refStepPattern;
if (curPatPos >= stepPattern.getMaxKey()) {
refStepPattern = Timestamp::fromMS(0);
} else {
const AccelerometerData step = stepPattern.get(curPatPos);
acc = base + noise*2.5f + step;
}
}
for (Listener* l : listeners) {l->onSyntheticStepData(walkedTime, acc);}