SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
pid.h
Go to the documentation of this file.
1#ifndef PID_H
2#define PID_H
3
4
5#include "time_utils.h"
6#include "foc_utils.h"
7
8/**
9 * PID controller class
10 */
12{
13public:
14 /**
15 *
16 * @param P - Proportional gain
17 * @param I - Integral gain
18 * @param D - Derivative gain
19 * @param ramp - Maximum speed of change of the output value
20 * @param limit - Maximum output value
21 * @param sampling_time - sampling time
22 *
23 * @note If sampling time is not set the filter will measure the
24 * elapsed time between each call. If yes it will consider it fixed.
25 * @note Sampling time can be changed dynamically as well by modifying the
26 * variable Ts in runtime.
27 */
28 PIDController(float P, float I, float D, float ramp = NOT_SET, float limit = NOT_SET, float sampling_time = NOT_SET);
29 ~PIDController() = default;
30
31 float operator() (float error);
32 void reset();
33
34 float P; //!< Proportional gain
35 float I; //!< Integral gain
36 float D; //!< Derivative gain
37 float output_ramp; //!< Maximum speed of change of the output value
38 float limit; //!< Maximum output value
39 float Ts; //!< Fixed sampling time (optional default NOT_SET)
40
41protected:
42 float error_prev; //!< last tracking error value
43 float output_prev; //!< last pid output value
44 float integral_prev; //!< last integral component value
45 unsigned long timestamp_prev; //!< Last execution timestamp
46};
47
48#endif // PID_H
float operator()(float error)
Definition pid.cpp:18
float output_prev
last pid output value
Definition pid.h:43
unsigned long timestamp_prev
Last execution timestamp.
Definition pid.h:45
float output_ramp
Maximum speed of change of the output value.
Definition pid.h:37
~PIDController()=default
float limit
Maximum output value.
Definition pid.h:38
float error_prev
last tracking error value
Definition pid.h:42
float D
Derivative gain.
Definition pid.h:36
float integral_prev
last integral component value
Definition pid.h:44
float Ts
Fixed sampling time (optional default NOT_SET)
Definition pid.h:39
float P
Proportional gain.
Definition pid.h:34
void reset()
Definition pid.cpp:66
float I
Integral gain.
Definition pid.h:35
#define NOT_SET
Definition foc_utils.h:34