-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Touch class to extract Brush and Rub classes as their own to…
…uch features
- Loading branch information
1 parent
f19ab5f
commit 2d00e5f
Showing
9 changed files
with
311 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ jobs: | |
} | ||
- { | ||
os: windows-latest, | ||
cmake_options: "BOOST_ROOT=c:/local/boost_1_86_0", | ||
dependencies: "choco install eigen -y --no-progress && choco install boost-msvc-14.3 -y --no-progress" | ||
cmake_options: "Boost_INCLUDE_DIR=D:/a/puara-gestures/puara-gestures/3rdparty", | ||
dependencies: "choco install eigen -y --no-progress" | ||
} | ||
|
||
runs-on: ${{ matrix.config.os }} | ||
|
@@ -31,12 +31,11 @@ jobs: | |
submodules: recursive | ||
|
||
- name: Dependencies | ||
run: ${{ matrix.config.dependencies }} | ||
run: ${{ matrix.config.dependencies }} | ||
|
||
- name: Build Project | ||
uses: threeal/[email protected] | ||
with: | ||
options: | | ||
PUARA_GESTURES_ENABLE_STANDALONE=0 | ||
${{ matrix.config.cmake_options }} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ build/ | |
*.user | ||
*code-workspace | ||
.pio | ||
exampleProjects/touch/.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,144 +1,54 @@ | ||
#pragma once | ||
|
||
#include <puara/utils.h> | ||
#include <puara/utils/blobDetector.h> | ||
#include <puara/utils/leakyintegrator.h> | ||
|
||
#include <cmath> | ||
#include<iostream> | ||
#include "touchFeatures.h" | ||
|
||
namespace puara_gestures | ||
{ | ||
|
||
class Touch | ||
{ | ||
public: | ||
static constexpr int maxNumBlobs = BlobDetector::maxNumBlobs; | ||
float touchAll = 0.0f; // f, 0--1 | ||
float touchTop = 0.0f; // f, 0--1 | ||
float touchMiddle = 0.0f; // f, 0--1 | ||
float touchBottom = 0.0f; // f, 0--1 | ||
float brush = 0.0f; // f, 0--? (~cm/s) | ||
double multiBrush[maxNumBlobs]{}; // ffff, 0--? (~cm/s) | ||
float rub{}; // f, 0--? (~cm/s) | ||
double multiRub[maxNumBlobs]{}; // ffff, 0--? (~cm/s) | ||
static constexpr auto touchSizeEdge{4}; // amount of stripes for top and bottom portions (arbitrary) | ||
|
||
// touch array | ||
int touchSizeEdge = 4; // amount of touch stripes for top and bottom portions (arbitrary) | ||
float touchAll{}; // f, 0--1 | ||
float touchTop{}; // f, 0--1 | ||
float touchMiddle{}; // f, 0--1 | ||
float touchBottom{}; // f, 0--1 | ||
|
||
BlobDetector blobDetector; | ||
int brushCounter[maxNumBlobs]{}; | ||
/** brush: direction and intensity of capsense brush motion in ~cm/s (distance between stripes = ~1.5cm) */ | ||
float brush{}; | ||
Brush brushes[maxNumBlobs]; | ||
|
||
// Arrays of LeakyIntegrator instances | ||
utils::LeakyIntegrator multiBrushIntegrator[maxNumBlobs]; | ||
utils::LeakyIntegrator multiRubIntegrator[maxNumBlobs]; | ||
/** rub: intensity of rub motion in ~cm/s (distance between stripes = ~1.5cm) */ | ||
float rub{}; | ||
Rub rubs[maxNumBlobs]; | ||
|
||
Touch() | ||
{ | ||
for(int i = 0; i < maxNumBlobs; ++i) | ||
{ | ||
multiBrushIntegrator[i] = utils::LeakyIntegrator(0.0f, 0.0f, 0.7f, 100, 0); | ||
multiRubIntegrator[i] = utils::LeakyIntegrator(0.0f, 0.0f, 0.7f, 100, 0); | ||
} | ||
} | ||
BlobDetector blobDetector; | ||
|
||
/* Expects an array of discrete touch values (int, 0 or 1) and | ||
* the size of the array | ||
*/ | ||
void updateTouchArray(int* discrete_touch, int touchSize) | ||
{ // raw_touch | ||
|
||
// touchAll: get the "amount of touch" for the entire touch sensor | ||
// normalized between 0 and 1 | ||
touchAll = touchAverage(discrete_touch, 0, touchSize); | ||
|
||
// touchTop: get the "amount of touch" for the top part of the capsense | ||
// normalized between 0 and 1 | ||
touchTop = touchAverage(discrete_touch, 0, touchSizeEdge); | ||
|
||
// touchMiddle: get the "amount of touch" for the central part of the capsense | ||
// normalized between 0 and 1 | ||
touchMiddle | ||
= touchAverage(discrete_touch, (0 + touchSizeEdge), (touchSize - touchSizeEdge)); | ||
|
||
// touchBottom: get the "amount of touch" for the botton part of the capsense | ||
// normalized between 0 and 1 | ||
touchBottom = touchAverage(discrete_touch, (touchSize - touchSizeEdge), touchSize); | ||
|
||
// 1D blob detection: used for brush | ||
const auto movement = blobDetector.detect1D(discrete_touch, touchSize); | ||
|
||
// brush: direction and intensity of capsense brush motion | ||
// rub: intensity of rub motion | ||
// in ~cm/s (distance between stripes = ~1.5cm) | ||
for(int i = 0; i < movement.size(); ++i) | ||
{ | ||
// Update the "amount of touch" for the entire touch sensor, as well as the top, middle and bottom parts. | ||
// All normalized between 0 and 1. | ||
touchAll = utils::arrayAverage(discrete_touch, 0, touchSize); | ||
touchTop = utils::arrayAverage(discrete_touch, 0, touchSizeEdge); | ||
touchMiddle = utils::arrayAverage(discrete_touch, (0 + touchSizeEdge), (touchSize - touchSizeEdge)); | ||
touchBottom = utils::arrayAverage(discrete_touch, (touchSize - touchSizeEdge), touchSize); | ||
|
||
const auto blobMovements{blobDetector.detect1D(discrete_touch, touchSize)}; | ||
for(int i = 0; i < maxNumBlobs; ++i) | ||
{ | ||
if(movement[i] == 0) | ||
{ | ||
if(brushCounter[i] < 10) | ||
{ | ||
brushCounter[i]++; | ||
// wait some time before dropping the rub/brush values | ||
} | ||
else if(multiBrush[i] < 0.001) | ||
{ | ||
multiBrush[i] = 0; | ||
multiRub[i] = 0; | ||
} | ||
else | ||
{ | ||
// multiBrush[i] = multiBrushIntegrator[i].integrate( | ||
// movement * 0.15, multiBrush[i], 0.7, leakyBrushFreq, leakyBrushTimer); | ||
|
||
// multiRub[i] = multiRubIntegrator[i].integrate( | ||
// (std::abs(movement * 0.15)), multiRub[i], 0.7, leakyRubFreq, | ||
// leakyRubTimer); | ||
// | ||
multiBrush[i] = multiBrushIntegrator[i].integrate(movement[i] * 0.15); | ||
multiRub[i] = multiRubIntegrator[i].integrate(std::abs(movement[i] * 0.15)); | ||
} | ||
} | ||
else if(std::abs(movement[i]) > 1) | ||
{ | ||
// multiBrush[i] = multiBrushIntegrator[i].integrate( | ||
// 0, multiBrush[i], 0.6, leakyBrushFreq, leakyBrushTimer); | ||
|
||
multiBrush[i] = multiBrushIntegrator[i].integrate(0); | ||
} | ||
else | ||
{ | ||
// multiBrush[i] = multiBrushIntegrator[i].integrate( | ||
// movement * 0.15, multiBrush[i], 0.8, leakyBrushFreq, leakyBrushTimer); | ||
// multiRub[i] = multiRubIntegrator[i].integrate( | ||
// (std::abs(movement * 0.15)) * 0.15, multiRub[i], 0.99, leakyRubFreq, | ||
// leakyRubTimer); | ||
|
||
multiBrush[i] = multiBrushIntegrator[i].integrate(movement[i] * 0.15); | ||
multiRub[i] = multiRubIntegrator[i].integrate((std::abs(movement[i] * 0.15))); | ||
|
||
brushCounter[i] = 0; | ||
} | ||
brushes[i].update(blobMovements[i]); | ||
rubs[i].update(blobMovements[i]); | ||
} | ||
brush = utils::arrayAverageZero(multiBrush, maxNumBlobs); | ||
rub = utils::arrayAverageZero(multiRub, maxNumBlobs); | ||
} | ||
|
||
float touchAverage(float* touchArrayStrips, int firstStrip, int lastStrip) | ||
{ | ||
int sum = 0; | ||
for(int i = firstStrip; i < lastStrip - 1; ++i) | ||
sum += touchArrayStrips[i]; | ||
|
||
return ((float)sum) / (lastStrip - firstStrip); | ||
} | ||
|
||
float touchAverage(int* touchArrayStrips, int firstStrip, int lastStrip) | ||
{ | ||
int sum = 0; | ||
for(int i = firstStrip; i < lastStrip; i++) | ||
sum += (float)touchArrayStrips[i]; | ||
|
||
return ((float)sum) / (lastStrip - firstStrip); | ||
// Calculate total brush and rub values | ||
brush = utils::arrayAverageZero(brushes, maxNumBlobs); | ||
rub = utils::arrayAverageZero(rubs, maxNumBlobs); | ||
} | ||
}; | ||
} |
Oops, something went wrong.