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 10:18:48 2014 +0000
Revision:
40:bdd949fc3bc2
Child:
48:2ba6321d79fc
First attempt at full integration.

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 40:bdd949fc3bc2 8 }
robertbui 40:bdd949fc3bc2 9
robertbui 40:bdd949fc3bc2 10 GestureRecognition::~GestureRecognition(){
robertbui 40:bdd949fc3bc2 11 }
robertbui 40:bdd949fc3bc2 12
robertbui 40:bdd949fc3bc2 13
robertbui 40:bdd949fc3bc2 14 //Finger data is given in range of 0-150. 1500 = finger is bent. 0 = finger is straight out.
robertbui 40:bdd949fc3bc2 15
robertbui 40:bdd949fc3bc2 16 CubeUpdateParameters GestureRecognition::sensorToGesture(Glove data){
robertbui 40:bdd949fc3bc2 17 CubeUpdateParameters returnParams;
robertbui 40:bdd949fc3bc2 18 returnParams.size = 0;
robertbui 40:bdd949fc3bc2 19 returnParams.deltaX = 0;
robertbui 40:bdd949fc3bc2 20 returnParams.deltaY = 0;
robertbui 40:bdd949fc3bc2 21 returnParams.deltaZ = 0;
robertbui 40:bdd949fc3bc2 22 if (++counter == MAX_COUNT) {
robertbui 40:bdd949fc3bc2 23 //Change size based on finger gesture
robertbui 40:bdd949fc3bc2 24 if (data.fingers[0] > 75 && data.fingers[1] > 75 && data.fingers[2] > 75 && data.fingers[3] < 75 && data.fingers[4] > 75 )
robertbui 40:bdd949fc3bc2 25 returnParams.size = 2;
robertbui 40:bdd949fc3bc2 26 else if (data.fingers[0] > 75 && data.fingers[1] > 75 && data.fingers[2] < 75 && data.fingers[3] < 75 && data.fingers[4] > 75 )
robertbui 40:bdd949fc3bc2 27 returnParams.size = 4;
robertbui 40:bdd949fc3bc2 28 else if (data.fingers[0] > 75 && data.fingers[1] < 75 && data.fingers[2] < 75 && data.fingers[3] < 75 && data.fingers[4] > 75 )
robertbui 40:bdd949fc3bc2 29 returnParams.size = 6;
robertbui 40:bdd949fc3bc2 30 else if (data.fingers[0] < 75 && data.fingers[1] < 75 && data.fingers[2] < 75 && data.fingers[3] < 75 && data.fingers[4] > 75 )
robertbui 40:bdd949fc3bc2 31 returnParams.size = 8;
robertbui 40:bdd949fc3bc2 32 //Change color
robertbui 40:bdd949fc3bc2 33 else if (data.fingers[0] > 75 && data.fingers[1] > 75 && data.fingers[2] > 75 && data.fingers[4] > 75 ) {
robertbui 40:bdd949fc3bc2 34 returnParams.hue = data.fingers[3]/150.0;
robertbui 40:bdd949fc3bc2 35 }
robertbui 40:bdd949fc3bc2 36
robertbui 40:bdd949fc3bc2 37 //Change position. Roll, pitch, and yaw are given as degrees.
robertbui 40:bdd949fc3bc2 38 if (data.roll > 5 )
robertbui 40:bdd949fc3bc2 39 returnParams.deltaX = 1;
robertbui 40:bdd949fc3bc2 40 else if (data.roll < -5)
robertbui 40:bdd949fc3bc2 41 returnParams.deltaX = -1;
robertbui 40:bdd949fc3bc2 42 else if (data.pitch > 5)
robertbui 40:bdd949fc3bc2 43 returnParams.deltaZ = 1;
robertbui 40:bdd949fc3bc2 44 else if (data.pitch < -5)
robertbui 40:bdd949fc3bc2 45 returnParams.deltaZ = -1;
robertbui 40:bdd949fc3bc2 46 else if (data.pitch > 5)
robertbui 40:bdd949fc3bc2 47 returnParams.deltaY = 1;
robertbui 40:bdd949fc3bc2 48 else if (data.pitch + 360 < -5)
robertbui 40:bdd949fc3bc2 49 returnParams.deltaY = -1;
robertbui 40:bdd949fc3bc2 50
robertbui 40:bdd949fc3bc2 51 counter = 0;
robertbui 40:bdd949fc3bc2 52
robertbui 40:bdd949fc3bc2 53 }
robertbui 40:bdd949fc3bc2 54 return returnParams;
robertbui 40:bdd949fc3bc2 55 }