CMSIS-DSP  
CMSIS DSP Software Library
 
Loading...
Searching...
No Matches
PID Motor Control

Data Structures

struct  arm_pid_instance_q15
 Instance structure for the Q15 PID Control. More...
 
struct  arm_pid_instance_q31
 Instance structure for the Q31 PID Control. More...
 
struct  arm_pid_instance_f32
 Instance structure for the floating-point PID Control. More...
 

Functions

float32_t arm_pid_f32 (arm_pid_instance_f32 *S, float32_t in)
 Process function for the floating-point PID Control.
 
q31_t arm_pid_q31 (arm_pid_instance_q31 *S, q31_t in)
 Process function for the Q31 PID Control.
 
q15_t arm_pid_q15 (arm_pid_instance_q15 *S, q15_t in)
 Process function for the Q15 PID Control.
 
void arm_pid_init_f32 (arm_pid_instance_f32 *S, int32_t resetStateFlag)
 Initialization function for the floating-point PID Control.
 
void arm_pid_init_q15 (arm_pid_instance_q15 *S, int32_t resetStateFlag)
 Initialization function for the Q15 PID Control.
 
void arm_pid_init_q31 (arm_pid_instance_q31 *S, int32_t resetStateFlag)
 Initialization function for the Q31 PID Control.
 
void arm_pid_reset_f32 (arm_pid_instance_f32 *S)
 Reset function for the floating-point PID Control.
 
void arm_pid_reset_q15 (arm_pid_instance_q15 *S)
 Reset function for the Q15 PID Control.
 
void arm_pid_reset_q31 (arm_pid_instance_q31 *S)
 Reset function for the Q31 PID Control.
 

Description

A Proportional Integral Derivative (PID) controller is a generic feedback control loop mechanism widely used in industrial control systems. A PID controller is the most commonly used type of feedback controller.

This set of functions implements (PID) controllers for Q15, Q31, and floating-point data types. The functions operate on a single sample of data and each call to the function returns a single processed value. S points to an instance of the PID control data structure. in is the input sample value. The functions return the output value.

Algorithm:
   y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2]
   A0 = Kp + Ki + Kd
   A1 = (-Kp ) - (2 * Kd )
   A2 = Kd
where Kp is proportional constant, Ki is Integral constant and Kd is Derivative constant
Proportional Integral Derivative Controller
The PID controller calculates an "error" value as the difference between the measured output and the reference input. The controller attempts to minimize the error by adjusting the process control inputs. The proportional value determines the reaction to the current error, the integral value determines the reaction based on the sum of recent errors, and the derivative value determines the reaction based on the rate at which the error has been changing.
Instance Structure
The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure. A separate instance structure must be defined for each PID Controller. There are separate instance structure declarations for each of the 3 supported data types.
Reset Functions
There is also an associated reset function for each data type which clears the state array.
Initialization Functions
There is also an associated initialization function for each data type. The initialization function performs the following operations:
  • Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains.
  • Zeros out the values in the state buffer.
Instance structure cannot be placed into a const data section and it is recommended to use the initialization function.
Fixed-Point Behavior
Care must be taken when using the fixed-point versions of the PID Controller functions. In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. Refer to the function specific documentation below for usage guidelines.

Data Structure Documentation

◆ arm_pid_instance_q15

struct arm_pid_instance_q15

Instance structure for the Q15 PID Control.

Data Fields

q15_t A0
 
q15_t A1
 
q15_t A2
 
q15_t state [3]
 
q15_t Kp
 
q15_t Ki
 
q15_t Kd
 

Field Documentation

◆ A0

q15_t A0

The derived gain, A0 = Kp + Ki + Kd .

◆ A1

q15_t A1

The derived gain A1 = -Kp - 2Kd

◆ A2

q15_t A2

The derived gain A1 = Kd.

◆ Kd

q15_t Kd

The derivative gain.

◆ Ki

q15_t Ki

The integral gain.

◆ Kp

q15_t Kp

The proportional gain.

◆ state

q15_t state[3]

The state array of length 3.

◆ arm_pid_instance_q31

struct arm_pid_instance_q31

Instance structure for the Q31 PID Control.

Data Fields

q31_t A0
 
q31_t A1
 
q31_t A2
 
q31_t state [3]
 
q31_t Kp
 
q31_t Ki
 
q31_t Kd
 

Field Documentation

◆ A0

q31_t A0

The derived gain, A0 = Kp + Ki + Kd .

◆ A1

q31_t A1

The derived gain, A1 = -Kp - 2Kd.

◆ A2

q31_t A2

The derived gain, A2 = Kd .

◆ Kd

q31_t Kd

The derivative gain.

◆ Ki

q31_t Ki

The integral gain.

◆ Kp

q31_t Kp

The proportional gain.

◆ state

q31_t state[3]

The state array of length 3.

◆ arm_pid_instance_f32

struct arm_pid_instance_f32

Instance structure for the floating-point PID Control.

Data Fields

float32_t A0
 
float32_t A1
 
float32_t A2
 
float32_t state [3]
 
float32_t Kp
 
float32_t Ki
 
float32_t Kd
 

Field Documentation

◆ A0

The derived gain, A0 = Kp + Ki + Kd .

◆ A1

The derived gain, A1 = -Kp - 2Kd.

◆ A2

The derived gain, A2 = Kd .

◆ Kd

The derivative gain.

◆ Ki

The integral gain.

◆ Kp

The proportional gain.

◆ state

float32_t state[3]

The state array of length 3.

Function Documentation

◆ arm_pid_f32()

float32_t arm_pid_f32 ( arm_pid_instance_f32 S,
float32_t  in 
)

Process function for the floating-point PID Control.

Parameters
[in,out]Sis an instance of the floating-point PID Control structure
[in]ininput sample to process
Returns
processed output sample.

◆ arm_pid_init_f32()

void arm_pid_init_f32 ( arm_pid_instance_f32 S,
int32_t  resetStateFlag 
)

Initialization function for the floating-point PID Control.

Parameters
[in,out]Spoints to an instance of the PID structure
[in]resetStateFlag
  • value = 0: no change in state
  • value = 1: reset state
Details
The resetStateFlag specifies whether to set state to zero or not.
The function computes the structure fields: A0, A1 A2 using the proportional gain( Kp), integral gain( Ki) and derivative gain( Kd) also sets the state variables to all zeros.

◆ arm_pid_init_q15()

void arm_pid_init_q15 ( arm_pid_instance_q15 S,
int32_t  resetStateFlag 
)

Initialization function for the Q15 PID Control.

Parameters
[in,out]Spoints to an instance of the Q15 PID structure
[in]resetStateFlag
  • value = 0: no change in state
  • value = 1: reset state
Details
The resetStateFlag specifies whether to set state to zero or not.
The function computes the structure fields: A0, A1 A2 using the proportional gain( Kp), integral gain( Ki) and derivative gain( Kd) also sets the state variables to all zeros.

◆ arm_pid_init_q31()

void arm_pid_init_q31 ( arm_pid_instance_q31 S,
int32_t  resetStateFlag 
)

Initialization function for the Q31 PID Control.

Parameters
[in,out]Spoints to an instance of the Q31 PID structure
[in]resetStateFlag
  • value = 0: no change in state
  • value = 1: reset state
Details
The resetStateFlag specifies whether to set state to zero or not.
The function computes the structure fields: A0, A1 A2 using the proportional gain( Kp), integral gain( Ki) and derivative gain( Kd) also sets the state variables to all zeros.

◆ arm_pid_q15()

q15_t arm_pid_q15 ( arm_pid_instance_q15 S,
q15_t  in 
)

Process function for the Q15 PID Control.

Parameters
[in,out]Spoints to an instance of the Q15 PID Control structure
[in]ininput sample to process
Returns
processed output sample.
Scaling and Overflow Behavior
The function is implemented using a 64-bit internal accumulator. Both Gains and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format.

◆ arm_pid_q31()

q31_t arm_pid_q31 ( arm_pid_instance_q31 S,
q31_t  in 
)

Process function for the Q31 PID Control.

Parameters
[in,out]Spoints to an instance of the Q31 PID Control structure
[in]ininput sample to process
Returns
processed output sample.
Scaling and Overflow Behavior
The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions. After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format.

◆ arm_pid_reset_f32()

void arm_pid_reset_f32 ( arm_pid_instance_f32 S)

Reset function for the floating-point PID Control.

Parameters
[in,out]Spoints to an instance of the floating-point PID structure
Details
The function resets the state buffer to zeros.

◆ arm_pid_reset_q15()

void arm_pid_reset_q15 ( arm_pid_instance_q15 S)

Reset function for the Q15 PID Control.

Parameters
[in,out]Spoints to an instance of the Q15 PID structure
Details
The function resets the state buffer to zeros.

◆ arm_pid_reset_q31()

void arm_pid_reset_q31 ( arm_pid_instance_q31 S)

Reset function for the Q31 PID Control.

Parameters
[in,out]Spoints to an instance of the Q31 PID structure
Details
The function resets the state buffer to zeros.