prova
Dependencies: X_NUCLEO_53L0A1 mbed
Fork of 53L0A1_HandGestureRecognition by
Middlewares/ST/Gestures/GesturesDetect/Inc/tof_gestures_TAP_1.h@7:d79cbeda2982, 2017-12-15 (annotated)
- Committer:
- mapellil
- Date:
- Fri Dec 15 14:16:16 2017 +0000
- Revision:
- 7:d79cbeda2982
Added hand gesture (L-Rswipe) with L+R sensors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mapellil | 7:d79cbeda2982 | 1 | /******************************************************************************* |
mapellil | 7:d79cbeda2982 | 2 | Copyright © 2015, STMicroelectronics International N.V. |
mapellil | 7:d79cbeda2982 | 3 | All rights reserved. |
mapellil | 7:d79cbeda2982 | 4 | |
mapellil | 7:d79cbeda2982 | 5 | Use and Redistribution are permitted only in accordance with licensing terms |
mapellil | 7:d79cbeda2982 | 6 | available at www.st.com under software reference X-CUBE-6180XA1, and provided |
mapellil | 7:d79cbeda2982 | 7 | that the following conditions are met: |
mapellil | 7:d79cbeda2982 | 8 | * Redistributions of source code must retain the above copyright |
mapellil | 7:d79cbeda2982 | 9 | notice, this list of conditions and the following disclaimer. |
mapellil | 7:d79cbeda2982 | 10 | * Redistributions in binary form must reproduce the above copyright |
mapellil | 7:d79cbeda2982 | 11 | notice, this list of conditions and the following disclaimer in the |
mapellil | 7:d79cbeda2982 | 12 | documentation and/or other materials provided with the distribution. |
mapellil | 7:d79cbeda2982 | 13 | * Neither the name of STMicroelectronics nor the |
mapellil | 7:d79cbeda2982 | 14 | names of its contributors may be used to endorse or promote products |
mapellil | 7:d79cbeda2982 | 15 | derived from this software without specific prior written permission. |
mapellil | 7:d79cbeda2982 | 16 | |
mapellil | 7:d79cbeda2982 | 17 | THIS SOFTWARE IS PROTECTED BY STMICROELECTRONICS PATENTS AND COPYRIGHTS. |
mapellil | 7:d79cbeda2982 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
mapellil | 7:d79cbeda2982 | 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
mapellil | 7:d79cbeda2982 | 20 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND |
mapellil | 7:d79cbeda2982 | 21 | NON-INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS ARE DISCLAIMED. |
mapellil | 7:d79cbeda2982 | 22 | IN NO EVENT SHALL STMICROELECTRONICS INTERNATIONAL N.V. BE LIABLE FOR ANY |
mapellil | 7:d79cbeda2982 | 23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
mapellil | 7:d79cbeda2982 | 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
mapellil | 7:d79cbeda2982 | 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
mapellil | 7:d79cbeda2982 | 26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
mapellil | 7:d79cbeda2982 | 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
mapellil | 7:d79cbeda2982 | 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
mapellil | 7:d79cbeda2982 | 29 | ********************************************************************************/ |
mapellil | 7:d79cbeda2982 | 30 | |
mapellil | 7:d79cbeda2982 | 31 | /* |
mapellil | 7:d79cbeda2982 | 32 | * @file tof_gestures_TAP_1.h |
mapellil | 7:d79cbeda2982 | 33 | * $Date$ |
mapellil | 7:d79cbeda2982 | 34 | * $Revision$ |
mapellil | 7:d79cbeda2982 | 35 | */ |
mapellil | 7:d79cbeda2982 | 36 | |
mapellil | 7:d79cbeda2982 | 37 | #ifndef TOF_GESTURES_TAP_1_H_ |
mapellil | 7:d79cbeda2982 | 38 | #define TOF_GESTURES_TAP_1_H_ |
mapellil | 7:d79cbeda2982 | 39 | |
mapellil | 7:d79cbeda2982 | 40 | #include "tof_gestures_platform.h" |
mapellil | 7:d79cbeda2982 | 41 | #include "ring_buffer.h" |
mapellil | 7:d79cbeda2982 | 42 | |
mapellil | 7:d79cbeda2982 | 43 | #ifdef __cplusplus |
mapellil | 7:d79cbeda2982 | 44 | extern "C" { |
mapellil | 7:d79cbeda2982 | 45 | #endif |
mapellil | 7:d79cbeda2982 | 46 | |
mapellil | 7:d79cbeda2982 | 47 | /** @defgroup tof_gestures_TAP_1 Single TAP (1) |
mapellil | 7:d79cbeda2982 | 48 | * @brief Single Tap gesture detection based on simple analysis (MAD) of range (single ToF device) |
mapellil | 7:d79cbeda2982 | 49 | @par Description |
mapellil | 7:d79cbeda2982 | 50 | This tof_gestures module allows to detect in a very robust way a single TAP (flat hand going down) with a single ToF device. Returned |
mapellil | 7:d79cbeda2982 | 51 | gestures code are one of the following ones : ::GESTURES_SINGLE_TAP or ::GESTURES_NULL in case no TAP is detected. |
mapellil | 7:d79cbeda2982 | 52 | @par Algorithm Description |
mapellil | 7:d79cbeda2982 | 53 | The approach consists in collecting __range__ samples when a target (hand) is detected by the ranging device. Then, MAD |
mapellil | 7:d79cbeda2982 | 54 | (Mean of Absolute Difference versus the mean) is calculated and TAP gesture is detected based on a threshold. Some false TAP detections |
mapellil | 7:d79cbeda2982 | 55 | could happen in case a target is detected in the background (behind the han). To avoid these false detections, set the MinBackGroundDistance |
mapellil | 7:d79cbeda2982 | 56 | to the minimum distance a background target can be detected in the application. If no background, set MinBackGroundDistance to a big value |
mapellil | 7:d79cbeda2982 | 57 | * @ingroup tof_gestures |
mapellil | 7:d79cbeda2982 | 58 | * @{ |
mapellil | 7:d79cbeda2982 | 59 | */ |
mapellil | 7:d79cbeda2982 | 60 | |
mapellil | 7:d79cbeda2982 | 61 | |
mapellil | 7:d79cbeda2982 | 62 | |
mapellil | 7:d79cbeda2982 | 63 | /** Mean variation to start tap detection (5%) */ |
mapellil | 7:d79cbeda2982 | 64 | #define TAP_1_BACKGROUND_VARIATION 0.05 |
mapellil | 7:d79cbeda2982 | 65 | /** Buffer size used for background mean calculation */ |
mapellil | 7:d79cbeda2982 | 66 | #define TAP_1_BUFFER_SIZE 16 |
mapellil | 7:d79cbeda2982 | 67 | /** Minimum number of ranging data to get before deciding to detect a TAP */ |
mapellil | 7:d79cbeda2982 | 68 | #define TAP_1_NB_OF_DATA_TO_DECIDE 4 |
mapellil | 7:d79cbeda2982 | 69 | |
mapellil | 7:d79cbeda2982 | 70 | /** |
mapellil | 7:d79cbeda2982 | 71 | * @struct Gesture_TAP_1_Data_t |
mapellil | 7:d79cbeda2982 | 72 | * @brief Data structure for single tap gesture detection |
mapellil | 7:d79cbeda2982 | 73 | */ |
mapellil | 7:d79cbeda2982 | 74 | typedef struct { |
mapellil | 7:d79cbeda2982 | 75 | int MinBackGroundDistance; /*!< Input : Minimum background distance (typically 300 mm). Set to big value if no background detected in final application. */ |
mapellil | 7:d79cbeda2982 | 76 | int gestureCode; /*!< Output : Gesture intermediate code */ |
mapellil | 7:d79cbeda2982 | 77 | ring_buffer rangeList; /*!< Private : List of range samples */ |
mapellil | 7:d79cbeda2982 | 78 | int timestampLastDetectedTap; /*!< Private : Time of the last detected TAP */ |
mapellil | 7:d79cbeda2982 | 79 | int nbOfDataToDecide; /*!< Private : Number of range data collected to detect a TAP in a very robust way */ |
mapellil | 7:d79cbeda2982 | 80 | int meanBackground; /*!< Private : Mean distance of the background */ |
mapellil | 7:d79cbeda2982 | 81 | int timestamp; /*!< Private : Used for internal timing */ |
mapellil | 7:d79cbeda2982 | 82 | } Gesture_TAP_1_Data_t; |
mapellil | 7:d79cbeda2982 | 83 | |
mapellil | 7:d79cbeda2982 | 84 | /** |
mapellil | 7:d79cbeda2982 | 85 | * @brief Initialize gesture data |
mapellil | 7:d79cbeda2982 | 86 | * @return 0 on success |
mapellil | 7:d79cbeda2982 | 87 | */ |
mapellil | 7:d79cbeda2982 | 88 | int tof_gestures_initTAP_1(int MinBackGroundDistance, Gesture_TAP_1_Data_t *data); |
mapellil | 7:d79cbeda2982 | 89 | |
mapellil | 7:d79cbeda2982 | 90 | |
mapellil | 7:d79cbeda2982 | 91 | /** |
mapellil | 7:d79cbeda2982 | 92 | * @brief Detect gesture |
mapellil | 7:d79cbeda2982 | 93 | * @return One of these gestures code from ::Gestures_Code_t : ::GESTURES_SINGLE_TAP or ::GESTURES_NULL |
mapellil | 7:d79cbeda2982 | 94 | * @warning This function must be called all the time, even if no valid range_mm is available from the ToF device. |
mapellil | 7:d79cbeda2982 | 95 | * In that case, call the function with the typical max ranging capability of the device |
mapellil | 7:d79cbeda2982 | 96 | */ |
mapellil | 7:d79cbeda2982 | 97 | int tof_gestures_detectTAP_1(int32_t range_mm, Gesture_TAP_1_Data_t *data); |
mapellil | 7:d79cbeda2982 | 98 | |
mapellil | 7:d79cbeda2982 | 99 | /** @} */ |
mapellil | 7:d79cbeda2982 | 100 | #ifdef __cplusplus |
mapellil | 7:d79cbeda2982 | 101 | } |
mapellil | 7:d79cbeda2982 | 102 | #endif |
mapellil | 7:d79cbeda2982 | 103 | #endif /* TOF_GESTURES_TAP_1_H_ */ |
mapellil | 7:d79cbeda2982 | 104 |