MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PIDController Class Reference

#include <PIDController.h>

+ Collaboration diagram for PIDController:

Public Member Functions

double getCommand () const
 
double getEDerivative () const
 
double getEIntegral () const
 
double getEPrevious () const
 
double getError () const
 
double getGain () const
 
double getOutput () const
 
double getSaturation () const
 
double getSensed () const
 
double getTauD () const
 
double getTauI () const
 
 PIDController ()
 
void process (const Eref &e, ProcPtr process)
 
void reinit (const Eref &e, ProcPtr process)
 
void setCommand (double command)
 
void setGain (double gain)
 
void setSaturation (double saturation)
 
void setSensed (double sensed)
 
void setTauD (double tau_d)
 
void setTauI (double tau_i)
 

Static Public Member Functions

static const CinfoinitCinfo ()
 

Private Attributes

double command_
 
double e_derivative_
 
double e_integral_
 
double e_previous_
 
double error_
 
double gain_
 
double output_
 
double saturation_
 
double sensed_
 
double tau_d_
 
double tau_i_
 

Detailed Description

Definition at line 44 of file PIDController.h.

Constructor & Destructor Documentation

PIDController::PIDController ( )

Definition at line 186 of file PIDController.cpp.

186  :
187  command_(0),
188  saturation_(DBL_MAX),
189  gain_(1),
190  tau_i_(0),
191  tau_d_(0),
192  sensed_(0),
193  output_(0),
194  error_(0),
195  e_integral_(0),
196  e_derivative_(0),
197  e_previous_(0)
198 {
199  ; // do nothing else
200 }
double e_previous_
Definition: PIDController.h:80
double e_integral_
Definition: PIDController.h:78
double e_derivative_
Definition: PIDController.h:79
double saturation_
Definition: PIDController.h:71

Member Function Documentation

double PIDController::getCommand ( ) const

Definition at line 207 of file PIDController.cpp.

References command_.

Referenced by initCinfo().

208 {
209  return command_;
210 }

+ Here is the caller graph for this function:

double PIDController::getEDerivative ( ) const

Definition at line 281 of file PIDController.cpp.

References e_derivative_.

Referenced by initCinfo().

282 {
283  return e_derivative_;
284 }
double e_derivative_
Definition: PIDController.h:79

+ Here is the caller graph for this function:

double PIDController::getEIntegral ( ) const

Definition at line 276 of file PIDController.cpp.

References e_integral_.

Referenced by initCinfo().

277 {
278  return e_integral_;
279 }
double e_integral_
Definition: PIDController.h:78

+ Here is the caller graph for this function:

double PIDController::getEPrevious ( ) const

Definition at line 286 of file PIDController.cpp.

References e_previous_.

Referenced by initCinfo().

287 {
288  return e_previous_;
289 }
double e_previous_
Definition: PIDController.h:80

+ Here is the caller graph for this function:

double PIDController::getError ( ) const

Definition at line 271 of file PIDController.cpp.

References error_.

Referenced by initCinfo().

272 {
273  return error_;
274 }

+ Here is the caller graph for this function:

double PIDController::getGain ( ) const

Definition at line 232 of file PIDController.cpp.

References gain_.

Referenced by initCinfo().

233 {
234  return gain_;
235 }

+ Here is the caller graph for this function:

double PIDController::getOutput ( ) const

Definition at line 222 of file PIDController.cpp.

References output_.

Referenced by initCinfo().

223 {
224  return output_;
225 }

+ Here is the caller graph for this function:

double PIDController::getSaturation ( ) const

Definition at line 266 of file PIDController.cpp.

References saturation_.

Referenced by initCinfo().

267 {
268  return saturation_;
269 }
double saturation_
Definition: PIDController.h:71

+ Here is the caller graph for this function:

double PIDController::getSensed ( ) const

Definition at line 217 of file PIDController.cpp.

References sensed_.

Referenced by initCinfo().

218 {
219  return sensed_;
220 }

+ Here is the caller graph for this function:

double PIDController::getTauD ( ) const

Definition at line 252 of file PIDController.cpp.

References tau_d_.

Referenced by initCinfo().

253 {
254  return tau_d_;
255 }

+ Here is the caller graph for this function:

double PIDController::getTauI ( ) const

Definition at line 242 of file PIDController.cpp.

References tau_i_.

Referenced by initCinfo().

243 {
244  return tau_i_;
245 }

+ Here is the caller graph for this function:

const Cinfo * PIDController::initCinfo ( )
static

Definition at line 54 of file PIDController.cpp.

References moose::error, getCommand(), getEDerivative(), getEIntegral(), getEPrevious(), getError(), getGain(), getOutput(), getSaturation(), getSensed(), getTauD(), getTauI(), Neutral::initCinfo(), outputOut(), pidCinfo, process(), reinit(), setCommand(), setGain(), setSaturation(), setSensed(), setTauD(), and setTauI().

55 {
56  static DestFinfo process( "process",
57  "Handle process calls.",
59  static DestFinfo reinit( "reinit",
60  "Reinitialize the object.",
62  static Finfo* processShared[] = {
63  &process, &reinit
64  };
65 
66  static ValueFinfo<PIDController, double> gain( "gain",
67  "This is the proportional gain (Kp). This tuning parameter scales the"
68  " proportional term. Larger gain usually results in faster response, but"
69  " too much will lead to instability and oscillation.",
72  static ValueFinfo<PIDController, double> saturation("saturation",
73  "Bound on the permissible range of output. Defaults to maximum double"
74  " value.",
77  static ValueFinfo<PIDController, double> command("command",
78  "The command (desired) value of the sensed parameter. In control theory"
79  " this is commonly known as setpoint(SP).",
82  static ReadOnlyValueFinfo<PIDController, double> sensed( "sensed",
83  "Sensed (measured) value. This is commonly known as process variable"
84  "(PV) in control theory.",
86  static ValueFinfo<PIDController, double> tauI( "tauI",
87  "The integration time constant, typically = dt. This is actually"
88  " proportional gain divided by integral gain (Kp/Ki)). Larger Ki"
89  " (smaller tauI) usually leads to fast elimination of steady state"
90  " errors at the cost of larger overshoot.",
93  static ValueFinfo<PIDController, double> tauD( "tauD",
94  "The differentiation time constant, typically = dt / 4. This is"
95  " derivative gain (Kd) times proportional gain (Kp). Larger Kd (tauD)"
96  " decreases overshoot at the cost of slowing down transient response"
97  " and may lead to instability.",
100  static ReadOnlyValueFinfo<PIDController, double> outputValue( "outputValue",
101  "Output of the PIDController. This is given by:"
102  " gain * ( error + INTEGRAL[ error dt ] / tau_i + tau_d * d(error)/dt )\n"
103  "Where gain = proportional gain (Kp), tau_i = integral gain (Kp/Ki) and"
104  " tau_d = derivative gain (Kd/Kp). In control theory this is also known"
105  " as the manipulated variable (MV)",
108  "The error term, which is the difference between command and sensed"
109  " value.",
111  static ReadOnlyValueFinfo<PIDController, double> integral( "integral",
112  "The integral term. It is calculated as INTEGRAL(error dt) ="
113  " previous_integral + dt * (error + e_previous)/2.",
115  static ReadOnlyValueFinfo<PIDController, double> derivative( "derivative",
116  "The derivative term. This is (error - e_previous)/dt.",
118  static ReadOnlyValueFinfo<PIDController, double> e_previous( "e_previous",
119  "The error term for previous step.",
121  static DestFinfo commandIn( "commandIn",
122  "Command (desired value) input. This is known as setpoint (SP) in"
123  " control theory." ,
125  static DestFinfo sensedIn( "sensedIn",
126  "Sensed parameter - this is the one to be tuned. This is known as"
127  " process variable (PV) in control theory. This comes from the process"
128  " we are trying to control.",
130  static DestFinfo gainDest( "gainDest",
131  "Destination message to control the PIDController gain dynamically.",
133  static SharedFinfo proc( "proc",
134  "This is a shared message to receive Process messages "
135  "from the scheduler objects."
136  "The first entry in the shared msg is a MsgDest "
137  "for the Process operation. It has a single argument, "
138  "ProcInfo, which holds lots of information about current "
139  "time, thread, dt and so on. The second entry is a MsgDest "
140  "for the Reinit operation. It also uses ProcInfo. ",
141  processShared, sizeof( processShared ) / sizeof( Finfo* )
142  );
143 
144 
145  static Finfo* pidFinfos[] = {
146  &gain,
147  &saturation,
148  &command,
149  &sensed,
150  &tauI,
151  &tauD,
152  &outputValue,
153  &error,
154  &integral,
155  &derivative,
156  &e_previous,
157  outputOut(),
158  &commandIn,
159  &sensedIn,
160  &gainDest,
161  &proc
162  };
163  static string doc[] = {
164  "Name", "PIDController",
165  "Author", "Subhasis Ray",
166  "Description", "PID feedback controller."
167  "PID stands for Proportional-Integral-Derivative. It is used to"
168  " feedback control dynamical systems. It tries to create a feedback"
169  " output such that the sensed (measured) parameter is held at command"
170  " value. Refer to wikipedia (http://wikipedia.org) for details on PID"
171  " Controller." };
172  static Dinfo<PIDController> dinfo;
173  static Cinfo pidCinfo(
174  "PIDController",
176  pidFinfos,
177  sizeof( pidFinfos ) / sizeof( Finfo* ),
178  &dinfo,
179  doc,
180  sizeof(doc)/sizeof(string));
181  return &pidCinfo;
182 }
void reinit(const Eref &e, ProcPtr process)
double getTauD() const
double getEDerivative() const
double getGain() const
double getCommand() const
Definition: Dinfo.h:60
double getTauI() const
double getEPrevious() const
void setSensed(double sensed)
double getEIntegral() const
void setGain(double gain)
void process(const Eref &e, ProcPtr process)
double getSaturation() const
void setTauD(double tau_d)
Definition: OpFunc.h:27
void setCommand(double command)
double getOutput() const
double getSensed() const
static const Cinfo * pidCinfo
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
static SrcFinfo1< double > * outputOut()
Definition: Cinfo.h:18
void setSaturation(double saturation)
double getError() const
void setTauI(double tau_i)
Definition: Finfo.h:12

+ Here is the call graph for this function:

void PIDController::process ( const Eref e,
ProcPtr  process 
)

Definition at line 291 of file PIDController.cpp.

References command_, ProcInfo::dt, e_derivative_, e_integral_, e_previous_, error_, gain_, output_, outputOut(), saturation_, sensed_, tau_d_, and tau_i_.

Referenced by initCinfo().

292 {
293  double dt = proc->dt;
295  error_ = command_ - sensed_;
296  e_integral_ += 0.5 * (error_ + e_previous_) * dt;
297  e_derivative_ = (error_ - e_previous_) / dt;
299  if (output_ > saturation_){
301  e_integral_ -= 0.5 * (error_ + e_previous_) * dt;
302  } else if (output_ < -saturation_){
303  output_ = -saturation_;
304  e_integral_ -= 0.5 * (error_ + e_previous_) * dt;
305  }
306  outputOut()->send(e, output_);
307 }
double e_previous_
Definition: PIDController.h:80
double e_integral_
Definition: PIDController.h:78
double e_derivative_
Definition: PIDController.h:79
double saturation_
Definition: PIDController.h:71
static SrcFinfo1< double > * outputOut()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PIDController::reinit ( const Eref e,
ProcPtr  process 
)

Definition at line 310 of file PIDController.cpp.

References ProcInfo::dt, e_derivative_, e_integral_, e_previous_, error_, output_, outputOut(), sensed_, tau_d_, and tau_i_.

Referenced by initCinfo().

311 {
312  if ( tau_i_ <= 0.0 ){
313  tau_i_ = proc->dt;
314  }
315  if ( tau_d_ < 0.0 ){
316  tau_d_ = proc->dt / 4;
317  }
318  sensed_ = 0.0;
319  output_ = 0;
320  error_ = 0;
322  e_integral_ = 0;
323  e_derivative_ = 0;
324  outputOut()->send(e, output_);
325 }
double e_previous_
Definition: PIDController.h:80
double e_integral_
Definition: PIDController.h:78
double e_derivative_
Definition: PIDController.h:79
static SrcFinfo1< double > * outputOut()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void PIDController::setCommand ( double  command)

Definition at line 202 of file PIDController.cpp.

References command_.

Referenced by initCinfo().

203 {
204  command_ = command;
205 }

+ Here is the caller graph for this function:

void PIDController::setGain ( double  gain)

Definition at line 227 of file PIDController.cpp.

References gain_.

Referenced by initCinfo().

228 {
229  gain_ = gain;
230 }

+ Here is the caller graph for this function:

void PIDController::setSaturation ( double  saturation)

Definition at line 257 of file PIDController.cpp.

References saturation_.

Referenced by initCinfo().

258 {
259  if (saturation <= 0) {
260  cout << "Error: PIDController::setSaturation - saturation must be positive." << endl;
261  } else {
262  saturation_ = saturation;
263  }
264 }
double saturation_
Definition: PIDController.h:71

+ Here is the caller graph for this function:

void PIDController::setSensed ( double  sensed)

Definition at line 212 of file PIDController.cpp.

References sensed_.

Referenced by initCinfo().

213 {
214  sensed_ = sensed;
215 }

+ Here is the caller graph for this function:

void PIDController::setTauD ( double  tau_d)

Definition at line 247 of file PIDController.cpp.

References tau_d_.

Referenced by initCinfo().

248 {
249  tau_d_ = tau_d;
250 }

+ Here is the caller graph for this function:

void PIDController::setTauI ( double  tau_i)

Definition at line 237 of file PIDController.cpp.

References tau_i_.

Referenced by initCinfo().

238 {
239  tau_i_ = tau_i;
240 }

+ Here is the caller graph for this function:

Member Data Documentation

double PIDController::command_
private

Definition at line 70 of file PIDController.h.

Referenced by getCommand(), process(), and setCommand().

double PIDController::e_derivative_
private

Definition at line 79 of file PIDController.h.

Referenced by getEDerivative(), process(), and reinit().

double PIDController::e_integral_
private

Definition at line 78 of file PIDController.h.

Referenced by getEIntegral(), process(), and reinit().

double PIDController::e_previous_
private

Definition at line 80 of file PIDController.h.

Referenced by getEPrevious(), process(), and reinit().

double PIDController::error_
private

Definition at line 77 of file PIDController.h.

Referenced by getError(), process(), and reinit().

double PIDController::gain_
private

Definition at line 72 of file PIDController.h.

Referenced by getGain(), process(), and setGain().

double PIDController::output_
private

Definition at line 76 of file PIDController.h.

Referenced by getOutput(), process(), and reinit().

double PIDController::saturation_
private

Definition at line 71 of file PIDController.h.

Referenced by getSaturation(), process(), and setSaturation().

double PIDController::sensed_
private

Definition at line 75 of file PIDController.h.

Referenced by getSensed(), process(), reinit(), and setSensed().

double PIDController::tau_d_
private

Definition at line 74 of file PIDController.h.

Referenced by getTauD(), process(), reinit(), and setTauD().

double PIDController::tau_i_
private

Definition at line 73 of file PIDController.h.

Referenced by getTauI(), process(), reinit(), and setTauI().


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