a

Dependencies:   mbed mbed-rtos

Committer:
alexpirciu
Date:
Thu Mar 28 07:44:42 2019 +0000
Revision:
1:ceee5a608e7c
assa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alexpirciu 1:ceee5a608e7c 1 #ifndef PID_CONTROLLER_H
alexpirciu 1:ceee5a608e7c 2 #define PID_CONTROLLER_H
alexpirciu 1:ceee5a608e7c 3
alexpirciu 1:ceee5a608e7c 4 #include <cstdio>
alexpirciu 1:ceee5a608e7c 5 #include <Linalg/linalg.h>
alexpirciu 1:ceee5a608e7c 6 #include <SystemModels/systemmodels.hpp>
alexpirciu 1:ceee5a608e7c 7 #include <mbed.h>
alexpirciu 1:ceee5a608e7c 8
alexpirciu 1:ceee5a608e7c 9 namespace controllers
alexpirciu 1:ceee5a608e7c 10 {
alexpirciu 1:ceee5a608e7c 11 namespace siso
alexpirciu 1:ceee5a608e7c 12 {
alexpirciu 1:ceee5a608e7c 13
alexpirciu 1:ceee5a608e7c 14 /**
alexpirciu 1:ceee5a608e7c 15 * @brief General interface class for the controller
alexpirciu 1:ceee5a608e7c 16 *
alexpirciu 1:ceee5a608e7c 17 * @tparam T type of the variables (float, double)
alexpirciu 1:ceee5a608e7c 18 */
alexpirciu 1:ceee5a608e7c 19 template<class T>
alexpirciu 1:ceee5a608e7c 20 class IController{
alexpirciu 1:ceee5a608e7c 21 public:
alexpirciu 1:ceee5a608e7c 22 virtual T calculateControl(const T&)=0;
alexpirciu 1:ceee5a608e7c 23 virtual void clear()=0;
alexpirciu 1:ceee5a608e7c 24 };
alexpirciu 1:ceee5a608e7c 25
alexpirciu 1:ceee5a608e7c 26 /**
alexpirciu 1:ceee5a608e7c 27 * @brief It generates a discrete transferfunction for realizing a proportional–integral–derivative controller, which is discretized by the Euler’s method.
alexpirciu 1:ceee5a608e7c 28 *
alexpirciu 1:ceee5a608e7c 29 * @tparam T type of the variables (float, double)
alexpirciu 1:ceee5a608e7c 30 */
alexpirciu 1:ceee5a608e7c 31 template<class T>
alexpirciu 1:ceee5a608e7c 32 class CPidController:public IController<T>
alexpirciu 1:ceee5a608e7c 33 {
alexpirciu 1:ceee5a608e7c 34 public:
alexpirciu 1:ceee5a608e7c 35 /* Discrete transfer function type */
alexpirciu 1:ceee5a608e7c 36 using CPidSystemmodelType = systemmodels::lti::siso::CDiscreteTransferFucntion<T,3,3>;
alexpirciu 1:ceee5a608e7c 37
alexpirciu 1:ceee5a608e7c 38 /* Constructor */
alexpirciu 1:ceee5a608e7c 39 CPidController(T f_kp
alexpirciu 1:ceee5a608e7c 40 ,T f_ki
alexpirciu 1:ceee5a608e7c 41 ,T f_kd
alexpirciu 1:ceee5a608e7c 42 ,T f_tf
alexpirciu 1:ceee5a608e7c 43 ,T f_dt);
alexpirciu 1:ceee5a608e7c 44 CPidController(CPidSystemmodelType f_pid,T f_dt);
alexpirciu 1:ceee5a608e7c 45
alexpirciu 1:ceee5a608e7c 46 /* Overloaded operator */
alexpirciu 1:ceee5a608e7c 47 T calculateControl(const T& f_input);
alexpirciu 1:ceee5a608e7c 48 /* Serial callback */
alexpirciu 1:ceee5a608e7c 49 static void staticSerialCallback(void* obj,char const * a, char * b);
alexpirciu 1:ceee5a608e7c 50 /* Initialization */
alexpirciu 1:ceee5a608e7c 51 void clear();
alexpirciu 1:ceee5a608e7c 52 private:
alexpirciu 1:ceee5a608e7c 53 #ifdef CONTROL_TEST_HPP
alexpirciu 1:ceee5a608e7c 54 FRIEND_TEST(PidControlTest,Initialization);
alexpirciu 1:ceee5a608e7c 55 FRIEND_TEST(PidControlTest,Setter);
alexpirciu 1:ceee5a608e7c 56 #endif
alexpirciu 1:ceee5a608e7c 57 /* Controller setting */
alexpirciu 1:ceee5a608e7c 58 void setController(T f_kp
alexpirciu 1:ceee5a608e7c 59 ,T f_ki
alexpirciu 1:ceee5a608e7c 60 ,T f_kd
alexpirciu 1:ceee5a608e7c 61 ,T f_tf);
alexpirciu 1:ceee5a608e7c 62 /* Serial callback implementation */
alexpirciu 1:ceee5a608e7c 63 void serialCallback(char const * a, char * b);
alexpirciu 1:ceee5a608e7c 64
alexpirciu 1:ceee5a608e7c 65
alexpirciu 1:ceee5a608e7c 66
alexpirciu 1:ceee5a608e7c 67 /* Discrete transfer function */
alexpirciu 1:ceee5a608e7c 68 CPidSystemmodelType m_pidTf;
alexpirciu 1:ceee5a608e7c 69
alexpirciu 1:ceee5a608e7c 70
alexpirciu 1:ceee5a608e7c 71 /* delta-time term */
alexpirciu 1:ceee5a608e7c 72 T m_dt;
alexpirciu 1:ceee5a608e7c 73
alexpirciu 1:ceee5a608e7c 74 };
alexpirciu 1:ceee5a608e7c 75 /* Include function definitions */
alexpirciu 1:ceee5a608e7c 76 #include "PidController.inl"
alexpirciu 1:ceee5a608e7c 77 }; // namespace siso
alexpirciu 1:ceee5a608e7c 78 }; // namespace controllers
alexpirciu 1:ceee5a608e7c 79
alexpirciu 1:ceee5a608e7c 80
alexpirciu 1:ceee5a608e7c 81
alexpirciu 1:ceee5a608e7c 82 #endif