Library for control puposes

Dependents:  

Fork of Cntrl_Lib by Ruprecht Altenburger

Files at this revision

API Documentation at this revision

Comitter:
pmic
Date:
Thu Feb 07 09:08:47 2019 +0000
Parent:
11:76538cb0bb96
Commit message:
Add new default istantiate option for GPA

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
diff -r 76538cb0bb96 -r c8ec698c53ed GPA.cpp
--- a/GPA.cpp	Mon Jan 07 13:46:28 2019 +0000
+++ b/GPA.cpp	Thu Feb 07 09:08:47 2019 +0000
@@ -1,12 +1,28 @@
 /*
-    GPA: Frequency point wise gain and phase analyser to measure the frequency
-         respone function (FRF) of a dynamical system
+    GPA: Frequency point wise gain and phase analyser to measure the frequency respone function (FRF) of a dynamical system, based on the one point DFT
+
+         Hint:        If the plant has a pole at zero, is unstable or weakly damped the measurement has to be perfomed
+                      in closed loop (this is NOT tfestimate, the algorithm is based on the one point DFT).
+         Assumption:  The system is and remains at the desired steady state of interest when the measurment starts
 
-         Hint:       If the plant has a pole at zero, is unstable or weakly damped the measurement has to be perfomed in closed loop
-         Assumption: The system is at the desired steady state of interest when the measurment starts
+    Instantiate option 0: ("Not a Jedi yet" users, for logarithmic equaly spaced frequency points)
+    
+        GPA(float fMin, float fMax, int NfexcDes, float Aexc0, float Aexc1, float Ts)
+        
+            fMin:       Minimal desired frequency that should be measured in Hz
+            fMax:       Maximal desired frequency that should be measured in Hz
+            NfexcDes:   Number of logarithmic equaly spaced frequency points between fMin and fMax
+            Aexc0:      Excitation amplitude at fMin
+            Aexc1:      Excitation amplitude at fMax
+            Ts:         Sampling time in sec
+            
+            Default values are as follows:
+            int NperMin   = 3;
+            int NmeasMin  = (int)ceil(1.0f/Ts);
+            int NstartMin = (int)ceil(3.0f/Ts);
+            int NsweepMin = 0;
 
-
-    Instantiate option 1: (logarithmic equaly spaced frequency points)
+    Instantiate option 1: ("Jedi or Sith Lord", for logarithmic equaly spaced frequency points)
     
         GPA(float fMin, float fMax, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1, int NstartMin, int NsweepMin)
         
@@ -15,7 +31,7 @@
             NfexcDes:   Number of logarithmic equaly spaced frequency points
             NperMin:    Minimal number of periods that are used for each frequency point
             NmeasMin:   Minimal number of samples that are used for each frequency point
-            Ts:         Sampling time
+            Ts:         Sampling time in sec
             Aexc0:      Excitation amplitude at fMin
             Aexc1:      Excitation amplitude at fMax
             NstartMin:  Minimal number of samples to sweep to the first frequency point (can be equal 0)
@@ -30,7 +46,8 @@
             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
-
+            
+            For the other parameters see above.
 
     Instantiate option 3: (for an arbitary but sorted frequency grid measurement)
     
@@ -40,11 +57,12 @@
             Aexc0:      Excitation amplitude at fexcDes[0]
             Aexc1:      Excitation amplitude at fexcDes[NfexcDes-1]
             NfexcDes:   Length of fexcDes
-
+            
+            For the other parameters see above.
 
-    Note:     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
-              is not measured try to increase Nmeas (could not be reached).
+    Note:   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
+            is not measured (could not be reached) try to increase Nmeas.
               
         
     Block diagram:
@@ -145,6 +163,25 @@
 //      instantiate
 // -----------------------------------------------------------------------------
 
+GPA::GPA(float fMin, float fMax, int NfexcDes, float Aexc0, float Aexc1, float Ts)
+{
+    int NperMin = 3;
+    int NmeasMin = (int)ceil(1.0f/Ts);
+    int NstartMin = (int)ceil(3.0f/Ts);
+    int NsweepMin = 0;
+    
+    assignParameters(NfexcDes, NperMin, NmeasMin, (double)Ts, NstartMin, NsweepMin);
+
+    // calculate logarithmic spaced frequency points
+    fexcDes = (double*)malloc(NfexcDes*sizeof(double));
+    fexcDesLogspace((double)fMin, (double)fMax, NfexcDes);
+
+    calculateDecreasingAmplitudeCoefficients((double)Aexc0, (double)Aexc1);
+    initializeConstants((double)Ts);
+    assignFilterStorage();
+    reset();
+}
+
 GPA::GPA(float fMin, float fMax, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1, int NstartMin, int NsweepMin)
 {
     assignParameters(NfexcDes, NperMin, NmeasMin, (double)Ts, NstartMin, NsweepMin);
diff -r 76538cb0bb96 -r c8ec698c53ed GPA.h
--- a/GPA.h	Mon Jan 07 13:46:28 2019 +0000
+++ b/GPA.h	Thu Feb 07 09:08:47 2019 +0000
@@ -1,7 +1,8 @@
 class GPA
 {
 public:
-
+    
+    GPA(float fMin, float fMax, int NfexcDes, float Aexc0, float Aexc1, float Ts);
     GPA(float fMin, float fMax, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1, int NstartMin, int NsweepMin);
     GPA(float f0, float f1, float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1, int NstartMin, int NsweepMin);
     GPA(float *fexcDes, int NfexcDes, int NperMin, int NmeasMin, float Ts, float Aexc0, float Aexc1, int NstartMin, int NsweepMin);