motor_controller
PIV.hpp
Go to the documentation of this file.
1 //
2 // C++ Interface: PIV
3 //
4 // Description:
5 //
6 //
7 // Author: <Ajish Babu>, (C) 2009
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 #ifndef CONTROLLERPIVCONTROLLER_H
13 #define CONTROLLERPIVCONTROLLER_H
14 
15 #include "SimpleIntegrator.hpp"
16 
17 namespace motor_controller
18 {
19  struct PIVSettings {
20  double Kpp;
21  double Kiv;
22  double Kpv;
23  double Kvff;
24  double Kaff;
25  double Kalp;
26  double Ts;
27  double YMin;
28  double YMax;
29  double Kt;
30  PIVSettings() : Kpp(0),Kiv(0),Kpv(0),Kvff(0),Kaff(0),Kalp(0),Ts(0.1),
31  YMin(0), YMax(0), Kt(0) {}
32  };
33 
34  class PIV
35  {
36  public:
37  PIV();
38  PIV( double _Kpp, double _Kiv, double _Kpv,
39  double _Kvff, double _Kaff,
40  double _Kalp,
41  double _Ts,
42  double _YMin = 0, double _YMax = 0,
43  double _Kt = 0);
44  PIV ( const struct PIVSettings& _settings );
45 
46  ~PIV();
47 
48  void setGains ( double _Kpp, double _Kiv, double _Kpv ); // Sets the PIV gains
49  void setFeedForwardGain( double _Kvff=0.0, double _Kaff=0.0 ){ Kvff = _Kvff; Kaff = _Kaff; };
50  void setVelSmoothingGain( double _Kalp ) { Kalp = _Kalp; };
51  void setSamplingTime (double _Ts);
52  void setOutputLimits ( double _YMin, double _YMax ){ YMin = _YMin; YMax = _YMax; }; // Sets the max and min output limits
53  void setPositionController(bool _status) { posController = _status; };
54  void setIntegratorWindupCoeff (double _Kt) { Kt = _Kt; }; // Sets the intergrator wind up coefficients
55  void setPIVSettings ( const struct PIVSettings& _settings );
56  double getSmoothenedVelocity() { return velSmooth; };
57  double getVelocity() { return velComputed; }
58  bool isSaturated() { return bSaturated; }
59 
60  double getPosCommand() { return posCommand; }
61 
62  double saturate_windup(double _value); // Saturates the input based on YMin and YMax returns the excess value
63  double saturate ( double _val );
64  void reset();
65 
66  double updateVelLoop ( double _velMeasured, double _velCmd, double _posCmd, double accFF=0.0 ); // update velocity loop
67  double updatePosLoop ( double _posError ) const { return Kpp * (_posError); }; // updates position loop
68 
69  double update ( double _posMeasured, double _posRef, double _velFF = 0.0, double _accFF = 0.0 );
70 
71  void printCoefficients();
72 
73  double getKvff () { return Kvff; }
74  double getKpp () { return Kpp; }
75 
76 
77  private:
78  double Kpp; // Proportional Position loop
79  double Kiv; // Intergral Velocity loop
80  double Kpv; // Proportional Position loop
81 
82  double Kvff; // Velocity feed forward
83  double Kaff; // Acceleration feed forward
84  double Kalp; // Smoothing factor for velocity input 0 <= Ka1 < 1
85 
86  double Kt; // Anti-integrator-windup coefficient
87  double limitDiff; // Stores the difference in the saturation
88 
89  double Ts; // Sampling time
90 
91  double YMax; // Maximum output value
92  double YMin; // Minimum output value
93 
94  double velPrevStep; // Velocity from previous step for filtering
95  double posPrevStep; // Position from the previous step for velocity calculation
96 
97  bool posController; // Activate or deactivate position controller
98  bool firstRun; // To check if it is the first run
99  bool bSaturated; // True if the last run was saturated
100 
101  double posCommand; // Generated position command
102  double velComputed; // Velocity computed from the position input
103 
104  double velSmooth; // Smoothened velocity
105  double velCommand; // the velocity command
106 
107  SimpleIntegrator velITerm; // Integral term
108  };
109 
110 }
111 
112 #endif
double updatePosLoop(double _posError) const
Definition: PIV.hpp:67
double Ts
Sampling Time.
Definition: PIV.hpp:26
void setFeedForwardGain(double _Kvff=0.0, double _Kaff=0.0)
Definition: PIV.hpp:49
double getSmoothenedVelocity()
Definition: PIV.hpp:56
double Kt
Anti-Windup Coefficient.
Definition: PIV.hpp:29
void setOutputLimits(double _YMin, double _YMax)
Definition: PIV.hpp:52
Definition: InputShaper.hpp:22
Definition: PIV.hpp:19
Definition: SimpleIntegrator.hpp:33
double Kaff
Acceleration Feedforward Gain.
Definition: PIV.hpp:24
double getKpp()
Definition: PIV.hpp:74
PIVSettings()
Definition: PIV.hpp:30
double Kalp
Velocity Estimation Smoothing Factor.
Definition: PIV.hpp:25
double Kpp
Position Proportional Gain.
Definition: PIV.hpp:20
double Kpv
Velocity Proportional Gain.
Definition: PIV.hpp:22
void setPositionController(bool _status)
Definition: PIV.hpp:53
double YMax
Upper Output Limit.
Definition: PIV.hpp:28
double getPosCommand()
Definition: PIV.hpp:60
void setIntegratorWindupCoeff(double _Kt)
Definition: PIV.hpp:54
double Kvff
Velocity Feedforward Gain.
Definition: PIV.hpp:23
double getKvff()
Definition: PIV.hpp:73
double Kiv
Velocity Integral Gain.
Definition: PIV.hpp:21
Definition: PIV.hpp:34
double getVelocity()
Definition: PIV.hpp:57
double YMin
Lower Output Limit.
Definition: PIV.hpp:27
bool isSaturated()
Definition: PIV.hpp:58
void setVelSmoothingGain(double _Kalp)
Definition: PIV.hpp:50