Temp Fork

Dependencies:   MMA8451Q Multi_WS2811 NVIC_set_all_priorities TSI cc3000_hostdriver_mbedsocket mbed

Fork of CubicHand by Model-Based Team

Files at this revision

API Documentation at this revision

Comitter:
robertbui
Date:
Thu Dec 11 06:08:13 2014 +0000
Parent:
30:3261015fdd17
Commit message:
initial draft of gesture recognition.

Changed in this revision

CubeUpdateParameters.h Show annotated file Show diff for this revision Revisions of this file
DataGlove.cpp Show annotated file Show diff for this revision Revisions of this file
DataGlove.h Show annotated file Show diff for this revision Revisions of this file
GestureRecognition.h Show annotated file Show diff for this revision Revisions of this file
GloveWifi.cpp Show annotated file Show diff for this revision Revisions of this file
ledCube.cpp Show annotated file Show diff for this revision Revisions of this file
ledCube.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DataGlove.cpp	Thu Dec 11 05:57:54 2014 +0000
+++ b/DataGlove.cpp	Thu Dec 11 06:08:13 2014 +0000
@@ -58,14 +58,7 @@
     GloveSocket.SendDataToGlove(SendBuf, 6);
 }
 
-
-Glove DataGlove::ReceiveBlocking()
-{
-	while(Receive() == false);
-	return *gl;
-}
-
-bool DataGlove::Receive()
+void DataGlove::Receive()
 {
     raw = false;
     numReceived += GloveSocket.GetDataFromBuffer(Buf, 1);
@@ -83,7 +76,7 @@
             if ((numReceived  - 3 )< pkglen) 
             {
                 if(numReceived == 0) notConnectedCount++;
-                return false;
+                return;
             }
             for (u = 3; u <= pkglen; u++)
             {
@@ -98,12 +91,11 @@
                 timeOfArrival = (Buf[6] << 24) + (Buf[7] << 16) + (Buf[8] << 8) + Buf[9];
                 id = (Buf[4] << 8) + Buf[5];
                 pkgtype = Buf[3];
-                ReceiveCount++;
-                /*if(ReceiveCount > 501 && ReceiveCount%25 == 0) {//printf("%d %c\r\n", ReceiveCount, Buf[0]);
+                if(ReceiveCount > 501 && ReceiveCount++%25 == 0) {//printf("%d %c\r\n", ReceiveCount, Buf[0]);
                 	printf("%f %f %f %f %f %f %f %f\r\n", corrected->roll, corrected->pitch, corrected->yaw, 
                 	corrected->fingers[0], corrected->fingers[1], corrected->fingers[2], 
                 	corrected->fingers[3], corrected->fingers[4]);
-                }*/
+                }
                 switch (pkgtype){
                     case STREAM_FINGERS_QUATERNION:
                     {
@@ -136,7 +128,6 @@
                 Buf[0] = 0; //Clear Token so no repeats.
                 notConnectedCount = 0;
                 numReceived = 0;
-                return true;
             }
             else
             {
@@ -145,7 +136,7 @@
             }
         }
         // Normalize the data for the first 1000 samples
-        /*if (ReceiveCount < 500) {
+        if (ReceiveCount < 500) {
         	correction->roll = (correction->roll*ReceiveCount + gl->roll)/(ReceiveCount+1);
         	correction->pitch = (correction->pitch*ReceiveCount + gl->pitch)/(ReceiveCount+1);
         	correction->yaw = (correction->yaw*ReceiveCount + gl->yaw)/(ReceiveCount+1);
@@ -158,21 +149,21 @@
         	corrected->yaw = gl->yaw - correction->yaw;
         	for (int iter = 0; iter < 5; iter++)
         		corrected->fingers[iter] = gl->fingers[iter] - correction->fingers[iter];
-        }*/
+        }
     }
-   else {
+    else {
         //printf("couldn't get data %d\r\n", notConnectedCount);
         // Re-establishing communication in case no data is received for 1s (20 frames per second*1 = 20)
-        /*if (notConnectedCount > 200) {
+        if (notConnectedCount > 200) {
             printf("Connection broke! Trying to re-establish... %d %c\r\n",numReceived,Buf[0]);
             //GloveSocket.Reconnect();
             //StreamData(STREAM_QUATERNION);
             notConnectedCount = 0;
-        }*/
+        }
         numReceived = 0;
-        //notConnectedCount++;
+        notConnectedCount++;
     }
-    return false;
+    
 }
 
 void DataGlove::ExtractFingersQuat()
@@ -328,7 +319,6 @@
 {
 	return *gl;
 }
-
 bool DataGlove::CheckForNewValues()
 {
 	if(NewData == true)
--- a/DataGlove.h	Thu Dec 11 05:57:54 2014 +0000
+++ b/DataGlove.h	Thu Dec 11 06:08:13 2014 +0000
@@ -19,8 +19,7 @@
 		DataGlove();
 		~DataGlove();
 		void Init();
-		bool Receive();
-		Glove ReceiveBlocking();
+		void Receive();
 		
 		//Returns the latest glove values in a structure.
 		Glove GetCurrentValues();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GestureRecognition.h	Thu Dec 11 06:08:13 2014 +0000
@@ -0,0 +1,11 @@
+class GestureRecognition
+{
+    public:
+        GestureRecognition();
+        ~GestureRecognition();
+        
+        
+    private:
+      
+    
+};
\ No newline at end of file
--- a/GloveWifi.cpp	Thu Dec 11 05:57:54 2014 +0000
+++ b/GloveWifi.cpp	Thu Dec 11 06:08:13 2014 +0000
@@ -84,7 +84,7 @@
         wait(1);
     }
     socket->set_blocking(false, 10);
-    //printf("Reconnected!\r\n");
+    printf("Reconnected!\r\n");
 }
 
 int GloveWifi::GetDataFromBuffer(char * buf, int size)
@@ -99,8 +99,9 @@
     {
         DropCount = 0;
     }
-    if(DropCount > 100)
+    if(DropCount > 200)
     {
+        printf("!\r\n");
         Reconnect();
         DropCount = 0;
     }
--- a/ledCube.cpp	Thu Dec 11 05:57:54 2014 +0000
+++ b/ledCube.cpp	Thu Dec 11 06:08:13 2014 +0000
@@ -18,11 +18,11 @@
 #define PANEL1             0
 #define PANEL2             1
 #define PANEL3             2
-#define nLEDs              200//MAX_LEDS_PER_STRIP;
-#define nROWs              10
-#define nCOLs              10  
-#define DATA_OUT_PIN1      2 // PTD2
-#define DATA_OUT_PIN2      3 // PTD3 
+#define nLEDs              200 //MAX_LEDS_PER_STRIP;
+#define nROWs              10  //number of rows per cube panel 
+#define nCOLs              10  //number of columns per cube panel
+#define DATA_OUT_PIN1      2   // PTD2
+#define DATA_OUT_PIN2      3   // PTD3 
 
 
 LedCube::LedCube():X(0),Y(1),Z(2),ledStrip1(nLEDs, DATA_OUT_PIN1),ledStrip2(nLEDs, DATA_OUT_PIN2)
@@ -33,6 +33,7 @@
 {
 }
 
+/*Sets the initial size and position of the lighted cube*/ 
 void LedCube::Init(int x, int y, int z)
 {
     size = 2;
@@ -51,6 +52,19 @@
     ledStrip2.begin();
 }
 
+/*Determines which LED should be lit based on its 
+cartesian coordinate. The origin is the led at
+bottom left of panel 1 when using a three panel cube
+     ________
+    /       /|
+   /   3   / |
+  /_______/ 2|
+  |       |  | 
+  |   1   | /
+  |       |
+  --------        
+*/
+
 int LedCube::getLedIndex(int panel, int x, int y) {
     if (panel == PANEL1) {
         if (y % 2 == 0) {
@@ -222,4 +236,14 @@
     if((pos[X] + newSize) < nCOLs && (pos[Y] + newSize) < nCOLs && (pos[Z] + newSize) < nCOLs) {
         size = newSize;
     }
-}
\ No newline at end of file
+}
+
+void LedCube::UpdateCube(int size, int deltaX, int deltaY, int deltaZ, float hue) {
+     changeSize(size);
+     move(deltaX, deltaY, deltaZ); 
+     changeColor(hue); 
+     cubeUpdate(); 
+}
+
+
+
--- a/ledCube.h	Thu Dec 11 05:57:54 2014 +0000
+++ b/ledCube.h	Thu Dec 11 06:08:13 2014 +0000
@@ -13,6 +13,7 @@
         void updateLEDs(bool on, int size, int x, int y, int z);
         void updateLEDsOld(bool on, int size, int x, int y, int z);
         void cubeUpdate();
+        void UpdateCube(int size, int deltaX, int deltaY, int deltaZ, float hue); 
         int move(int deltaX, int deltaY, int deltaZ);
         void changeColor(float hue);
         void changeSize(int newSize);
--- a/main.cpp	Thu Dec 11 05:57:54 2014 +0000
+++ b/main.cpp	Thu Dec 11 06:08:13 2014 +0000
@@ -9,9 +9,6 @@
 
 int main() 
 {
-    long Counter = 0;
-    DigitalOut StatusLED(LED1);
-    StatusLED = 0;
     Serial pc(USBTX, USBRX);
     pc.baud(115200);
     pc.printf("Connceted to PC \r\n");
@@ -19,12 +16,8 @@
     pc.printf("DataGlove Cube Client\r\n");
     while(true) 
     {
-        MasterGlove.ReceiveBlocking();
+        MasterGlove.Receive();
         //pc.printf("Looping \r\n");
         //wait(0.1);
-        if(Counter++%25 == 0)
-        {
-            StatusLED = !StatusLED;
-        }
      }
 }