Skip to content

PID_Controller

Implementation of a PID with anti windup.

#include <pid_controller.h>

Public Functions

Name
PID_Controller()
Constructor of a pid controller with kp, ki and kd equal to 0.
PID_Controller(float Kp, float Ki, float Kd, float max_error, float max_out)
Constructor of a PID controller. Initially enabled.
PID_Controller(float Kp, float Ki, float Kd, float max_error, float max_out, float min_error, float min_out)
Constructor of a PID controller. Initially enabled.
PID_Controller(float Kp, float Ki, float Kd, float Kff, float Kff_d, float Kff_lin_drag, float Kff_quad_drag, float max_error, float max_out, float min_error, float min_out)
Constructor of a PID controller (without low pass filter). Initially enabled.
PID_Controller(float Kp, float Ki, float Kd, float Kff, float Kff_d, float Kff_lin_drag, float Kff_quad_drag, float max_error, float max_out, float min_error, float min_out, double lpf_dt, double lpf_fc)
Constructor of a PID controller (with low pass filter). Initially enabled.
float computeCommand(float error_p, float ref_value, float duration, bool debug)
Core function. Computes the output of the PID.
void reset()
Reset function. Sets the integral error term to 0.
void setFFGains(const float & ff_gain, const float & ff_d_gain, const float & ff_lin_drag_gain, const float & ff_quad_drag_gain)
Set the feedfoward Gains object.
void setGains(const float & kp, const float & ki, const float & kd)
Set the Gains object.
void setLimitBounds(const float & max_out, const float & min_out)
Set the Limit Bounds object.
std::vector< double > getGains() const
Get the Gains object.
std::vector< double > getLimitBounds() const
Get the Limit Bounds object.
farol_msgs::mPidDebug getDebugInfo() const
Get debug info from the PID controller internal variables.

Public Attributes

Name
bool disable

Protected Attributes

Name
float p_gain_
float i_gain_
float d_gain_
float ff_gain_
float ff_d_gain_
float ff_lin_drag_gain_
float ff_quad_drag_gain_
float max_error_
float max_out_
float min_error_
float min_out_
float integral_
float pre_error_
float prev_ref_value_
bool has_lpf_
std::unique_ptr< LowPassFilter > lpf_
farol_msgs::mPidDebug msg_debug_

Public Functions Documentation

function PID_Controller

PID_Controller()

Constructor of a pid controller with kp, ki and kd equal to 0.

function PID_Controller

PID_Controller(
    float Kp,
    float Ki,
    float Kd,
    float max_error,
    float max_out
)

Constructor of a PID controller. Initially enabled.

Parameters:

  • Kp Proporcional gain
  • Ki Integral gain
  • Kd Derivative gain
  • max_error maximum reference error allowed
  • max_out minimum reference error allowed

function PID_Controller

PID_Controller(
    float Kp,
    float Ki,
    float Kd,
    float max_error,
    float max_out,
    float min_error,
    float min_out
)

Constructor of a PID controller. Initially enabled.

Parameters:

  • Kp Proporcional gain
  • Ki Integral gain
  • Kd Derivative gain
  • max_error maximum reference error allowed
  • max_out maximum output allowed
  • min_error minimum refrence error allowed
  • min_out minimum output allowed

function PID_Controller

PID_Controller(
    float Kp,
    float Ki,
    float Kd,
    float Kff,
    float Kff_d,
    float Kff_lin_drag,
    float Kff_quad_drag,
    float max_error,
    float max_out,
    float min_error,
    float min_out
)

Constructor of a PID controller (without low pass filter). Initially enabled.

Parameters:

  • Kp Proporcional gain
  • Ki Integral gain
  • Kd Derivative gain
  • Kff Feedforward gain
  • Kff_d Feedforward gain (linear drag) []
  • Kff_dd Feedforward gain (quadratic drag)
  • max_error maximum reference error allowed
  • max_out maximum output allowed
  • min_error minimum refrence error allowed
  • min_out minimum output allowed

function PID_Controller

PID_Controller(
    float Kp,
    float Ki,
    float Kd,
    float Kff,
    float Kff_d,
    float Kff_lin_drag,
    float Kff_quad_drag,
    float max_error,
    float max_out,
    float min_error,
    float min_out,
    double lpf_dt,
    double lpf_fc
)

Constructor of a PID controller (with low pass filter). Initially enabled.

Parameters:

  • Kp Proporcional gain
  • Ki Integral gain
  • Kd Derivative gain
  • Kff Feedforward gain
  • Kff_d Feedforward gain (linear drag) []
  • Kff_dd Feedforward gain (quadratic drag)
  • max_error maximum reference error allowed
  • max_out maximum output allowed
  • min_error minimum refrence error allowed
  • min_out minimum output allowed
  • lpf_dt Low pass filter sampling time
  • lpf_fc Low pass filter cutoff param

function computeCommand

float computeCommand(
    float error_p,
    float ref_value,
    float duration,
    bool debug
)

Core function. Computes the output of the PID.

Parameters:

  • error_p Error between the reference and the estimated variable
  • ref_value Reference value to compute the feedforward term
  • duration Sample time
  • debug Check if we want to generate a debugging message to later publish

Return:

function reset

void reset()

Reset function. Sets the integral error term to 0.

function setFFGains

void setFFGains(
    const float & ff_gain,
    const float & ff_d_gain,
    const float & ff_lin_drag_gain,
    const float & ff_quad_drag_gain
)

Set the feedfoward Gains object.

Parameters:

  • ff_gain Feefoward gain of reference
  • ff_d_gain Feedoforward gain of reference derivative
  • ff_lin_drag_gain Feefoward gain (for linear drag)
  • ff_quad_drag_gain Feefoward gain (for quadratic drag)

function setGains

void setGains(
    const float & kp,
    const float & ki,
    const float & kd
)

Set the Gains object.

Parameters:

  • kp Proportional gain
  • ki Integral gain
  • kd Derivative gain

function setLimitBounds

void setLimitBounds(
    const float & max_out,
    const float & min_out
)

Set the Limit Bounds object.

Parameters:

  • max_out maximum output allowed
  • min_out minimum output allowed

function getGains

std::vector< double > getGains() const

Get the Gains object.

Return: std::vector const

function getLimitBounds

std::vector< double > getLimitBounds() const

Get the Limit Bounds object.

Return: std::vector const

function getDebugInfo

farol_msgs::mPidDebug getDebugInfo() const

Get debug info from the PID controller internal variables.

Return: std::vector const

Public Attributes Documentation

variable disable

bool disable;

Protected Attributes Documentation

variable p_gain_

float p_gain_;

variable i_gain_

float i_gain_;

variable d_gain_

float d_gain_;

variable ff_gain_

float ff_gain_;

variable ff_d_gain_

float ff_d_gain_;

variable ff_lin_drag_gain_

float ff_lin_drag_gain_;

variable ff_quad_drag_gain_

float ff_quad_drag_gain_;

variable max_error_

float max_error_;

variable max_out_

float max_out_;

variable min_error_

float min_error_;

variable min_out_

float min_out_;

variable integral_

float integral_;

variable pre_error_

float pre_error_;

variable prev_ref_value_

float prev_ref_value_;

variable has_lpf_

bool has_lpf_ {false};

variable lpf_

std::unique_ptr< LowPassFilter > lpf_;

variable msg_debug_

farol_msgs::mPidDebug msg_debug_;

Updated on 2024-03-07 at 10:30:48 +0000


Last update: March 7, 2024