Class PID

Class Documentation

class PID

Public Functions

PID(double p, double i, double d, double i_max, double i_min)

Constructor.

Parameters:
  • p – proportional gain

  • i – integral gain

  • d – derivative gain

  • i_max – integral wind-up max value

  • i_min – integral wind-up min value

PID()

Constructor. Starts all gains and limits at zero.

bool init(const std::string &name, rclcpp::Node::SharedPtr node)

initialize gain settings from ROS parameter values

void reset()

Reset integral wind-up term.

double update(double error, double dt)

Run PID calculation and return control result.

PID derivate term is calculated from change in error value and dt

Parameters:
  • error – error term (goal-actual)

  • dt – timestep used for calculating derivative term and integral windup

Returns:

calculated PID command

double update(double error, double error_dot, double dt)

Run PID calculation and return control result.

Parameters:
  • error – error term (goal-actual)

  • error_dot – value that is used for derivative term calculation

  • dt – timestep used for integral windup

Returns:

calculated PID command

Protected Functions

bool checkGains()

Checks and fixes gain settings.

Returns:

true is gains are ok, false if gains are invalid

Protected Attributes

double p_gain_

proportial gain

double i_gain_

integral gain

double d_gain_

derivative gain

double i_max_

integral gain min and max limits

double i_min_
double i_term_

integral wind-up term

double error_last_

Last error value, used for calculating error_dot when not provided.

rclcpp::Node::SharedPtr node_