Pid#

group drv_pid

Implementation of a PID controller.

Author

Alexandre Abadie alexandre.abadie@inria.fr

Copyright

Inria, 2022

Enums

enum pid_mode_t#

PID mode.

Values:

enumerator DB_PID_MODE_AUTO#

Automatic PID enabled.

enumerator DB_PID_MODE_MANUAL#

Manual mode.

enum pid_direction_t#

PID direction.

Values:

enumerator DB_PID_DIRECTION_DIRECT#

Direct direction.

enumerator DB_PID_DIRECTION_REVERSED#

Reversed direction.

Functions

void db_pid_init(pid_t *pid, float input, float target, float kp, float ki, float kd, float output_min, float output_max, uint32_t sample_time, pid_mode_t mode, pid_direction_t direction)#

Initialize a PID control loop.

Parameters:
  • pid[in] Pointer to the pid struct

  • input[in] Initial input value

  • target[in] Target value

  • kp[in] Gain applied to the input value

  • ki[in] Gain applied to the integrated term

  • kd[in] Gain applied to the derivative term

  • output_min[in] Minimum output value

  • output_max[in] Maximum output value

  • sample_time[in] Sampling time of the pid (correspond to the update rate)

  • mode[in] PID mode (manual or automatic)

  • direction[in] Direction of the PID (direct or reversed)

void db_pid_update(pid_t *pid)#

Update the PID state.

Input attribute of the PID should be updated before calling this function

Parameters:
  • pid[inout] Pointer to the pid struct

void db_pid_set_gains(pid_t *pid, const pid_gains_t *gains)#

Set PID gains.

Parameters:
  • pid[in] Pointer to the pid struct

  • gains[in] Pointer to the gains struct

void db_pid_set_sample_time(pid_t *pid, uint32_t sample_time)#

Set PID sample time (in milliseconds)

Parameters:
  • pid[in] Pointer to the pid struct

  • sample_time[in] Sample time in milliseconds (must be > 0)

void db_pid_set_output_limits(pid_t *pid, float output_min, float output_max)#

Set PID output limits.

Parameters:
  • pid[in] Pointer to the pid struct

  • output_min[in] Minimum value of output

  • output_max[in] Maximum value of output

void db_pid_set_mode(pid_t *pid, pid_mode_t mode)#

Update the mode of the PID (manual or automatic)

Parameters:
  • pid[in] Pointer to the pid struct

  • mode[in] New mode

void db_pid_set_direction(pid_t *pid, pid_direction_t direction)#

Update the direction of the PID.

Parameters:
  • pid[in] Pointer to the pid struct

  • direction[in] New direction

struct pid_gains_t#

PID gains.

Public Members

float kp#

Value factor.

float ki#

Integral value factor.

float kd#

Derivative value factor.

struct pid_state_t#

PID internal state.

Public Members

float output_sum#

Cumulative output values (used to keep history in integration component)

float last_input#

Input used in previous iteration (used by the derivative component)

struct pid_t#

PID instance.

Public Members

pid_gains_t gains#

Factor parameters of the PID.

pid_mode_t mode#

Current mode, auto or manual.

pid_direction_t direction#

Direction.

pid_state_t state#

Internal state.

uint32_t sample_time#

Sampling time in milliseconds.

float input#

Current input value.

float output#

Last computed output.

float target#

Current target.

float output_min#

Minimal value allowed for output.

float output_max#

Maximal value allowed for output.