FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
PidWithExternalState.h
1#pragma once
2
3#include <limits>
4
7{
8 double P = 0.0;
9 double I = 0.0;
10 double D = 0.0;
11
12 double minOut = -std::numeric_limits<double>::infinity();
13 double maxOut = std::numeric_limits<double>::infinity();
14
15 double initOutput = 0.0;
16 double maxIntegratorPart = std::numeric_limits<double>::infinity();
17 double maxDerivativePart = std::numeric_limits<double>::infinity();
18};
19
44{
45public:
46 void Initialize(const PidSettings& settings);
47
50 double Output(double error, double integratedError, double time) const;
51
53 double IntegralRate(double error, double integratedError) const;
54
56 void Accept(double error, double time);
57
58private:
59 double IntegralPart(double integratedError) const;
60
61 PidSettings m_settings;
62 bool m_hasLast = false;
63 double m_lastError = 0.0;
64 double m_lastTime = 0.0;
65 double m_heldErrorRate = 0.0;
66};
PID controller for use inside a SimObject, whose integral is a state that FhSim integrates.
Definition PidWithExternalState.h:44
double Output(double error, double integratedError, double time) const
void Accept(double error, double time)
Stores the error of an accepted step and updates the held derivative from the previous one.
double IntegralRate(double error, double integratedError) const
The rate of the integral state: the error, or zero while the integral part is past a bound (anti-wind...
The gains and limits of a PidWithExternalState. The defaults leave every limit open.
Definition PidWithExternalState.h:7
double I
Integral gain.
Definition PidWithExternalState.h:9
double D
Derivative gain.
Definition PidWithExternalState.h:10
double minOut
Lower bound of the output.
Definition PidWithExternalState.h:12
double P
Proportional gain.
Definition PidWithExternalState.h:8
double maxDerivativePart
Clamps |derivative part|.
Definition PidWithExternalState.h:17
double initOutput
The integral part while the integral state is zero.
Definition PidWithExternalState.h:15
double maxIntegratorPart
The integral freezes while |integral part| is past this.
Definition PidWithExternalState.h:16
double maxOut
Upper bound of the output.
Definition PidWithExternalState.h:13