Class PIDController

Class Documentation

class PIDController

A simple PID (Proportional-Integral-Derivative) controller implementation.

Public Functions

PIDController(double min_ref, double max_ref, double min_output, double max_output)

Constructor.

Initializes the PID controller with output and reference range limits.

Parameters:
  • min_ref – Minimum allowed input reference value.

  • max_ref – Maximum allowed input reference value.

  • min_output – Minimum output control value.

  • max_output – Maximum output control value.

void set_pid(double n_KP, double n_KI, double n_KD)

Sets the PID gains.

Parameters:
  • n_KP – Proportional gain.

  • n_KI – Integral gain.

  • n_KD – Derivative gain.

double get_output(double new_reference, double dt)

Computes the control output for the given reference input.

Applies the PID formula and returns the control command within the specified output limits.

Parameters:
  • new_reference – The current reference input value (e.g., error signal).

  • dt – Time elapsed since last call in seconds.

Returns:

The computed control output.

void reset()

Reset internal integrator and derivative state.