Skip to content

Commit

Permalink
cleanup and add moved touch test
Browse files Browse the repository at this point in the history
  • Loading branch information
vberthiaume committed Dec 17, 2024
1 parent 7cdc6c8 commit 3def1e1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
8 changes: 0 additions & 8 deletions include/puara/descriptors/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ class Touch
// in ~cm/s (distance between stripes = ~1.5cm)
for(int i = 0; i < maxNumBlobs; ++i)
{
//TODO: unclear how we ever could get here?
// if(blobPos[i] == -1)
// {
// multiBrush[i] = 0;
// multiRub[i] = 0;
// brushCounter[i] = 0;
// }
// else
if(movement[i] == 0)
{
if(brushCounter[i] < 10)
Expand Down
22 changes: 11 additions & 11 deletions include/puara/utils/blobDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace puara_gestures
* @struct BlobDetector
* @brief A structure for detecting contiguous regions (blobs) of `1`s in binary arrays.
*
* The `BlobDetector` identifies contiguous blobs in a binary input array where elements are either
* The `BlobDetector` identifies contiguous blobs in a binary input array where elements are either
* `0` or `1`.
* For each blob, it computes:
* - The start position (`blobStartPos`)
Expand Down Expand Up @@ -60,26 +60,26 @@ struct BlobDetector

/**
* @brief Detects contiguous regions (blobs) of `1`s in a 1D binary array and computes their movement.
*
* This function identifies blobs in the input binary array `touchArray`, calculates their start
* positions, sizes, and centers, and returns the movement of the blobs compared to their positions
*
* This function identifies blobs in the input binary array `touchArray`, calculates their start
* positions, sizes, and centers, and returns the movement of the blobs compared to their positions
* from the previous function call.
*
*
* @param touchArray Pointer to the 1D binary array representing touch data. Each element is expected to be 0 or 1.
* @param size The size of the `touchArray`.
* @return A vector of integers representing the movement of each blob's start position since the
* @return A vector of integers representing the movement of each blob's start position since the
* last invocation of `detect1D`. The size of the returned vector is `maxNumBlobs`.
*
*
* @note
* - The function updates the global variables `blobStartPos`, `blobSize`, `blobCenter`,
* - The function updates the global variables `blobStartPos`, `blobSize`, `blobCenter`,
* and `lastState_blobPos`.
* - The number of blobs detected is limited by `maxNumBlobs`.
* - If the number of blobs exceeds `maxNumBlobs`, additional blobs are ignored.
*
*
* @warning
* - Ensure that `touchArray` has at least `size` elements to avoid out-of-bounds access.
* - The function relies on external global variables (`blobStartPos`, `blobSize`, `blobCenter`,
* `lastState_blobPos`, `maxNumBlobs`, `blobAmount`). Ensure they are initialized appropriately
* - The function relies on external global variables (`blobStartPos`, `blobSize`, `blobCenter`,
* `lastState_blobPos`, `maxNumBlobs`, `blobAmount`). Ensure they are initialized appropriately
* before calling the function.
*/
std::vector<int> detect1D(const int* const touchArray, const int size)
Expand Down
32 changes: 28 additions & 4 deletions tests/testing_touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,37 @@ int main()
discrete_touch[14] = 1;
discrete_touch[15] = 1;

// Update the touch data
// Update the touch data and print the computed values
touch.updateTouchArray(discrete_touch, touchSize);

// Output the computed values
std::cout << "touchAll: " << touch.touchAll << std::endl;
std::cout << "brush: " << touch.brush << std::endl;
std::cout << "rub: " << touch.rub << std::endl;

// multi touch
//reset the touch array, and next we'll repeat the above blobs but offset by 1 to simulate movement
for(int i = 0; i < touchSize; ++i)
discrete_touch[i] = 0;

// simulate a blob of size 1 starting at position 1
discrete_touch[1] = 1;

// simulate a blob of size 2 starting at position 6
discrete_touch[6] = 1;
discrete_touch[7] = 1;

// simulate a blob of size 3 starting at position 9
discrete_touch[9] = 1;
discrete_touch[10] = 1;
discrete_touch[11] = 1;

// simulate a blob of size 1 at position 13 -- commented out to test the end of the array in the next blob
//discrete_touch[13] = 1;

// simulate a blob of size 1 starting at position 15
discrete_touch[15] = 1;

// Update the touch data and print the computed values
touch.updateTouchArray(discrete_touch, touchSize);
std::cout << "touchAll: " << touch.touchAll << std::endl;
std::cout << "brush: " << touch.brush << std::endl;
std::cout << "rub: " << touch.rub << std::endl;
}

0 comments on commit 3def1e1

Please sign in to comment.