Test of pmic GPA with filter

Dependencies:   mbed

Fork of nucf446-cuboid-balance1_strong by RT2_Cuboid_demo

Files at this revision

API Documentation at this revision

Comitter:
pmic
Date:
Tue Apr 10 12:24:57 2018 +0000
Parent:
25:e46687840dd6
Commit message:
correct new functinality

Changed in this revision

GPA.cpp Show annotated file Show diff for this revision Revisions of this file
GPA.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e46687840dd6 -r 492c7ab05e67 GPA.cpp
--- a/GPA.cpp	Mon Apr 09 18:23:10 2018 +0000
+++ b/GPA.cpp	Tue Apr 10 12:24:57 2018 +0000
@@ -30,19 +30,21 @@
            
     instantiate option 2: (for a second, refined frequency grid measurement)
     
-    GPA(float f0, float f1, float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+    GPA(float f0, float f1, float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
     
         f0:       frequency point for the calculation of Aexc0 in Hz (should be chosen like in the first measurement)
         f1:       frequency point for the calculation of Aexc1 in Hz (should be chosen like in the first measurement)
         *fexcDes: sorted frequency point array in Hz
+        NfexcDes: length of fexcDes
         
     instantiate option 3: (for an arbitary but sorted frequency grid measurement)
     
-    GPA(float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+    GPA(float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
     
         *fexcDes: sorted frequency point array in Hz
         Aexc0:    excitation amplitude at fexcDes[0]
         Aexc1:    excitation amplitude at fexcDes[NfexcDes-1]
+        NfexcDes: length of fexcDes
 
     hints:    the amplitude drops with 1/fexc, if you're using Axc1 = Aexc0/fMax then d/dt exc = const.,
               this is recommended if your controller does not have a rolloff. if a desired frequency point
@@ -127,10 +129,10 @@
     reset();
 }
 
-GPA::GPA(float f0, float f1, float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+GPA::GPA(float f0, float f1, float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
 {
     // convert fexcDes from float to double, it is assumed that it is sorted
-    NfexcDes = sizeof(fexcDes)/sizeof(fexcDes[0]);
+    this->NfexcDes = NfexcDes;
     this->fexcDes = (double*)malloc(NfexcDes*sizeof(double));
     for(int i = 0; i < NfexcDes; i++) {
         this->fexcDes[i] = (double)fexcDes[i];
@@ -153,10 +155,10 @@
     reset();
 }
 
-GPA::GPA(float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
+GPA::GPA(float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1)
 {
     // convert fexcDes from float to double, it is assumed that it is sorted
-    NfexcDes = sizeof(fexcDes)/sizeof(fexcDes[0]);
+    this->NfexcDes = NfexcDes;
     this->fexcDes = (double*)malloc(NfexcDes*sizeof(double));
     for(int i = 0; i < NfexcDes; i++) {
         this->fexcDes[i] = (double)fexcDes[i];
@@ -345,4 +347,10 @@
     printLine();
     printf(" number of data points:  %9i\r\n", NmeasTotal);
     printf(" measurment time in sec: %9.2f\r\n", (float)((double)NmeasTotal*Ts));
-}
\ No newline at end of file
+}
+
+void GPA::printNfexcDes()
+{
+    printLine();
+    printf(" number of frequancy points:  %2i\r\n", NfexcDes);
+}
diff -r e46687840dd6 -r 492c7ab05e67 GPA.h
--- a/GPA.h	Mon Apr 09 18:23:10 2018 +0000
+++ b/GPA.h	Tue Apr 10 12:24:57 2018 +0000
@@ -3,8 +3,8 @@
 public:
 
     GPA(float fMin, float fMax, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1);
-    GPA(float f0, float f1, float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1);
-    GPA(float *fexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1);
+    GPA(float f0, float f1, float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1);
+    GPA(float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1);
 
     float operator()(float inp, float out) {
         return update((double)inp, (double)out);
@@ -18,12 +18,13 @@
     void     printGPAfexcDes();
     void     printGPAmeasPara();
     void     printGPAmeasTime();
+    void     printNfexcDes();
 
 private:
 
-    int    NfexcDes;
-    int    NperMin;
-    int    NmeasMin;
+    int     NfexcDes;
+    int     NperMin;
+    int     NmeasMin;
     double  Ts;
     double *fexcDes;
     double  aAexcDes;
@@ -34,24 +35,24 @@
     double  pi2Ts;
     double  piDiv2;
 
-    int    Nmeas;
-    int    Nper;
+    int     Nmeas;
+    int     Nper;
     double  fexc;
     double  fexcPast;
-    int    ii;
-    int    jj;
+    int     ii;
+    int     jj;
     double  scaleG;
     double  cr;
     double  ci;
     double *sU;
     double *sY;
     double  sinarg;
-    int    NmeasTotal;
+    int     NmeasTotal;
     double  Aexc;
     double  pi2Tsfexc;
 
-    void   fexcDesLogspace(double fMin, double fMax, int NfexcDes);
-    void   calcGPAmeasPara(double fexcDes_i);
-    void   printLine();
+    void    fexcDesLogspace(double fMin, double fMax, int NfexcDes);
+    void    calcGPAmeasPara(double fexcDes_i);
+    void    printLine();
 
 };
\ No newline at end of file
diff -r e46687840dd6 -r 492c7ab05e67 main.cpp
--- a/main.cpp	Mon Apr 09 18:23:10 2018 +0000
+++ b/main.cpp	Tue Apr 10 12:24:57 2018 +0000
@@ -30,7 +30,10 @@
 float D = 0.2f;
 IIR_filter pt2(w0, D, Ts, 1.0f);
 
-GPA gpa1(1.0f, 200.0f,50, 5, 100, Ts, 1.0f,1.0f);       // init GPA, see references there
+// GPA gpa1(1.0f, 200.0f, 50, 5, 100, Ts, 1.0f, 1.0f);       // init GPA, see references there
+float  fexcDes[5] = {10.0f, 20.0f, 30.0f, 40.0f, 50.0f};
+// GPA gpa1(1.0f, 200.0f, fexcDes, sizeof(fexcDes)/sizeof(fexcDes[0]), 5, 100, Ts, 1.0f, 1.0f);
+GPA gpa1(fexcDes, sizeof(fexcDes)/sizeof(fexcDes[0]), 5, 100, Ts, 1.0f, 1.0f);
 // user defined functions
 void updateControllers(void);   // speed controller loop (via interrupt)
 void pressed(void);             // user Button pressed
@@ -51,6 +54,17 @@
     gpa1.reset();
     pt2.reset(0.0f);
     
+    gpa1.printGPAmeasPara();
+    /*
+    gpa1.printNfexcDes();
+    printLine();
+    for(int i = 0; i < 5; i++) {
+        printf(" frequancy points:  %9.3f\r\n", fexcDes[i]);
+    }
+    printLine();
+    printf(" number of frequancy points:  %2i\r\n", sizeof(fexcDes)/sizeof(fexcDes[0]));
+    */
+    
     // attach controller loop to timer interrupt
     ControllerLoopTimer.attach(&updateControllers, Ts); //Assume Fs = 400Hz;
 }