Gait detection system for exoskeleton control

Dependencies:   Servo mbed

Revision:
2:786e1897a6ec
Parent:
1:3ce5d2797365
--- a/main.cpp	Tue Feb 21 00:45:21 2017 +0000
+++ b/main.cpp	Fri Feb 24 23:52:23 2017 +0000
@@ -5,6 +5,7 @@
 //Initialize pins
 AnalogIn   ain(p16);
 Serial device(p28,p27);
+Serial pc(USBTX, USBRX);
 Servo actuator(p21);
 
 //Variables
@@ -15,8 +16,13 @@
 float gaitPeriodMean = 0.00f;
 float inputReading = 0.00f;
 float percentage = 0.00f;
-float actuationPercentage = 30.0f;
-Servo myservo(p21);
+//float actuationPercentage = 30.0f;
+int actuationPercentage = 30;
+//char buffer[2];
+int inByte;
+
+Servo myServo(p21);
+PwmOut dcMotor(p22);
 
 //function to calculate the mean 
 float mean (float tab[], int size){
@@ -26,18 +32,19 @@
     }
     return sum/(size-1);
 }
+
 //Servo Motor function
 void ServoActuaute(){
-    for(float p=0; p<1.0; p += 0.2) {
-        myservo = p;
-        wait(0.2);
-    }    
+    myServo.write(0);
+    wait(0.4);
+    myServo.write(0.7);  
 }
 
 int main(void)
 {
     device.baud(57600);
-
+    myServo.write(0);
+    
     while (1) {
         //Check for Serial Event
         if (device.readable()){
@@ -56,7 +63,7 @@
                 
                 //Busy waiting for 1st heel strike
                 while (inputReading < 0.20f){
-                    device.putc(110);//equivalent to printf("n")
+                    device.printf("n|n");//equivalent to printf("n")
                     wait_ms(10);
                     inputReading = ain.read();
                     wait_ms(20);
@@ -83,7 +90,7 @@
                             //mean =(gaitPeriod[2]+gaitPeriod[3]+gaitPeriod[4]+gaitPeriod[5]+gaitPeriod[6])/5.0f;
                             gaitPeriodMean = mean(gaitPeriod,6);
                             //device.printf("Gait period: %1.2f\r\n", mean);
-                            device.printf("m|%1.2f", gaitPeriodMean);
+                            device.printf("|%1.2f", gaitPeriodMean);
                             wait_ms(30);
                             gaitCounter = 100;//get out of While
                         }                                                          
@@ -98,15 +105,26 @@
                 inputReading = ain.read();
                 wait_ms(20);
                 
+                //get the actuation timing
+                //inByte = device.getc();
+                //
+                //actuationPercentage = atoi(buffer);
+                //pc.printf("inByte: ");
+                //pc.printf("%d",inByte);
+                //pc.printf("\n\r");
+                //pc.printf("actuationPercentage: ");
+                //pc.printf("%d",actuationPercentage);pc.printf("\n\r");
+                
+                
+                
                 //Busy waiting for the first heel strike to occur
                 while(inputReading<0.20f){
                     inputReading = ain.read();
                     wait_ms(20);
+                    device.printf("n|w");
                     //device.printf("I am in empty While B\r\n");
-                    }
-      
-                //device.printf("I just get out of Empty While\r\n");
-                
+                }
+                    
                 //Re-initialize gaitCounter to Zero to start a new cycle
                 percentage = 0;
                 t.reset();
@@ -136,7 +154,6 @@
                     
                     if (percentage >= actuationPercentage - 0.2 && percentage <= actuationPercentage + 0.2){
                         ServoActuaute();
-                        device.printf("s|s");
                     }
                         
                     //Check if the user wants to stop the system  
@@ -149,13 +166,6 @@
                             wait_ms(10);
                             t.stop();t.reset();t.start();
                         }
-                        /*/Check for motor actuation request
-                        else if(command == 'c'){
-                            if (percentage == actuationPercentage){
-                                ServoActuaute();
-                                device.printf("s|s");
-                            }
-                        }*/
                     }
                 }
              break;