PID header
The PID function and the values of PID parameters are defined in the header file AxisConfiguration.h
. Notice the following:
- The values we provide are examples. You should find the best PID settings for your axis.
- The values we provide are for velocity mode.
In AxisConfiguration.h
, your PID code should be as follows:
#pragma once
/* Velocity PID */
/*We do not provide the Torque PID sample as there are no default values
in torque modes. The axes needs to be tuned.*/
//Communication delay used for the error calculation.
//With DC enabled the normal value for EtherCAT is 3 cycles.
#define FEEDBACK_DELAY 3
//Proportional Gain.
#define KP 1
//Integral Gain.
#define KI 0
//KI Term Limit.
//Percent for Torque and Percent of MaxOutput for Velocity.
#define KI_LIMIT_PERCENT 0
//Derivative Gain.
#define KD 0
//Velocity Feedforward Gain.
#define KV 1
//Acceleration Feedforward Gain.
#define KAA 0.003
//Deceleration Feedforward Gain.
#define KAD 0.003
//Jerk Feedforward Gain.
#define KJ 0
//Delay in Seconds after which the reduced gain factor is applied to KP and KD terms.
#define REDUCED_GAIN_DELAY 0.2
//Factor applied to the KP and KD terms after the delay expired.
#define REDUCED_GAIN_FACTOR 0.1
//Only apply the KI term after the interpolation is done.
#define KI_STOPPED_ONLY TRUE
//Used the secondary encoder to calculate the error used by the KD term.
#define KD_USE_INTERNAL_ENCODER FALSE
//The drive will not move if its velocity is less than this value.
//This is only useful in velocity control modes if the drive clamps small velocity to zero.
#define MINIMUM_OUTPUT 0
//Maximum value sent to the drive.
#define MAXIMUM_OUTPUT 5000
//Enable monitoring of maximum error of the position lag.
#define POSITION_LAG_MONITORING FALSE
VOID UpdatePID(int Index);