presentatie versie met potmeters enabled

Dependencies:   Encoder HIDScope mbed

Revision:
6:30afff8ae34a
Parent:
5:ad4ae6b65474
Child:
7:acf28eb906c4
--- a/main.cpp	Thu Oct 29 10:33:03 2015 +0000
+++ b/main.cpp	Thu Oct 29 11:15:29 2015 +0000
@@ -3,7 +3,7 @@
 #include "HIDScope.h"
 #include "math.h"
 
-HIDScope scope(4);          // definieerd het aantal kanalen van de scope
+HIDScope scope(4);          // defines the amount of channels of the scope
 
 // Define Tickers and control frequencies
 Ticker          controller1, controller2, main_filter, cartesian;
@@ -19,11 +19,11 @@
 
 //////////////////////// IN-OUTPUT /////////////////////////////////////////////
 //MOTOR OUTPUTPINS
-    PwmOut motor1_aan(D6), motor2_aan(D5);      // PWM signaal motor 2 (uit sheets)
-    DigitalOut motor1_rich(D7), motor2_rich(D4); // digitaal signaal voor richting
+    PwmOut motor1_aan(D6), motor2_aan(D5);      // PWM signaal motor 2
+    DigitalOut motor1_rich(D7), motor2_rich(D4); // digitaal signaal for direction
 
 // ENCODER INPUTPINS
-    Encoder motor1_enc(D12,D11), motor2_enc(D10,D9);        // encoder outputpins
+    Encoder motor1_enc(D12,D11), motor2_enc(D10,D9);        // encoderinputpins
 
 // EXTRA INPUTS AND REQUIRED VARIABLES
 //POTMETERS (used for debugging purposes, not reliable anymore)
@@ -31,23 +31,21 @@
     AnalogIn potleft(A5);
     
 // Analoge input signalen defineren
-    AnalogIn    EMG_in(A0);                 // EMG_in.read kan je nu gebruiken om het analoge signaal A2 uit te lezen
-    AnalogIn    EMG_int(A2);                // deze leest A3 uit
+    AnalogIn    EMG_in(A0);
+    AnalogIn    EMG_int(A2);
 
 // BUTTONS 
     // control flow             
-    DigitalIn   buttonlinks(PTA4);       
-    DigitalIn   buttonrechts(PTC6);
-    DigitalIn   reset_button(D1);
+    DigitalIn   buttonlinks(PTA4);       // button for starting the motor controller
+    DigitalIn   buttonrechts(PTC6);     // button for startin calibration procedures
+    DigitalIn   reset_button(D1);       // button for returning the arm to the start position
+    DigitalIn   program_button(D0);     // button for starting a preprogrammed movement. (pick up cup)
         // init values
         bool loop_start = false;
         bool calib_start = false;
         bool reset = false;
+        bool program = false;
         
-    // axis control
-    DigitalIn   program_button(D0);
-        // init values
-        bool program = false;
 // LED outputs on bioshield
     DigitalOut led_right(D2);
 // LED outputs on dev-board
@@ -60,9 +58,11 @@
 ////////////////////////// GLOBAL VARIABLES ///////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////////////////
 
-    bool switch_xy = false; // bool for switching
+// switch axes
+    bool switch_xy = false; // bool for switching axes
     double sw1 = 0; // counter for switching axes
     double t_switch = 0.6; // seconds for switching
+    
 // physical constants
     const double L = 36;           // lenght of arms
     const double pi = 3.1415926535897;      // pi
@@ -128,7 +128,7 @@
     // motor 2
     const double m2_Kp = 3;
     const double m2_Ki = 0.5;
-    const double m2_Kd = 0.3;
+    const double m2_Kd = 0.4;
 // storage variables.   these variables are used to store data between controller iterations
     // motor 1
     double m1_err_int = 0; 
@@ -137,7 +137,7 @@
     double m2_err_int = 0;
     double m2_prev_err = 0;
 
-// EMG calibration variables
+// EMG calibration variables (standard is 7)
 double emg_gain1 = 7;       
 double emg_gain2 = 7;
 
@@ -147,7 +147,7 @@
 
 // FILTER VARIABLES
     // storage variables
-        // differential action filter, same is used for both PID controllers
+        // differential action filter, same is used for PID controllers
             double m_f_v1 = 0, m_f_v2 = 0;
         // input filter to smooth angle reference signals
             double r1_f_v1 = 0, r1_f_v2 = 0, r2_f_v1 = 0, r2_f_v2 = 0;