PID Algorithm¶
At the root of the PiMotion™ controller, the PID algorithm used is the ideal parallel form shown here:
\(output(t) = K_p{e(t)} + K_{i}\int_{0}^{t}{e(\tau)}\,{d\tau} + K_{d}\frac{d}{dt}e(t) + [K_{vff}(\frac{v_{target}}{2^{K_{vffshift}}}) + (K_{aff}\cdot a_{target} \cdot2^{K_{affshift}})]\)
Where for the above equation:
\(output\) = the output of the PID algorithm.\(K_p\) = the proportional gain.\(K_i\) = the integral gain (the integral component is limited by \(I_{limit}\)).\(K_d\) = the derivative gain.\(e(t)\) = the current controller error (see below).\(t\) = the present time.\(\tau\) = variable of integration from time 0 to the present time \(t\)\(v_{target}\) = the target velocity (calculated from the trajectory generator).\(s_{target}\) = the target acceleration (calculated from the trajectory generator).\(K_{vff}\) = the velocity feed forward.\(K_{aff}\) = the acceleration feed forward.\(K_{vffshift}\) = scaler of the target velocity (target_velocity >> vff_shift).\(K_{affshift}\) = scaler of the target acceleration (target_acceleration << aff_shift).
In position based servo mode \(e(t)\) is calculated as:
\(e(t)\) = target_position_error(t) = current_position(t) - target_position(t)
In velocity servo mode \(e(t)\) is calculated as:
\(e(t)\) = target_velocity_error(t) = actual_velocity(t) - target_velocity(t)
Conversion from Standard Form to Ideal Parallel Form¶
It may be desired to use the standard form shown below. Since the PiMotion™ only takes values in terms of \(K_p\), \(K_i\) and \(K_d\), it is necessary to do a conversion.
The standard form PID algorith is shown here:
\(output(t) = K_p\left(\,{e(t)} + \frac{1}{T_i}\int_{0}^{t}{e(\tau)}\,{d\tau} + T_d\frac{d}{dt}e(t)\right)\)
Where:
\(K_c\) = the controller gain.\(T_i\) = the reset time (in seconds).\(T_d\) = the derivative time (in seconds).\(T\) = electrical cycle time (or loop sample time in seconds)
To convert to the ideal parallel form set \(K_p\) \(K_i\) and \(K_d\) with the following:
\(K_p = K_c\)\(K_i = \frac{K_c}{T_i}\cdot T\)\(K_d = K_c\cdot \frac{T_d}{T}\)
Now the controller will behave as a standard form PID algorithm.
Functions for configuring PID parameters¶
Parameter Python C Java \(K_p\) Pidev.mtr_set_kp()
mtr_set_kp()
mtr_set_kp
\(K_i\) Pidev.mtr_set_ki()
mtr_set_ki()
mtr_set_ki
\(K_d\) Pidev.mtr_set_kd()
mtr_set_kd()
mtr_set_kd
\(K_{vff}\) Pidev.mtr_set_kvff()
mtr_set_kvff()
mtr_set_kvff
\(K_{aff}\) Pidev.mtr_set_kaff()
mtr_set_kaff()
mtr_set_kaff
\(K_{vffshift}\) Pidev.mtr_set_kvff_shift()
mtr_set_kvff_shift()
mtr_set_kvff_shift
\(K_{affshift}\) Pidev.mtr_set_kaff_shift()
mtr_set_kaff_shift()
mtr_set_kaff_shift