prova

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of 53L0A1_HandGestureRecognition by ST

Committer:
mapellil
Date:
Thu Feb 22 15:50:29 2018 +0000
Revision:
9:6205ef056c8a
Parent:
7:d79cbeda2982
AStDay

Who changed what in which revision?

UserRevisionLine numberNew 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_SWIPE_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_SWIPE_1_H_
mapellil 7:d79cbeda2982 38 #define TOF_GESTURES_SWIPE_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_SWIPE_1 Single SWIPE (1)
mapellil 7:d79cbeda2982 48 * @brief Single Swipe gesture detection based on dynamic thresholds applied on 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 SWIPE (hand, finger, object) with a single ToF device. Returned
mapellil 7:d79cbeda2982 51 gestures code are one of the following ones : ::GESTURES_HAND_ENTERING, ::GESTURES_HAND_LEAVING, ::GESTURES_SINGLE_SWIPE during swipe
mapellil 7:d79cbeda2982 52 detection or ::GESTURES_NULL, ::GESTURES_DISCARDED, ::GESTURES_DISCARDED_TOO_SLOW in case SWIPE is not detected or discarded.
mapellil 7:d79cbeda2982 53 @par Algorithm Description
mapellil 7:d79cbeda2982 54 The approach consists in collecting __range__ samples over the time to get the background distance when no object is crossing the
mapellil 7:d79cbeda2982 55 device FoV. A variation of the returned distance versus the background is detected as a hand/object entering in the FoV. A simple
mapellil 7:d79cbeda2982 56 state machine is used to detect when the object will go out from the FoV. This module allows to detect any kind of swipes at all speeds
mapellil 7:d79cbeda2982 57 (very low, medium and very fast) and with any tilts of the hand.
mapellil 7:d79cbeda2982 58 @par Algorithm tuning
mapellil 7:d79cbeda2982 59 A set of macros are defined in the module header file to tune the swipe detection.
mapellil 7:d79cbeda2982 60 @par Known Limitations
mapellil 7:d79cbeda2982 61 @li A gesture with hand leaving the FoV from the top direction (instead of left/right) may be detected as Swipe
mapellil 7:d79cbeda2982 62 @li A Swipe may be wrongly detected when an object is placed at the border of the device FoV
mapellil 7:d79cbeda2982 63 * @ingroup tof_gestures
mapellil 7:d79cbeda2982 64 * @{
mapellil 7:d79cbeda2982 65 */
mapellil 7:d79cbeda2982 66
mapellil 7:d79cbeda2982 67 /** Buffer size used for averaging purpose */
mapellil 7:d79cbeda2982 68 #define SWIPE_1_BUFFER_SIZE 16
mapellil 7:d79cbeda2982 69 /** Background distance accepted variation (20%) */
mapellil 7:d79cbeda2982 70 #define SWIPE_1_BACKGROUND_VARIATION 0.2
mapellil 7:d79cbeda2982 71 /** Hand distance accepted variation (40%) */
mapellil 7:d79cbeda2982 72 #define SWIPE_1_HAND_VARIATION 0.4
mapellil 7:d79cbeda2982 73 /** State machine will reset if hand remains more than x msec in the FoV */
mapellil 7:d79cbeda2982 74 #define SWIPE_1_MAX_SWIPE_DURATION 1000
mapellil 7:d79cbeda2982 75 /** Max duration for distance to converge back to background when hand has left FoV */
mapellil 7:d79cbeda2982 76 #define SWIPE_1_BACKGROUND_TIMEOUT 100
mapellil 7:d79cbeda2982 77 /** Number of ranging distances to skip before starting gesture detection (0:max sensitivity) */
mapellil 7:d79cbeda2982 78 #define SWIPE_1_SENSITIVITY 0
mapellil 7:d79cbeda2982 79
mapellil 7:d79cbeda2982 80
mapellil 7:d79cbeda2982 81 /**
mapellil 7:d79cbeda2982 82 * @struct Gesture_SWIPE_1_Data_t
mapellil 7:d79cbeda2982 83 * @brief Data structure for single swipe gesture detection
mapellil 7:d79cbeda2982 84 */
mapellil 7:d79cbeda2982 85 typedef struct {
mapellil 7:d79cbeda2982 86 int gestureCode; /*!< Output : Gesture intermediate code */
mapellil 7:d79cbeda2982 87 ring_buffer rangeList; /*!< Private : List of range samples */
mapellil 7:d79cbeda2982 88 int meanBackground; /*!< Private : Mean distance of the background */
mapellil 7:d79cbeda2982 89 int meanHand; /*!< Private : Mean distance of the detected hand/object */
mapellil 7:d79cbeda2982 90 int timestamp; /*!< Private : Used for internal timing */
mapellil 7:d79cbeda2982 91 int cpt; /*!< Private : Internal counter */
mapellil 7:d79cbeda2982 92 } Gesture_SWIPE_1_Data_t;
mapellil 7:d79cbeda2982 93
mapellil 7:d79cbeda2982 94 /**
mapellil 7:d79cbeda2982 95 * @brief Initialize gesture data
mapellil 7:d79cbeda2982 96 * @return 0 on success
mapellil 7:d79cbeda2982 97 */
mapellil 7:d79cbeda2982 98 int tof_gestures_initSWIPE_1(Gesture_SWIPE_1_Data_t *data);
mapellil 7:d79cbeda2982 99 /**
mapellil 7:d79cbeda2982 100 * @brief Detect gesture
mapellil 7:d79cbeda2982 101 * @return One of these gestures code from ::Gestures_Code_t : ::GESTURES_HAND_ENTERING, ::GESTURES_HAND_LEAVING, ::GESTURES_SINGLE_SWIPE or
mapellil 7:d79cbeda2982 102 * ::GESTURES_NULL, ::GESTURES_DISCARDED, ::GESTURES_DISCARDED_TOO_SLOW
mapellil 7:d79cbeda2982 103 * @warning This function must be called all the time, even if no valid range_mm is available from the ToF device.
mapellil 7:d79cbeda2982 104 * In that case, call the function with the typical max ranging capability of the device
mapellil 7:d79cbeda2982 105 *
mapellil 7:d79cbeda2982 106 */
mapellil 7:d79cbeda2982 107 int tof_gestures_detectSWIPE_1(int32_t range_mm, Gesture_SWIPE_1_Data_t *data);
mapellil 7:d79cbeda2982 108
mapellil 7:d79cbeda2982 109 /** @} */
mapellil 7:d79cbeda2982 110 #ifdef __cplusplus
mapellil 7:d79cbeda2982 111 }
mapellil 7:d79cbeda2982 112 #endif
mapellil 7:d79cbeda2982 113 #endif /* TOF_GESTURES_SWIPE_1_H_ */
mapellil 7:d79cbeda2982 114