ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
PID.h
Go to the documentation of this file.
1/**
2 * @file PID.h
3 * @brief Defines the `PID` class for implementing a proportional-integral-derivative controller.
4 *
5 * The `PID` class provides functionality to calculate control outputs based on
6 * proportional, integral, and derivative components of error.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15/**
16 * @class PID
17 * @brief Implements a proportional-integral-derivative (PID) controller.
18 *
19 * This class calculates control outputs based on the error between a setpoint
20 * and a process variable, using configurable proportional, integral, and derivative gains.
21 */
22class PID {
23private:
24 float integral; ///< Integral term accumulator.
25 float error; ///< Current error value.
26 float previousError; ///< Previous error value for derivative calculation.
27 float output; ///< Calculated output value.
28 float kp; ///< Proportional gain.
29 float ki; ///< Integral gain.
30 float kd; ///< Derivative gain.
31 float previousSeconds; ///< Time of the previous calculation in seconds.
32
33public:
34 /**
35 * @brief Default constructor for `PID`, initializes gains to zero.
36 */
37 PID();
38
39 /**
40 * @brief Constructs a `PID` controller with specified gains.
41 *
42 * @param kp Proportional gain.
43 * @param ki Integral gain.
44 * @param kd Derivative gain.
45 */
46 PID(float kp, float ki, float kd);
47
48 /**
49 * @brief Destructor for `PID`.
50 */
51 ~PID();
52
53 /**
54 * @brief Calculates the control output based on the setpoint and process variable.
55 *
56 * This method uses the elapsed time in milliseconds since the last call to calculate the derivative term.
57 *
58 * @param setpoint Desired target value.
59 * @param processVariable Current value of the process variable.
60 * @param currentMillis Current time in milliseconds.
61 * @return Calculated control output.
62 */
63 float Calculate(float setpoint, float processVariable, unsigned long currentMillis);
64
65 /**
66 * @brief Calculates the control output based on the setpoint and process variable.
67 *
68 * This method requires the caller to provide the time delta in seconds since the last calculation.
69 *
70 * @param setpoint Desired target value.
71 * @param processVariable Current value of the process variable.
72 * @param dT Time delta in seconds since the last calculation.
73 * @return Calculated control output.
74 */
75 float Calculate(float setpoint, float processVariable, float dT);
76};
Implements a proportional-integral-derivative (PID) controller.
Definition PID.h:22
float ki
Integral gain.
Definition PID.h:29
float output
Calculated output value.
Definition PID.h:27
float integral
Integral term accumulator.
Definition PID.h:24
float Calculate(float setpoint, float processVariable, unsigned long currentMillis)
Calculates the control output based on the setpoint and process variable.
Definition PID.cpp:25
float kp
Proportional gain.
Definition PID.h:28
float previousSeconds
Time of the previous calculation in seconds.
Definition PID.h:31
float error
Current error value.
Definition PID.h:25
float previousError
Previous error value for derivative calculation.
Definition PID.h:26
PID()
Default constructor for PID, initializes gains to zero.
Definition PID.cpp:3
~PID()
Destructor for PID.
Definition PID.cpp:23
float kd
Derivative gain.
Definition PID.h:30