Cubic Hand project for EECS 249A course.

Dependencies:   MMA8451Q TSI cc3000_hostdriver_mbedsocket NVIC_set_all_priorities mbed Multi_WS2811

Committer:
robertbui
Date:
Thu Dec 11 17:49:21 2014 +0000
Revision:
49:361833355173
Parent:
48:2ba6321d79fc
Child:
51:09796a9ee78d
Gesture parameters update.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robertbui 40:bdd949fc3bc2 1 #include "GestureRecognition.h"
robertbui 40:bdd949fc3bc2 2 #include "mbed.h"
robertbui 40:bdd949fc3bc2 3
robertbui 40:bdd949fc3bc2 4 #define MAX_COUNT 10
robertbui 40:bdd949fc3bc2 5
robertbui 40:bdd949fc3bc2 6 GestureRecognition::GestureRecognition(){
robertbui 40:bdd949fc3bc2 7 counter = 0;
robertbui 49:361833355173 8 secondCounter = 0;
robertbui 40:bdd949fc3bc2 9 }
robertbui 40:bdd949fc3bc2 10
robertbui 40:bdd949fc3bc2 11 GestureRecognition::~GestureRecognition(){
robertbui 40:bdd949fc3bc2 12 }
robertbui 40:bdd949fc3bc2 13
robertbui 40:bdd949fc3bc2 14
robertbui 49:361833355173 15 //Finger data is given in range of 0-150. 150 = finger is bent. 0 = finger is straight out.
robertbui 40:bdd949fc3bc2 16
robertbui 40:bdd949fc3bc2 17 CubeUpdateParameters GestureRecognition::sensorToGesture(Glove data){
robertbui 49:361833355173 18 CubeUpdateParameters returnParams;
robertbui 49:361833355173 19 returnParams.size = 0;
robertbui 49:361833355173 20 returnParams.deltaX = 0;
robertbui 49:361833355173 21 returnParams.deltaY = 0;
robertbui 49:361833355173 22 returnParams.deltaZ = 0;
robertbui 49:361833355173 23 int fingerThreshold = 50;
robertbui 49:361833355173 24 if (++counter >= MAX_COUNT) {
robertbui 49:361833355173 25 returnParams.size = 4;
robertbui 49:361833355173 26 if (secondCounter > 3) {
robertbui 49:361833355173 27 printf("%f\r\n", data.fingers[0]);
robertbui 49:361833355173 28 secondCounter = 0;
robertbui 49:361833355173 29 }
robertbui 49:361833355173 30 secondCounter++;
robertbui 40:bdd949fc3bc2 31 //Change size based on finger gesture
robertbui 49:361833355173 32 /*if (data.fingers[0] > fingerThreshold && data.fingers[1] > fingerThreshold && data.fingers[2] > fingerThreshold && data.fingers[3] < fingerThreshold && data.fingers[4] > fingerThreshold )
robertbui 40:bdd949fc3bc2 33 returnParams.size = 2;
robertbui 49:361833355173 34 else if (data.fingers[0] > fingerThreshold && data.fingers[1] > fingerThreshold && data.fingers[2] < fingerThreshold && data.fingers[3] < fingerThreshold && data.fingers[4] > fingerThreshold )
robertbui 40:bdd949fc3bc2 35 returnParams.size = 4;
robertbui 49:361833355173 36 else if (data.fingers[0] > fingerThreshold && data.fingers[1] < fingerThreshold && data.fingers[2] < fingerThreshold && data.fingers[3] < fingerThreshold && data.fingers[4] > fingerThreshold )
robertbui 40:bdd949fc3bc2 37 returnParams.size = 6;
robertbui 49:361833355173 38 else if (data.fingers[0] < fingerThreshold && data.fingers[1] < fingerThreshold && data.fingers[2] < fingerThreshold && data.fingers[3] < 75 && data.fingers[4] > 75 )
robertbui 49:361833355173 39 returnParams.size = 8; */
robertbui 40:bdd949fc3bc2 40 //Change color
robertbui 49:361833355173 41 // else if (data.fingers[0] > fingerThreshold && data.fingers[1] > fingerThreshold && data.fingers[2] > fingerThreshold && data.fingers[4] > fingerThreshold ) {
robertbui 40:bdd949fc3bc2 42 returnParams.hue = data.fingers[3]/150.0;
robertbui 49:361833355173 43 // }
robertbui 40:bdd949fc3bc2 44
robertbui 40:bdd949fc3bc2 45 //Change position. Roll, pitch, and yaw are given as degrees.
robertbui 48:2ba6321d79fc 46 if (data.roll > 10 )
robertbui 48:2ba6321d79fc 47 returnParams.deltaX = -1;
robertbui 48:2ba6321d79fc 48 else if (data.roll < -10)
robertbui 40:bdd949fc3bc2 49 returnParams.deltaX = 1;
robertbui 48:2ba6321d79fc 50 if (data.pitch > 10)
robertbui 40:bdd949fc3bc2 51 returnParams.deltaZ = 1;
robertbui 48:2ba6321d79fc 52 else if (data.pitch < -10)
robertbui 40:bdd949fc3bc2 53 returnParams.deltaZ = -1;
robertbui 48:2ba6321d79fc 54 if (data.yaw > 10)
robertbui 49:361833355173 55 returnParams.deltaY = -1;
robertbui 48:2ba6321d79fc 56 else if (data.yaw + 360 > 10 && data.yaw < 0)
robertbui 49:361833355173 57 returnParams.deltaY = 1;
robertbui 40:bdd949fc3bc2 58
robertbui 40:bdd949fc3bc2 59 counter = 0;
robertbui 40:bdd949fc3bc2 60
robertbui 40:bdd949fc3bc2 61 }
robertbui 40:bdd949fc3bc2 62 return returnParams;
robertbui 40:bdd949fc3bc2 63 }