Julius Bernth / Mbed OS Cuvette_Centrifuge_Test_v1-2_ParallelMode

Dependencies:   QEI LIS3DH_spi

Revision:
11:62d2a592b1ae
Parent:
10:8a41143a9f52
Child:
12:bc34f264e2f2
--- a/main.cpp	Thu Aug 12 13:58:10 2021 +0000
+++ b/main.cpp	Thu Aug 12 15:15:32 2021 +0000
@@ -170,7 +170,7 @@
             Tnow = testTimer.read();
             //check accel. If problem, change state to ERROR
             //check accel here
-            //printf("x\r\n");
+            
             /*
             Ax = 0.2*pinAx.read() + 0.8*Ax - 0.5;
             Ay = 0.2*pinAy.read() + 0.8*Ay - 0.5;
@@ -223,6 +223,10 @@
                 //deactivate motor?
             }
             
+/*            if(state == STATE_ERROR){
+                demandSpeed_RPM -=66.7*SAMPLE_TIME_US/1000000;
+            }*/
+            
             demandSpeed_RPM = LimitDouble(demandSpeed_RPM,0.0,MAX_SPEED_RPM);//limit demand
             currentPulses = encoder.getPulses();//calculate current speed
             double deltaPulses = currentPulses - lastPulses;
@@ -251,8 +255,12 @@
                 PHA.write(1);
                 output = -1*output;
             }
+            
+/*            if(state == STATE_ERROR){
+                output = 0;
+            }*/
+                
             PWMA.write(output);//write to motor
-            
             lastPulses = currentPulses;//update 
             lastError = error;
             lastSpeedRPM = currentSpeedRPM;
@@ -286,7 +294,7 @@
                 //CentrifugeTestThread.terminate();//terminate threads
             }
         } //end running conditional
-        else{
+        /*else{
             Tnow = 0.0;
             state = STATE_READY;//change state
             testTimer.stop(); //stop and reset timers
@@ -308,7 +316,7 @@
             lastErrorDot = 0.0;
             lastError = 0.0;
             integralTerm = 0.0;
-        } 
+        } */
     }
 }
 
@@ -316,9 +324,6 @@
     while(1){    
         semStartTest.wait();
         printf("\r\n Test starting \r\n");
-        
-        //check if motor is spinning
-        
         state = STATE_RUNNING;
         //set up test
         testTimer.reset();
@@ -332,7 +337,7 @@
         lastPulses = 0;//reset previous encoder reading
         encoderTimer.start();
         PrintThread.start(PrintTimeRemaining);
-        printf("\r\n Test setup complete \r\n");
+        printf("\r\n Test setup complete, State:%d \r\n", state);
         EN_FAULTA.write(1);
         //EN_FAULTB.write(1);
         if(state == STATE_RUNNING){
@@ -373,7 +378,13 @@
                 pinLedRed = 1;
             }
             if (count ==1){
-                printf("Button pressed. Hold for %f s\r\n",BUTTON_HOLD_TIME_S);
+                if(state == STATE_READY){
+                    printf("Button pressed. Hold for %f s\r\n",BUTTON_HOLD_TIME_S);
+                }
+                else if(state == STATE_RUNNING){
+                    printf("Test terminated by user. Please restart system.\r\n");
+                    state = STATE_ERROR;
+                }
             }
             ThisThread::sleep_for(10);
         }
@@ -395,8 +406,8 @@
                 break;
             case STATE_RUNNING:
                 if(count >1){
-                    EN_FAULTA.write(0);
-                    EN_FAULTB.write(0);
+                    //EN_FAULTA.write(0);
+//                    EN_FAULTB.write(0);
                     state = STATE_ERROR;
                     //EN_FAULTB.write(0);
                 }