FhSim  3.1.0
Marine systems simulation
Loading...
Searching...
No Matches
PidWithExternalState Class Reference

PID controller for use inside a SimObject, whose integral is a state that FhSim integrates. More...

#include <PidWithExternalState.h>

Public Member Functions

void Initialize (const PidSettings &settings)
 
double Output (double error, double integratedError, double time) const
 
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-windup).
 
void Accept (double error, double time)
 Stores the error of an accepted step and updates the held derivative from the previous one.
 

Detailed Description

Out = bound(-P e + (InitOutput - I integral(e)) + bound(-D de/dt, MaxDerivativePart), MinOut, MaxOut). The owner adds one state for the integral, sets its derivative to IntegralRate(), and calls Accept() from AcceptedStep(). The derivative de/dt is the rate between the last two accepted errors, held until the next accepted step (zero until two steps are accepted), so the output depends on the state and the accepted history only, never on where in a step it is evaluated.

Anti-windup: the integral freezes while the integral part is past the tighter of MaxIntegratorPart and the output bounds, and the error would drive it further out. The direction takes the sign of I.

Usage

controller.Initialize({P, I, D, minOut, maxOut});
// OdeFcn and output ports (const):
out = controller.Output(error, X[integralState], T);
XDot[integralState] = controller.IntegralRate(error, X[integralState]);
// AcceptedStep:
controller.Accept(error, T);

Member Function Documentation

◆ Output()

double PidWithExternalState::Output ( double  error,
double  integratedError,
double  time 
) const

The bounded controller output for error and the integrated error. time is unused: the derivative part is held from the accepted steps.


The documentation for this class was generated from the following file: