Skip to content

Commit

Permalink
create TouchFeature class. I think that broke the brush and rub featu…
Browse files Browse the repository at this point in the history
…res, but need to test on another system to be sure
  • Loading branch information
vberthiaume committed Jan 7, 2025
1 parent bca9c96 commit 8497d65
Showing 1 changed file with 46 additions and 56 deletions.
102 changes: 46 additions & 56 deletions include/puara/descriptors/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,67 @@
namespace puara_gestures
{

class Brush
class TouchFeature
{
public:
/** ffff, 0--? (~cm/s) */
float value{};

void update(float input) { value = integrator.integrate(input); }

void reset() { value = 0; }

private:
void update (float movement)
{
// no movement since the last update -> reset the counter
if(movement == 0)
{
// wait some time before dropping the rub/brush values
if(++counter < 10)
return;

if(value < 0.001)
reset();
else
integrate(movement * .15);
}
//large movement, so integrate 0?
else if(std::abs(value) > 1)
{
// if(integrateWithZero())
integrate(0);
}
//goldilocks movement, so integrate the actual value and reset the brush counter
else
{
integrate(movement);
counter = 0;
}
}

protected:
int counter{};
virtual void integrate(float input) = 0;
utils::LeakyIntegrator integrator{0.0f, 0.0f, 0.7f, 100, 0};
virtual bool integrateWithZero() = 0;
};

class Rub
class Brush : public TouchFeature
{
public:
/** ffff, 0--? (~cm/s) */
float value{};

void update(float input) { value = integrator.integrate(std::abs(input)); }

void reset() { value = 0; }
void integrate(float movement) override { value = integrator.integrate(movement); }
bool integrateWithZero() override { return true; }
};

private:
utils::LeakyIntegrator integrator{0.0f, 0.0f, 0.7f, 100, 0};
class Rub : public TouchFeature
{
void integrate(float movement) override { value = integrator.integrate(std::abs(movement)); }
bool integrateWithZero() override { return false; }
};

class Touch
{
public:
static constexpr int maxNumBlobs = BlobDetector::maxNumBlobs;
static constexpr auto touchSizeEdge{4}; // amount of stripes for top and bottom portions (arbitrary)

float touchAll{}; // f, 0--1
float touchTop{}; // f, 0--1
float touchMiddle{}; // f, 0--1
Expand All @@ -54,13 +83,7 @@ class Touch
float rub{};
Rub rubs[maxNumBlobs];

// touch array
int touchSizeEdge{4}; // amount of stripes for top and bottom portions (arbitrary)

BlobDetector blobDetector;
int brushCounter[maxNumBlobs]{};

Touch() = default;

/* Expects an array of discrete touch values (int, 0 or 1) and
* the size of the array
Expand All @@ -74,45 +97,12 @@ class Touch
touchMiddle = utils::arrayAverage(discrete_touch, (0 + touchSizeEdge), (touchSize - touchSizeEdge));
touchBottom = utils::arrayAverage(discrete_touch, (touchSize - touchSizeEdge), touchSize);

// 1D blob detection: used for brush
// Detect blobs and update brushes and rubs based on the movement from the last update
const auto movement = blobDetector.detect1D(discrete_touch, touchSize);

for(int i = 0; i < movement.size(); ++i)
{
// no movement since the last update -> reset the brush counter
if(movement[i] == 0)
{
// wait some time before dropping the rub/brush values
if(++brushCounter[i] < 10)
continue;

if(brushes[i].value < 0.001)
{
brushes[i].reset();
rubs[i].reset();
}
else
{
const auto m{movement[i] * 0.15};
brushes[i].update(m);
rubs[i].update(m);
}
}
//large movement, so update only brushes with 0?
else if(std::abs(movement[i]) > 1)
{
brushes[i].update(0);
//should we also be updating rubs?
//rubs[i].update(0);
}
//goldilocks movement, so update both brushes and rubs, and reset the brush counter
else
{
brushes[i].update(movement[i]);
rubs[i].update(movement[i]);

brushCounter[i] = 0;
}
brushes[i].update(movement[i]);
rubs[i].update(movement[i]);
}

// Calculate total brush and rub values
Expand Down

0 comments on commit 8497d65

Please sign in to comment.