Goed werkende PID, vanaf nu dit script gebruiken.

Dependencies:   Encoder HIDScope MODSERIAL mbed

Revision:
2:d04df4be6cf7
Parent:
1:d9cfdc904b10
--- a/main.cpp	Fri Oct 16 13:41:47 2015 +0000
+++ b/main.cpp	Mon Oct 19 09:18:40 2015 +0000
@@ -25,8 +25,8 @@
 bool checkButtonStateY_go = false;
 bool Filter_go = false;
 
-DigitalIn telknopX(SW2);
-DigitalIn telknopY(SW3);
+//DigitalIn telknopX(SW2);
+//DigitalIn telknopY(SW3);
 DigitalOut ledX(D2);
 DigitalOut ledY(D3);
 
@@ -123,6 +123,9 @@
 {
     double reademg1 = emg1.read();
     double reademg2 = emg2.read();
+    scope.set(0, reademg1);
+    scope.set(1, reademg2);
+    scope.send();
     double h1_emg1 = High_1_Filter1.step(reademg1);
     high[0] = High_2_Filter1.step(h1_emg1);
     double h1_emg2 = High_1_Filter2.step(reademg2);
@@ -152,8 +155,8 @@
     signal2 = filtered_notch2/max2;
     //scope.set(2, filtered_notch1);
     //scope.set(3, filtered_notch2);
-    scope.set(0, signal1);
-    scope.set(1, signal2);
+    //scope.set(0, reademg1);
+    //scope.set(1, reademg2);
     scope.send();
 }
 
@@ -203,27 +206,27 @@
 
 void Amplitude() //true is aangespanen, false is niet aangespannen. met 2 thresholds. Dit moet nog in procent worden omgezet!
 {
-    if(start == false && filtered_notch1< 0.6) {   //moeten waarden 70 en 20 worden als drempelwaarden
+    if(start == false && signal1< 0.6) {   //moeten waarden 70 en 20 worden als drempelwaarden
         start = true;
         //printf("start 0 \n\r");
     }
-    if (start == true && filtered_notch1<0.6) {
+    if (start == true && signal1<0.6) {
         start = true;
         //printf("start 1\n\r");
     }
-    if (start == true && filtered_notch1< 0.2) {
+    if (start == true && signal1< 0.2) {
         start = false;
         //printf("start 1\n\r");
     }
-    if (start == false && filtered_notch1 <0.2) {
+    if (start == false && signal1 <0.2) {
         start = false;
         //printf("start 0\n\r");
     }
-    if (start == true && filtered_notch1 <0.6 && filtered_notch1>0.2) {
+    if (start == true && signal1 <0.6 && signal1>0.2) {
         start = true;
         //printf("start 1\n\r");
     }
-    if (start == false && filtered_notch1 <0.6 && filtered_notch1>0.2) {
+    if (start == false && signal1 <0.6 && signal1>0.2) {
         start = false;
         //printf("start 0\n\r");
     }
@@ -358,7 +361,7 @@
 }
 
 //-------------------------- POSITIEBEPALING --------------------------//
-
+/*
 void checkButtonStateX()
 {
     if (buttonReleasedX(telknopX)) {
@@ -372,7 +375,7 @@
         countStateY = -countStateY;
     }
 }
-
+*/
 void countStepX()
 {
     if (start == true) {
@@ -402,22 +405,24 @@
     motor1_PID_Controller_go = true; 
 }
 
-void countStepX_activate(){
+/*void countStepX_activate(){
     countStepX_go = true; 
 }
-
-void checkButtonStateX_activate(){
+*/
+void checkButtonState_activate(){
     checkButtonStateX_go = true; 
+    checkButtonStateY_go = true;
 }
-
+/*
 void countStepY_activate(){
     countStepY_go = true; 
 }
 
+
 void checkButtonStateY_activate(){
     checkButtonStateY_go = true;
 }
-
+*/
 void Filter_activate(){
     Filter_go = true;
 }
@@ -427,19 +432,13 @@
     pc.baud(9600);
     encoder1.setPosition(0);
     encoder2.setPosition(0);
-    /*myControllerTicker1.attach( &motor1_PID_Controller, 0.005f ); //Ticker roept elke 0.01 s de motor2 controller aan. = 100Hz
-    myControllerTicker2.attach( &motor2_PI_Controller, 0.01f);
-    countStepTickerX.attach( &countStepX,1.0f );
-    countStepTickerY.attach( &countStepY,1.0f);
-    buttonStateCheckX.attach( &checkButtonStateX,0.001f);
-    buttonStateCheckY.attach( &checkButtonStateY,0.001f);
-    */
+    
     myControllerTicker1.attach( &motor1_PID_Controller_activate, 0.01f);   // Function@ hz
-    countStepTickerX.attach( &countStepX_activate, 1.0f);                 // Function@ hz
-    countStepTickerY.attach( &countStepY_activate, 1.04f);                 // Function@ hz
-    buttonStateCheckX.attach( &checkButtonStateX_activate, 0.001f);         // Function@ hz
-    buttonStateCheckY.attach( &checkButtonStateY_activate, 0.001f);            // Function@ hz
-
+    //countStepTickerX.attach( &countStepX_activate, 1.0f);                 // Function@ hz
+    //countStepTickerY.attach( &countStepY_activate, 1.04f);                 // Function@ hz
+    //buttonStateCheckX.attach( &checkButtonStateX_activate, 0.001f);         // Function@ hz
+    //buttonStateCheckY.attach( &checkButtonStateY_activate, 0.001f);            // Function@ hz
+    //buttonStateCheck.attach( &checkButtonState_activate,0.001f);
 
 //EMG-gedeelte
     led_green.write(1);
@@ -461,6 +460,7 @@
             motor1_PID_Controller_go = false;
             motor1_PID_Controller();
         }
+        /*
         if(countStepX_go) {
             countStepX_go = false;
             countStepX();
@@ -469,6 +469,7 @@
             countStepY_go = false;
             countStepY();
         }
+        
         if(checkButtonStateX_go) {
             checkButtonStateX_go = false;
             checkButtonStateX();
@@ -477,6 +478,7 @@
             checkButtonStateY_go = false;
             checkButtonStateY();
         }
+        */
         if(Filter_go) {
             Filter_go = false;
             Filter();