worked on grid-walking

worked on grid-generation
added helper library for nav-meshes
started working on nav meshes
This commit is contained in:
2018-01-08 20:55:50 +01:00
parent c346b7f222
commit ca6fed5371
33 changed files with 12991 additions and 1913 deletions

View File

@@ -5,7 +5,7 @@
#include "../../../misc/Time.h"
#include "../../../math/Interpolator.h"
#include"../../../sensors/pressure/ActivityButterPressure.h"
#include"../../../sensors/activity/ActivityButterPressure.h"
#include <KLib/misc/gnuplot/Gnuplot.h>
#include <KLib/misc/gnuplot/GnuplotPlot.h>
@@ -23,234 +23,234 @@
TEST(Butterworth, offlineSinus) {
//input data
std::minstd_rand gen;
std::uniform_real_distribution<double> noise (-0.1, +0.1);
//input data
std::minstd_rand gen;
std::uniform_real_distribution<double> noise (-0.1, +0.1);
int size = 1100; //Fs
double* input = new double[size];
double* output = new double[size];
int size = 1100; //Fs
double* input = new double[size];
double* output = new double[size];
// 17.5hz sin signal with random noise [-0.1, 0.1]
for( int i=0; i < size; ++i ){
input[i] = sin(0.1 * i) + noise(gen);
}
// 17.5hz sin signal with random noise [-0.1, 0.1]
for( int i=0; i < size; ++i ){
input[i] = sin(0.1 * i) + noise(gen);
}
//butterworth
Filter::ButterworthLP<double> butter(size,20,5);
butter.stepInitialization(0);
butter.filter(input, output, size, 0, true);
//butterworth
Filter::ButterworthLP<double> butter(size,20,5);
butter.stepInitialization(0);
butter.filter(input, output, size, 0, true);
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
for(int i=0; i < size-1; ++i){
for(int i=0; i < size-1; ++i){
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesOutput.getStroke().getColor().setHexStr("#00FF00");
plot.add(&linesInput);
plot.add(&linesOutput);
plot.add(&linesInput);
plot.add(&linesOutput);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
sleep(10);
sleep(10);
}
TEST(Butterworth, onlineSinus) {
int size = 1100; //Fs
double* input = new double[size];
double* output = new double[size];
int size = 1100; //Fs
double* input = new double[size];
double* output = new double[size];
Filter::ButterworthLP<double> butter(size,20,5);
butter.stepInitialization(0);
Filter::ButterworthLP<double> butter(size,20,5);
butter.stepInitialization(0);
//input data
std::minstd_rand gen;
std::uniform_real_distribution<double> noise (-0.1, +0.1);
//input data
std::minstd_rand gen;
std::uniform_real_distribution<double> noise (-0.1, +0.1);
// 17.5hz sin signal with random noise [-0.1, 0.1]
for( int i=0; i < size; ++i ){
input[i] = sin(0.1 * i) + noise(gen);
// 17.5hz sin signal with random noise [-0.1, 0.1]
for( int i=0; i < size; ++i ){
input[i] = sin(0.1 * i) + noise(gen);
output[i] = butter.process(input[i]);
}
output[i] = butter.process(input[i]);
}
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
for(int i=0; i < size-1; ++i){
for(int i=0; i < size-1; ++i){
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesOutput.getStroke().getColor().setHexStr("#00FF00");
plot.add(&linesInput);
plot.add(&linesOutput);
plot.add(&linesInput);
plot.add(&linesOutput);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
sleep(1);
sleep(1);
}
TEST(Butterworth, offlineOctaveBaro) {
double* input = new double[100000];
double* output = new double[100000];
double* input = new double[100000];
double* output = new double[100000];
Interpolator<int, double> interp;
Interpolator<int, double> interp;
//read file
std::string line;
std::string filename = getDataFile("baro/logfile_UAH_R1_S4_baro.dat");
std::ifstream infile(filename);
//read file
std::string line;
std::string filename = getDataFile("baro/logfile_UAH_R1_S4_baro.dat");
std::ifstream infile(filename);
int counter = 0;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
int counter = 0;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (iss >> ts >> value) {
while (iss >> ts >> value) {
interp.add(ts, value);
interp.add(ts, value);
while(interp.getMaxKey() > counter*20 ){
double interpValue = interp.get(counter*20);
while(interp.getMaxKey() > counter*20 ){
double interpValue = interp.get(counter*20);
input[counter] = interpValue;
//std::cout << counter*20 << " " << interpValue << " i" << std::endl;
++counter;
}
input[counter] = interpValue;
//std::cout << counter*20 << " " << interpValue << " i" << std::endl;
++counter;
}
//std::cout << ts << " " << value << " r" << std::endl;
//std::cout << ts << " " << value << " r" << std::endl;
}
}
}
}
Filter::ButterworthLP<double> butter(50,0.2,2);
butter.filter(input, output, counter, 938.15, true);
Filter::ButterworthLP<double> butter(50,0.2,2);
butter.filter(input, output, counter, 938.15, true);
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
for(int i=0; i < counter-1; ++i){
for(int i=0; i < counter-1; ++i){
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesOutput.getStroke().getColor().setHexStr("#00FF00");
plot.add(&linesInput);
plot.add(&linesOutput);
plot.add(&linesInput);
plot.add(&linesOutput);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
sleep(1);
sleep(1);
}
TEST(Butterworth, onlineOctaveBaro) {
std::vector<double> input;
std::vector<double> output;
std::vector<double> input;
std::vector<double> output;
Interpolator<int, double> interp;
Interpolator<int, double> interp;
Filter::ButterworthLP<double> butter(50,0.02,2);
butter.stepInitialization(938.15);
Filter::ButterworthLP<double> butter(50,0.02,2);
butter.stepInitialization(938.15);
//read file
std::string line;
std::string filename = getDataFile("baro/logfile_UAH_R1_S4_baro.dat");
std::ifstream infile(filename);
//read file
std::string line;
std::string filename = getDataFile("baro/logfile_UAH_R1_S4_baro.dat");
std::ifstream infile(filename);
int counter = 1;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
int counter = 1;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (iss >> ts >> value) {
while (iss >> ts >> value) {
interp.add(ts, value);
interp.add(ts, value);
while(interp.getMaxKey() > counter*20 ){
double interpValue = interp.get(counter*20);
while(interp.getMaxKey() > counter*20 ){
double interpValue = interp.get(counter*20);
//std::cout << counter*20 << " " << interpValue << " i" << std::endl;
//std::cout << counter*20 << " " << interpValue << " i" << std::endl;
input.push_back(interpValue);
input.push_back(interpValue);
output.push_back(butter.process(interpValue));
output.push_back(butter.process(interpValue));
++counter;
}
++counter;
}
//std::cout << ts << " " << value << " r" << std::endl;
//std::cout << ts << " " << value << " r" << std::endl;
}
}
}
}
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
K::Gnuplot gp;
K::GnuplotPlot plot;
K::GnuplotPlotElementLines linesInput;
K::GnuplotPlotElementLines linesOutput;
for(int i=0; i < input.size()-1; ++i){
for(int i=0; i < input.size()-1; ++i){
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 input_p1(i, input[i]);
K::GnuplotPoint2 input_p2(i+1, input[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
K::GnuplotPoint2 output_p1(i, output[i]);
K::GnuplotPoint2 output_p2(i+1, output[i+1]);
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesInput.addSegment(input_p1, input_p2);
linesOutput.addSegment(output_p1, output_p2);
}
linesOutput.getStroke().getColor().setHexStr("#00FF00");
plot.add(&linesInput);
plot.add(&linesOutput);
plot.add(&linesInput);
plot.add(&linesOutput);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
sleep(1);
sleep(1);
}

View File

@@ -0,0 +1,38 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../navMesh/NavMeshFactory.h"
TEST(NavMeshFactory, build1) {
Floorplan::IndoorMap map;
Floorplan::Floor floor; map.floors.push_back(&floor); floor.atHeight = 0; floor.height = 3;
Floorplan::FloorOutlinePolygon outline; floor.outline.push_back(&outline);
outline.poly.points.push_back(Point2(0,0));
outline.poly.points.push_back(Point2(10,0));
outline.poly.points.push_back(Point2(10,10));
outline.poly.points.push_back(Point2(0,10));
outline.outdoor = false;
outline.method = Floorplan::OutlineMethod::ADD;
NavMesh<NavMeshTriangle> nm;
NavMeshFactory<NavMeshTriangle> fac(&nm);
fac.build(&map);
ASSERT_NEAR(0, nm.getBBox().getMin().x, 0.5);
ASSERT_NEAR(0, nm.getBBox().getMin().y, 0.5);
ASSERT_NEAR(0, nm.getBBox().getMin().z, 0.5);
ASSERT_NEAR(10, nm.getBBox().getMax().x, 0.5);
ASSERT_NEAR(10, nm.getBBox().getMax().y, 0.5);
ASSERT_NEAR( 0, nm.getBBox().getMax().z, 0.5);
ASSERT_EQ(2, nm.getNumTriangles());
ASSERT_EQ(nm.getNeighbor(0,0), nm[1]);
ASSERT_EQ(nm.getNeighbor(1,0), nm[0]);
}
#endif

View File

@@ -0,0 +1,35 @@
#ifdef WITH_TESTS
#include "../Tests.h"
#include "../../navMesh/NavMeshTriangle.h"
TEST(NavMeshTriangle, contains) {
NavMeshTriangle t1(Point3(0,0,0), Point3(1,0,0), Point3(0,1,0));
ASSERT_TRUE(t1.contains(Point3(0,0,0)));
ASSERT_TRUE(t1.contains(Point3(1,0,0)));
ASSERT_TRUE(t1.contains(Point3(0,1,0)));
ASSERT_TRUE(t1.contains(Point3(0.5,0.5,0)));
ASSERT_FALSE(t1.contains(Point3(0.501,0.5,0)));
ASSERT_FALSE(t1.contains(Point3(0.5,0.501,0)));
ASSERT_FALSE(t1.contains(Point3(1,1,0)));
}
TEST(NavMeshTriangle, area) {
NavMeshTriangle t1(Point3(0,0,0), Point3(1,0,0), Point3(0,1,0));
ASSERT_NEAR(0.5, t1.getArea(), 0.0001);
NavMeshTriangle t2(Point3(0,0,9), Point3(1,0,9), Point3(0,1,9));
ASSERT_NEAR(0.5, t2.getArea(), 0.0001);
}
#endif

View File

@@ -1,4 +1,4 @@
#ifdef WITH_TESTS
#ifdef TODO_________WITH_TESTS
#include "../../Tests.h"
@@ -9,190 +9,190 @@
/** visualize the motionAxis */
TEST(MotionDetection, motionAxis) {
MotionDetection md;
MotionDetection md;
//plot.gp << "set arrow 919 from " << tt.pos.x << "," << tt.pos.y << "," << tt.pos.z << " to "<< tt.pos.x << "," << tt.pos.y << "," << tt.pos.z+1 << "lw 3\n";
//plot.gp << "set arrow 919 from " << tt.pos.x << "," << tt.pos.y << "," << tt.pos.z << " to "<< tt.pos.x << "," << tt.pos.y << "," << tt.pos.z+1 << "lw 3\n";
//Walking with smartphone straight and always parallel to motion axis
//std::string filename = getDataFile("motion/straight_potrait.csv");
//Walking with smartphone straight and always parallel to motion axis
//std::string filename = getDataFile("motion/straight_potrait.csv");
//straight_landscape_left/right: walking ~40 sec straight and changing every 5 seconds the mode. started with potrait. landscape routed either to left or right.
std::string filename = getDataFile("motion/straight_landscape_left.csv");
//std::string filename = getDataFile("motion/straight_landscape_right.csv");
//straight_landscape_left/right: walking ~40 sec straight and changing every 5 seconds the mode. started with potrait. landscape routed either to left or right.
std::string filename = getDataFile("motion/straight_landscape_left.csv");
//std::string filename = getDataFile("motion/straight_landscape_right.csv");
//straight_inturn_landscape: walked straight made a left turn and change the phone to landscape mode during the turn-phase
//std::string filename = getDataFile("motion/straight_inturn_landscape.csv");
//straight_inturn_landscape: walked straight made a left turn and change the phone to landscape mode during the turn-phase
//std::string filename = getDataFile("motion/straight_inturn_landscape.csv");
//rounds_potrait: walked 3 rounds holding the phone in potrait mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait.csv");
//rounds_potrait: walked 3 rounds holding the phone in potrait mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait.csv");
//round_landscape: walked 3 rounds holding the phone in landscape mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_landscape.csv");
//round_landscape: walked 3 rounds holding the phone in landscape mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_landscape.csv");
//round potrait_to_landscape: walked 1 round with potrait, 1 with landscape and again potrait. the mode was change while walking straight not in a turn. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait_to_landscape.csv");
//round potrait_to_landscape: walked 1 round with potrait, 1 with landscape and again potrait. the mode was change while walking straight not in a turn. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait_to_landscape.csv");
//rounds_pocket: had the phone in my jeans pocket screen pointed at my body and the phone was headfirst. pulled it shortly out after 2 rounds and rotated the phone 180° z-wise (screen not showing at me)
//std::string filename = getDataFile("motion/rounds_pocket.csv");
//rounds_pocket: had the phone in my jeans pocket screen pointed at my body and the phone was headfirst. pulled it shortly out after 2 rounds and rotated the phone 180° z-wise (screen not showing at me)
//std::string filename = getDataFile("motion/rounds_pocket.csv");
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
//std::string filename = getDataFile("motion/table_flat.csv");
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
//std::string filename = getDataFile("motion/table_flat.csv");
Offline::FileReader fr(filename);
K::Gnuplot gp;
K::GnuplotPlot plot;
K::Gnuplot gp;
K::GnuplotPlot plot;
gp << "set xrange[-1:1]\n set yrange[-1:1]\n";
gp << "set xrange[-1:1]\n set yrange[-1:1]\n";
Eigen::Vector2f curVec;
float motionAxisAngleRad;
Timestamp ts;
Timestamp lastTs;
Eigen::Vector2f curVec;
float motionAxisAngleRad;
Timestamp ts;
Timestamp lastTs;
//calc motion axis
//calc motion axis
for (const Offline::Entry& e : fr.getEntries()) {
ts = Timestamp::fromMS(e.ts);
ts = Timestamp::fromMS(e.ts);
if (e.type == Offline::Sensor::LIN_ACC) {
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
} else if (e.type == Offline::Sensor::GRAVITY) {
md.addGravity(ts, fr.getGravity()[e.idx].data);
curVec = md.getCurrentMotionAxis();
motionAxisAngleRad = md.getMotionChangeInRad();
}
md.addGravity(ts, fr.getGravity()[e.idx].data);
curVec = md.getCurrentMotionAxis();
motionAxisAngleRad = md.getMotionChangeInRad();
}
// start with the first available timestamp
if (lastTs.isZero()) {lastTs = ts;}
// start with the first available timestamp
if (lastTs.isZero()) {lastTs = ts;}
if(ts - lastTs > Timestamp::fromMS(500)) {
if(ts - lastTs > Timestamp::fromMS(500)) {
lastTs = ts;
lastTs = ts;
K::GnuplotPoint2 raw_p1(0, 0);
K::GnuplotPoint2 raw_p2(curVec(0,0), curVec(1,0));
K::GnuplotPlotElementLines motionLines;
motionLines.addSegment(raw_p1, raw_p2);
plot.add(&motionLines);
K::GnuplotPoint2 raw_p1(0, 0);
K::GnuplotPoint2 raw_p2(curVec(0,0), curVec(1,0));
K::GnuplotPlotElementLines motionLines;
motionLines.addSegment(raw_p1, raw_p2);
plot.add(&motionLines);
gp << "set label 111 ' Angle: " << motionAxisAngleRad * 180 / 3.14159 << "' at screen 0.1,0.1\n";
gp << "set label 111 ' Angle: " << motionAxisAngleRad * 180 / 3.14159 << "' at screen 0.1,0.1\n";
gp.draw(plot);
gp.flush();
//usleep(5000*33);
}
}
gp.draw(plot);
gp.flush();
//usleep(5000*33);
}
}
//was passiert bei grenzwerten. 90° oder sowas.
//wie stabil ist die motion axis eigentlich?
//erkenn wir aktuell überhaupt einen turn, wenn wir das telefon drehen?
//wie hilft mir die motion achse? über einen faktor? in welchem verhältnis stehen motion axis und heading?
//was passiert bei grenzwerten. 90° oder sowas.
//wie stabil ist die motion axis eigentlich?
//erkenn wir aktuell überhaupt einen turn, wenn wir das telefon drehen?
//wie hilft mir die motion achse? über einen faktor? in welchem verhältnis stehen motion axis und heading?
}
/** comparing motionAngle and turnAngle */
TEST(MotionDetection, motionAngle) {
MotionDetection md;
TurnDetection td;
MotionDetection md;
TurnDetection td;
//plot.gp << "set arrow 919 from " << tt.pos.x << "," << tt.pos.y << "," << tt.pos.z << " to "<< tt.pos.x << "," << tt.pos.y << "," << tt.pos.z+1 << "lw 3\n";
//plot.gp << "set arrow 919 from " << tt.pos.x << "," << tt.pos.y << "," << tt.pos.z << " to "<< tt.pos.x << "," << tt.pos.y << "," << tt.pos.z+1 << "lw 3\n";
//Walking with smartphone straight and always parallel to motion axis
std::string filename = getDataFile("motion/straight_potrait.csv");
//Walking with smartphone straight and always parallel to motion axis
std::string filename = getDataFile("motion/straight_potrait.csv");
//straight_landscape_left/right: walking ~40 sec straight and changing every 5 seconds the mode. started with potrait. landscape routed either to left or right.
//std::string filename = getDataFile("motion/straight_landscape_left.csv");
//std::string filename = getDataFile("motion/straight_landscape_right.csv");
//straight_landscape_left/right: walking ~40 sec straight and changing every 5 seconds the mode. started with potrait. landscape routed either to left or right.
//std::string filename = getDataFile("motion/straight_landscape_left.csv");
//std::string filename = getDataFile("motion/straight_landscape_right.csv");
//straight_inturn_landscape: walked straight made a left turn and change the phone to landscape mode during the turn-phase
//std::string filename = getDataFile("motion/straight_inturn_landscape.csv");
//straight_inturn_landscape: walked straight made a left turn and change the phone to landscape mode during the turn-phase
//std::string filename = getDataFile("motion/straight_inturn_landscape.csv");
//rounds_potrait: walked 3 rounds holding the phone in potrait mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait.csv");
//rounds_potrait: walked 3 rounds holding the phone in potrait mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait.csv");
//round_landscape: walked 3 rounds holding the phone in landscape mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_landscape.csv");
//round_landscape: walked 3 rounds holding the phone in landscape mode. always making left turns.
//std::string filename = getDataFile("motion/rounds_landscape.csv");
//round potrait_to_landscape: walked 1 round with potrait, 1 with landscape and again potrait. the mode was change while walking straight not in a turn. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait_to_landscape.csv");
//round potrait_to_landscape: walked 1 round with potrait, 1 with landscape and again potrait. the mode was change while walking straight not in a turn. always making left turns.
//std::string filename = getDataFile("motion/rounds_potrait_to_landscape.csv");
//rounds_pocket: had the phone in my jeans pocket screen pointed at my body and the phone was headfirst. pulled it shortly out after 2 rounds and rotated the phone 180° z-wise (screen not showing at me)
//std::string filename = getDataFile("motion/rounds_pocket.csv");
//rounds_pocket: had the phone in my jeans pocket screen pointed at my body and the phone was headfirst. pulled it shortly out after 2 rounds and rotated the phone 180° z-wise (screen not showing at me)
//std::string filename = getDataFile("motion/rounds_pocket.csv");
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
//std::string filename = getDataFile("motion/table_flat.csv");
//table_flat: phone was flat on the table and moved slowly forward/backward for 60 cm.
//std::string filename = getDataFile("motion/table_flat.csv");
Offline::FileReader fr(filename);
Timestamp ts;
Timestamp ts;
//save for later plotting
std::vector<float> delta_motionAngles;
std::vector<float> delta_turnAngles;
//save for later plotting
std::vector<float> delta_motionAngles;
std::vector<float> delta_turnAngles;
//calc motion axis
//calc motion axis
for (const Offline::Entry& e : fr.getEntries()) {
ts = Timestamp::fromMS(e.ts);
ts = Timestamp::fromMS(e.ts);
if (e.type == Offline::Sensor::LIN_ACC) {
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
md.addLinearAcceleration(ts, fr.getLinearAcceleration()[e.idx].data);
} else if (e.type == Offline::Sensor::GRAVITY) {
md.addGravity(ts, fr.getGravity()[e.idx].data);
delta_motionAngles.push_back(md.getMotionChangeInRad());
md.addGravity(ts, fr.getGravity()[e.idx].data);
delta_motionAngles.push_back(md.getMotionChangeInRad());
} else if (e.type == Offline::Sensor::ACC) {
const Offline::TS<AccelerometerData>& _acc = fr.getAccelerometer()[e.idx];
td.addAccelerometer(ts, _acc.data);
td.addAccelerometer(ts, _acc.data);
} else if (e.type == Offline::Sensor::GYRO) {
const Offline::TS<GyroscopeData>& _gyr = fr.getGyroscope()[e.idx];
delta_turnAngles.push_back(td.addGyroscope(ts, _gyr.data));
}
delta_turnAngles.push_back(td.addGyroscope(ts, _gyr.data));
}
}
}
//draw motion
static K::Gnuplot gpMotion;
K::GnuplotPlot plotMotion;
K::GnuplotPlotElementLines motionLines;
//draw motion
static K::Gnuplot gpMotion;
K::GnuplotPlot plotMotion;
K::GnuplotPlotElementLines motionLines;
for(int i = 0; i < delta_motionAngles.size() - 1; ++i){
for(int i = 0; i < delta_motionAngles.size() - 1; ++i){
K::GnuplotPoint2 raw_p1(i, delta_motionAngles[i]);
K::GnuplotPoint2 raw_p2(i + 1, delta_motionAngles[i+1]);
motionLines.addSegment(raw_p1, raw_p2);
K::GnuplotPoint2 raw_p1(i, delta_motionAngles[i]);
K::GnuplotPoint2 raw_p2(i + 1, delta_motionAngles[i+1]);
motionLines.addSegment(raw_p1, raw_p2);
}
}
gpMotion << "set title 'Motion Detection'\n";
plotMotion.add(&motionLines);
gpMotion.draw(plotMotion);
gpMotion.flush();
gpMotion << "set title 'Motion Detection'\n";
plotMotion.add(&motionLines);
gpMotion.draw(plotMotion);
gpMotion.flush();
//draw rotation
static K::Gnuplot gpTurn;
K::GnuplotPlot plotTurn;
K::GnuplotPlotElementLines turnLines;
//draw rotation
static K::Gnuplot gpTurn;
K::GnuplotPlot plotTurn;
K::GnuplotPlotElementLines turnLines;
for(int i = 0; i < delta_turnAngles.size() - 1; ++i){
for(int i = 0; i < delta_turnAngles.size() - 1; ++i){
K::GnuplotPoint2 raw_p1(i, delta_turnAngles[i]);
K::GnuplotPoint2 raw_p2(i + 1, delta_turnAngles[i+1]);
turnLines.addSegment(raw_p1, raw_p2);
}
K::GnuplotPoint2 raw_p1(i, delta_turnAngles[i]);
K::GnuplotPoint2 raw_p2(i + 1, delta_turnAngles[i+1]);
turnLines.addSegment(raw_p1, raw_p2);
}
gpTurn << "set title 'Turn Detection'\n";
plotTurn.add(&turnLines);
gpTurn.draw(plotTurn);
gpTurn.flush();
gpTurn << "set title 'Turn Detection'\n";
plotTurn.add(&turnLines);
gpTurn.draw(plotTurn);
gpTurn.flush();
sleep(1);
sleep(1);
}

View File

@@ -6,33 +6,33 @@
TEST(TurnDetection, rotationMatrix) {
Eigen::Vector3f dst; dst << 0, 0, 1;
Eigen::Vector3f src; src << 1, 1, 0; src.normalize();
Vector3 dst(0, 0, 1);
Vector3 src(1, 1, 0); src = src.normalized();
// get a matrix that rotates "src" into "dst"
Eigen::Matrix3f rot = TurnDetection::getRotationMatrix(src, dst);
Matrix3 rot = PoseDetection::getRotationMatrix(src, dst);
Eigen::Vector3f res = rot * src;
Vector3 res = rot * src;
ASSERT_NEAR(dst(0), res(0), 0.01);
ASSERT_NEAR(dst(1), res(1), 0.01);
ASSERT_NEAR(dst(2), res(2), 0.01);
ASSERT_NEAR(dst.x, res.x, 0.01);
ASSERT_NEAR(dst.y, res.y, 0.01);
ASSERT_NEAR(dst.z, res.z, 0.01);
}
TEST(TurnDetection, gyroRotate) {
Eigen::Vector3f zAxis; zAxis << 0, 0, 1;
Eigen::Vector3f acc; acc << 0, 7.0, 7.0;
Vector3 zAxis(0, 0, 1);
Vector3 acc(0, 7.0, 7.0);
Eigen::Matrix3f rot = TurnDetection::getRotationMatrix(acc, zAxis);
Matrix3 rot = PoseDetection::getRotationMatrix(acc, zAxis);
Eigen::Vector3f gyro; gyro << 0, 60, 60;
Vector3 gyro(0, 60, 60);
Eigen::Vector3f gyro2; gyro2 << 0, 0, 84;
Vector3 gyro2(0, 0, 84);
Eigen::Vector3f gyro3 = rot * gyro;
Vector3 gyro3 = rot * gyro;
ASSERT_NEAR(0, (gyro2-gyro3).norm(), 1.0);
@@ -41,10 +41,10 @@ TEST(TurnDetection, gyroRotate) {
TEST(TurnDetection, xx) {
Eigen::Vector3f dst; dst << 0, 0, 1;
Eigen::Vector3f src; src << 0.0, 2.9, -10.0; src.normalize(); // sample accelerometer readings
Vector3 dst(0, 0, 1);
Vector3 src(0.0, 2.9, -10.0); src = src.normalized(); // sample accelerometer readings
Eigen::Matrix3f rot = TurnDetection::getRotationMatrix(src, dst);
Matrix3 rot = PoseDetection::getRotationMatrix(src, dst);
// Eigen::Vector3f x; x << 1, 0, 0;
// Eigen::Vector3f z = src.normalized();
@@ -55,14 +55,14 @@ TEST(TurnDetection, xx) {
// rot.row(1) = y;
// rot.row(2) = z;
Eigen::Vector3f res = rot * src;
Vector3 res = rot * src;
// ASSERT_NEAR(dst(0), res(0), 0.01);
// ASSERT_NEAR(dst(1), res(1), 0.01);
// ASSERT_NEAR(dst(2), res(2), 0.01);
Eigen::Vector3f gyro; gyro << 0, 10, 30;
Vector3 gyro(0, 10, 30);
Eigen::Vector3f gyro2 = rot * gyro;
Vector3 gyro2 = rot * gyro;
int i = 0; (void) i;
}

View File

@@ -1,11 +1,11 @@
#ifdef WITH_TESTS
#ifdef TODO_______WITH_TESTS
#include "../../Tests.h"
#include "../../../sensors/pressure/RelativePressure.h"
#include "../../../sensors/pressure/PressureTendence.h"
#include "../../../sensors/pressure/ActivityButterPressure.h"
#include "../../../sensors/pressure/ActivityButterPressurePercent.h"
#include "../../../sensors/activity/ActivityButterPressure.h"
#include "../../../sensors/activity/ActivityButterPressurePercent.h"
#include <random>
@@ -79,7 +79,7 @@ TEST(Barometer, LIVE_tendence) {
}
sleep(1);
sleep(1);
}
@@ -115,7 +115,7 @@ TEST(Barometer, LIVE_tendence2) {
}
sleep(1);
sleep(1);
// tendence must be clear and smaller than the sigma
@@ -124,119 +124,119 @@ TEST(Barometer, LIVE_tendence2) {
}
TEST(Barometer, Activity) {
ActivityButterPressure act;
ActivityButterPressure act;
//read file
std::string line;
//read file
std::string line;
std::string filename = getDataFile("barometer/baro1.dat");
std::ifstream infile(filename);
std::ifstream infile(filename);
std::vector<ActivityButterPressure::History> actHist;
std::vector<ActivityButterPressure::History> rawHist;
std::vector<ActivityButterPressure::History> actHist;
std::vector<ActivityButterPressure::History> rawHist;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (iss >> ts >> value) {
ActivityButterPressure::Activity currentAct = act.add(Timestamp::fromMS(ts), BarometerData(value));
rawHist.push_back(ActivityButterPressure::History(Timestamp::fromMS(ts), BarometerData(value)));
actHist.push_back(ActivityButterPressure::History(Timestamp::fromMS(ts), BarometerData(currentAct)));
}
}
while (iss >> ts >> value) {
ActivityButterPressure::Activity currentAct = act.add(Timestamp::fromMS(ts), BarometerData(value));
rawHist.push_back(ActivityButterPressure::History(Timestamp::fromMS(ts), BarometerData(value)));
actHist.push_back(ActivityButterPressure::History(Timestamp::fromMS(ts), BarometerData(currentAct)));
}
}
K::Gnuplot gp;
K::Gnuplot gpRaw;
K::GnuplotPlot plot;
K::GnuplotPlot plotRaw;
K::GnuplotPlotElementLines rawLines;
K::GnuplotPlotElementLines resultLines;
K::Gnuplot gp;
K::Gnuplot gpRaw;
K::GnuplotPlot plot;
K::GnuplotPlot plotRaw;
K::GnuplotPlotElementLines rawLines;
K::GnuplotPlotElementLines resultLines;
for(int i=0; i < actHist.size()-1; ++i){
for(int i=0; i < actHist.size()-1; ++i){
//raw
K::GnuplotPoint2 raw_p1(rawHist[i].ts.sec(), rawHist[i].data.hPa);
K::GnuplotPoint2 raw_p2(rawHist[i+1].ts.sec(), rawHist[i+1].data.hPa);
//raw
K::GnuplotPoint2 raw_p1(rawHist[i].ts.sec(), rawHist[i].data.hPa);
K::GnuplotPoint2 raw_p2(rawHist[i+1].ts.sec(), rawHist[i+1].data.hPa);
rawLines.addSegment(raw_p1, raw_p2);
rawLines.addSegment(raw_p1, raw_p2);
//results
K::GnuplotPoint2 input_p1(actHist[i].ts.sec(), actHist[i].data.hPa);
K::GnuplotPoint2 input_p2(actHist[i+1].ts.sec(), actHist[i+1].data.hPa);
//results
K::GnuplotPoint2 input_p1(actHist[i].ts.sec(), actHist[i].data.hPa);
K::GnuplotPoint2 input_p2(actHist[i+1].ts.sec(), actHist[i+1].data.hPa);
resultLines.addSegment(input_p1, input_p2);
}
resultLines.addSegment(input_p1, input_p2);
}
plotRaw.add(&rawLines);
plot.add(&resultLines);
plotRaw.add(&rawLines);
plot.add(&resultLines);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
gpRaw.draw(plotRaw);
gpRaw.flush();
gpRaw.draw(plotRaw);
gpRaw.flush();
sleep(5);
sleep(5);
}
TEST(Barometer, ActivityPercent) {
ActivityButterPressurePercent act;
ActivityButterPressurePercent act;
//read file
std::string line;
std::string filename = getDataFile("barometer/baro1.dat");
std::ifstream infile(filename);
//read file
std::string line;
std::string filename = getDataFile("barometer/baro1.dat");
std::ifstream infile(filename);
std::vector<ActivityButterPressurePercent::ActivityProbabilities> actHist;
std::vector<double> rawHist;
std::vector<ActivityButterPressurePercent::ActivityProbabilities> actHist;
std::vector<double> rawHist;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (std::getline(infile, line))
{
std::istringstream iss(line);
int ts;
double value;
while (iss >> ts >> value) {
ActivityButterPressurePercent::ActivityProbabilities activity = act.add(Timestamp::fromMS(ts), BarometerData(value));
rawHist.push_back(value);
actHist.push_back(activity);
}
}
while (iss >> ts >> value) {
ActivityButterPressurePercent::ActivityProbabilities activity = act.add(Timestamp::fromMS(ts), BarometerData(value));
rawHist.push_back(value);
actHist.push_back(activity);
}
}
K::Gnuplot gp;
K::Gnuplot gpRaw;
K::GnuplotPlot plot;
K::GnuplotPlot plotRaw;
K::GnuplotPlotElementLines rawLines;
K::GnuplotPlotElementLines resultLines;
K::Gnuplot gp;
K::Gnuplot gpRaw;
K::GnuplotPlot plot;
K::GnuplotPlot plotRaw;
K::GnuplotPlotElementLines rawLines;
K::GnuplotPlotElementLines resultLines;
for(int i=0; i < actHist.size()-1; ++i){
for(int i=0; i < actHist.size()-1; ++i){
K::GnuplotPoint2 raw_p1(i, rawHist[i]);
K::GnuplotPoint2 raw_p2(i+1, rawHist[i+1]);
K::GnuplotPoint2 raw_p1(i, rawHist[i]);
K::GnuplotPoint2 raw_p2(i+1, rawHist[i+1]);
rawLines.addSegment(raw_p1, raw_p2);
rawLines.addSegment(raw_p1, raw_p2);
K::GnuplotPoint2 input_p1(i, actHist[i].elevatorDown);
K::GnuplotPoint2 input_p2(i+1, actHist[i+1].elevatorDown);
K::GnuplotPoint2 input_p1(i, actHist[i].elevatorDown);
K::GnuplotPoint2 input_p2(i+1, actHist[i+1].elevatorDown);
resultLines.addSegment(input_p1, input_p2);
}
resultLines.addSegment(input_p1, input_p2);
}
plotRaw.add(&rawLines);
plot.add(&resultLines);
plotRaw.add(&rawLines);
plot.add(&resultLines);
gp.draw(plot);
gp.flush();
gp.draw(plot);
gp.flush();
gpRaw.draw(plotRaw);
gpRaw.flush();
gpRaw.draw(plotRaw);
gpRaw.flush();
sleep(5);
sleep(5);
}