modm API documentation
modm::Pid< T, ScaleFactor > Class Template Reference

A proportional-integral-derivative controller (PID controller) More...

#include <modm/math/filter/pid.hpp>

Classes

struct  Parameter
 Parameter for a PID calculation More...
 

Public Typedefs

typedef T ValueType
 

Public Member Functions

 Pid (const float &kp=0, const float &ki=0, const float &kd=0, const T &maxErrorSum=0, const T &maxOutput=0)
 
 Pid (Parameter &parameter)
 
void setParameter (const Parameter &parameter)
 
void reset ()
 Reset all values.
 
void update (const T &input, bool externalLimitation=false)
 Calculate a new output value. More...
 
const T & getValue () const
 Returns the calculated actuating variable.
 
const T & getLastError () const
 Get last error. More...
 
const T & getErrorSum () const
 Get integrated error. More...
 

Detailed Description

template<typename T, unsigned int ScaleFactor = 1>
class modm::Pid< T, ScaleFactor >

A proportional-integral-derivative controller (PID controller)

The PID controller is one of the basic controlling algorithm.

The maxErrorSum is to be used, to limit the internal integrator and so provide an anti wind up.

With the template parameter ScaleFactor this class provides an fix point capability with integer types.

Example for a motor speed control with a 10-bit PWM output.

Pid<int16_t, 10> pid(0.4, 0.5, 0, 200, 512);
...
v_target = ... // setpoint
v_input = ... // input value
pid.update(v_target - v_input);
pwm = pid.getValue();
Author
Fabian Greif

Constructor & Destructor Documentation

template<typename T , unsigned int ScaleFactor = 1>
modm::Pid< T, ScaleFactor >::Pid ( const float &  kp = 0,
const float &  ki = 0,
const float &  kd = 0,
const T &  maxErrorSum = 0,
const T &  maxOutput = 0 
)
Parameters
kpproportional gain
kiintegral gain
kddifferential gain
maxErrorSumintegral will be limited to this value
maxOutputoutput will be limited to this value
template<typename T , unsigned int ScaleFactor = 1>
modm::Pid< T, ScaleFactor >::Pid ( Parameter parameter)
Parameters
parameterlist of parameters to the controller

Member Function Documentation

template<typename T , unsigned int ScaleFactor = 1>
const T& modm::Pid< T, ScaleFactor >::getErrorSum ( ) const
inline

Get integrated error.

This function is provided for debugging purposes only.

template<typename T , unsigned int ScaleFactor = 1>
const T& modm::Pid< T, ScaleFactor >::getLastError ( ) const
inline

Get last error.

This function is provided for debugging purposes only.

The differential term is calculated via:

Kd * (input - this->lastError);
template<typename T , unsigned int ScaleFactor = 1>
void modm::Pid< T, ScaleFactor >::setParameter ( const Parameter parameter)

Reset the parameters of the controller.

Parameters
parameterlist of parameters to the controller
template<typename T , unsigned int ScaleFactor = 1>
void modm::Pid< T, ScaleFactor >::update ( const T &  input,
bool  externalLimitation = false 
)

Calculate a new output value.

Parameters
inputError
externalLimitationIf true an external limitation is applied, this disables integral summation.

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