Jorn Dokter / Mbed 2 deprecated TEB_branch2

Dependencies:   mbed QEI HIDScope biquadFilter MODSERIAL FastPWM

Files at this revision

API Documentation at this revision

Comitter:
JornD
Date:
Mon Oct 14 11:46:35 2019 +0000
Parent:
33:5e2e95c322da
Child:
41:7c4c41326cc6
Commit message:
Added some files and commented out Jordan's code;

Changed in this revision

controller.cpp Show annotated file Show diff for this revision Revisions of this file
controller_copy.cpp Show annotated file Show diff for this revision Revisions of this file
functions.h Show annotated file Show diff for this revision Revisions of this file
global.h Show diff for this revision Revisions of this file
header.h Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
motorAndSensorControl.cpp Show annotated file Show diff for this revision Revisions of this file
structures.h Show annotated file Show diff for this revision Revisions of this file
--- a/controller.cpp	Wed Oct 09 15:26:54 2019 +0000
+++ b/controller.cpp	Mon Oct 14 11:46:35 2019 +0000
@@ -1,25 +1,8 @@
-//Gains
-double e = 1.02; 
-double Ts = 0.92;
+#include "structures.h"
 
-    double K_p = 1;//Position gain
-    double K_i = 1;//Integral gain
-    double K_d = 1;//Diverentiation gain
-    
-    //static double u_i = 0;
-    static double e_Prev = 0;
-
-double ControllerPID(double e, double Ts)
+void InitializeControllers(void)
 {
-    double u_p = K_p*e;               //Position action
-    double u_i = K_i*(e*Ts+u_i);      //Integral action
-    double u_d = K_d*((e-e_Prev)/Ts);   //Diverential action
-    
-    e_Prev = e; //Write error to previous error
+    ControllerSettings SetOne;
+    MemoryIO MemOne;
     
-    double u;
-    
-    u = u_p + u_i + u_d;
-    
-    return u;
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/controller_copy.cpp	Mon Oct 14 11:46:35 2019 +0000
@@ -0,0 +1,25 @@
+//Gains
+double e = 1.02; 
+double Ts = 0.92;
+
+    double K_p = 1;//Position gain
+    double K_i = 1;//Integral gain
+    double K_d = 1;//Diverentiation gain
+    
+    //static double u_i = 0;
+    static double e_Prev = 0;
+
+double ControllerPID(double e, double Ts)
+{
+    double u_p = K_p*e;               //Position action
+    double u_i = K_i*(e*Ts+u_i);      //Integral action
+    double u_d = K_d*((e-e_Prev)/Ts);   //Diverential action
+    
+    e_Prev = e; //Write error to previous error
+    
+    double u;
+    
+    u = u_p + u_i + u_d;
+    
+    return u;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/functions.h	Mon Oct 14 11:46:35 2019 +0000
@@ -0,0 +1,25 @@
+#ifndef header_h
+#define header_h
+int AddInt(int a, int b);
+
+double ControllerPID(double e, double Ts); //e = error, Ts = sampling time
+//void motorAndEncoder(float PWM1, float PWM2, float dt);
+
+
+    
+    //Define global variables
+    extern double X; //Input from EMG, signal X
+    
+    //Define structures
+
+
+#endif
+
+//double motorAndEncoder(float voltage1, float periodMotor1, float voltage2, float periodMotor2, float dt,  float &countsMotor1Return, float &countsMotor2Return, float &velocityMotor1Return, float &velocityMotor2Return);
+    //voltage in PWM (between -1 and 1), -1 for negative direction full power, 1 for positive direction full power
+    //period in seconds
+    //dt the time between measurements, i.o.w. Ticker timing, for velocity calculation
+    //Returns (velocityMotor1, velocityMotor2, countsMotor1[1], countsMotor2[0])
+        //Velocity in radians/s
+        
+//double ProcessEMG(double X);
\ No newline at end of file
--- a/global.h	Wed Oct 09 15:26:54 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-#ifndef global_h
-#define global_h
-
-
-
-#endif
\ No newline at end of file
--- a/header.h	Wed Oct 09 15:26:54 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#ifndef header_h
-#define header_h
-int AddInt(int a, int b);
-
-double ControllerPID(double e, double Ts); //e = error, Ts = sampling time
-//void motorAndEncoder(float PWM1, float PWM2, float dt);
-
-    //Structures
-    struct motorReturnSub
-    {
-        int counts;
-        float angle;
-        float velocity;
-    };
-    
-    struct motorData
-    {
-        motorReturnSub motor1;
-        motorReturnSub motor2;
-        motorReturnSub motor3;
-    };
-    
-    //Define global variables
-    extern double X; //Input from EMG, signal X
-    
-    //Define structures
-    extern motorData motorReturn; 
-
-#endif
-
-//double motorAndEncoder(float voltage1, float periodMotor1, float voltage2, float periodMotor2, float dt,  float &countsMotor1Return, float &countsMotor2Return, float &velocityMotor1Return, float &velocityMotor2Return);
-    //voltage in PWM (between -1 and 1), -1 for negative direction full power, 1 for positive direction full power
-    //period in seconds
-    //dt the time between measurements, i.o.w. Ticker timing, for velocity calculation
-    //Returns (velocityMotor1, velocityMotor2, countsMotor1[1], countsMotor2[0])
-        //Velocity in radians/s
-        
-//double ProcessEMG(double X);
\ No newline at end of file
--- a/main.cpp	Wed Oct 09 15:26:54 2019 +0000
+++ b/main.cpp	Mon Oct 14 11:46:35 2019 +0000
@@ -7,8 +7,8 @@
     
 //Homebrew libraries
 
-    //#include "global.h"
-    #include "header.h"
+    #include "structures.h"
+    #include "functions.h"
 
 
 //Objects
--- a/motorAndSensorControl.cpp	Wed Oct 09 15:26:54 2019 +0000
+++ b/motorAndSensorControl.cpp	Mon Oct 14 11:46:35 2019 +0000
@@ -2,11 +2,14 @@
 //period in seconds
 //dt the time between measurements, i.o.w. Ticker timing 
 
+/*
 #include "mbed.h"
 #include "FastPWM.h"
 #include "QEI.h"
-#include "global.h"
-#include "header.h"
+#include "functions.h"
+#include "structures.h"
+
+    extern motorData motorReturn; 
 
 //Objects
     //Motors
@@ -85,3 +88,4 @@
     motorReturn.motor1.velocity = velocityMotor1;
     motorReturn.motor2.velocity = velocityMotor2;
 }
+*/
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/structures.h	Mon Oct 14 11:46:35 2019 +0000
@@ -0,0 +1,38 @@
+#ifndef global_h
+#define global_h
+
+//Structures
+//--Motor data
+    struct motorReturnSub
+    {
+        int counts;
+        float angle;
+        float velocity;
+    };
+    
+    struct motorData
+    {
+        motorReturnSub motor1;
+        motorReturnSub motor2;
+        motorReturnSub motor3;
+    };
+//--PID controller settings
+    struct ControllerSettings //Controller settings of the discrete TF
+    {
+        float A;
+        float B;
+        float C;
+        float D;
+        float E;
+    };
+//--Memory of Input/Output
+    struct MemoryIO
+    {
+        float dY;   //output, delayed once
+        float ddY;  //output, delayed twice
+        float dX;   //input, delayed once
+        float ddX;  //input, delayed twice
+    };   
+
+
+#endif
\ No newline at end of file