Load Single PID Parameter

NI-Motion VI

Load Single PID Parameter

Loads a single PID control loop parameter for an axis.

Details

Device Compatibility

DeviceCompatibility
7330
N
7340
Y
7344
Y
7350
Y
7390
N
NI SoftMotion Controller for CANopen—Accelnet
N
NI SoftMotion Controller for CANopen—Xenus
N
Value (0) is the value to load for the selected PID parameter.

PID Parameter  Abbreviation  Data Range  Default
Proportional Gain  Kp  0 to 32,767  100
Integral Gain  Ki  0 to 32,767  0
Integration Limit  Ilim  0 to 32,767  1,000
Derivative Gain  Kd  0 to 32,767  1,000
Derivative Sample Period  Td  0 to 63  2
Velocity Feedback Gain  Kv  0 to 32,767  0
Acceleration Feedforward Gain  Aff  0 to 32,767  0
Velocity Feedforward Gain  Vff  0 to 32,767  0
Parameter (Kp) is the selector for the PID parameter to load.
Board ID is a unique number assigned by Measurement & Automation Explorer (MAX) used to send and receive commands and data to or from a specific NI motion controller.
Axis is the axis for which to load PID parameters. Valid axis numbers are 1 through 15 for all NI motion controllers. On controllers with less than eight axes, configuring non-existent axes has no effect.
Inp Vect indicates the source of the data for this VI. Available input vectors include immediate (0xFF), variable (0x01 through 0x78), or indirect variable (0x81 through 0xF8). Refer to Input and Return Vectors for more detailed information.
error in (no error) describes error conditions that occur before this VI runs. The default input of this cluster is no error. If an error already occurred, this VI returns the value of error in in error out. The VI runs normally only if no incoming error exists. Otherwise, the VI passes the error in value to error out. The error in cluster contains the following parameters:
status is TRUE if an error occurred before this VI was called, or FALSE if not. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code.
code is a number identifying an error or warning. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code. Use the error handler VIs to look up the meaning of this code and display the corresponding error message.
source is a string that indicates the origin of the error, if any. Typically, source is the name of the VI in which the error occurred.
Bd ID Out is provided for flow control. You can string together NI-Motion VIs by wiring the Bd ID Out terminal of one VI to the Board ID terminal of the next VI.
Resource Output is the Axis, Vector Space, ADC, or Encoder you wired into the VI. Use Resource Output to pass the resource to another VI and/or to display information about the device.
error out contains error information. If error in indicates an error, error out contains the same error information. Otherwise, it describes the error status that this VI produces.
status is TRUE if an error occurred, or FALSE if not. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code.
code is a number identifying an error or warning. If status is TRUE, code is a nonzero error code. If status is FALSE, code is zero or a warning code. Use the error handler VIs to look up the meaning of this code and display the corresponding error message.
source is a string that indicates the origin of the error, if any. Typically, source is the name of the VI in which the error occurred.

Using This VI

This VI expects to be given the parameters in the following order: Axis, Parameter, Value.

Refer to the motion controller documentation for an overview of the enhanced PID control loop on the NI motion controller. The Load Single PID Parameter VI allows you to change an individual PID value on-the-fly without having to worry about the other unchanged PID values.

Example

To load a Kp of 1,000 to an axis 2, call the Load Single PID Parameter VI with the following parameters:

Axis = 2
Parameter = Kp
Value = 1,000
Inp Vect = 0xFF (Immediate)

Note  If you are doing onboard programming and are using Inp Vect to get the data this VI needs, remember that this VI reads the variables starting at the memory address pointed to by Inp Vect in the following order: Parameter, Value.

Loading a Second Set of PID Parameters

To load a second set of PID parameters, use the Load All PID Parameters and Load Single PID Parameter VIs to load the second set of PID values. Instead of using regular axis resource IDs, such as axis 1 = 0x1 (1), axis 2 = 0x2 (2), and so on, use the following alternate resource IDs: axis 1 = 0xA1 (161), axis 2 = 0xA2 (162).

Use the Load Advanced Control Parameter VI to enable the new set of PID parameters based on the condition specified in the value parameter.

Refer to the Remarks section of the Load Advanced Control Parameter topic for more information about how to change feedback while the axis is enabled.

Refer to the links below for specific information about the components of the PID loop:

  • Proportional Gain

    The proportional gain (Kp) determines the contribution of restoring force that is directly proportional to the position error. This restoring force functions in much the same way as a spring in a mechanical system.

    Each sample period, the PID loop calculates the position error (the difference between the instantaneous trajectory position and the primary feedback position) and multiplies it by Kp to produce the proportional component of the 16-bit DAC command output.

    The formula for calculating this proportional contribution is as follows:

    An axis with zero or too small a value of Kp is not able to hold the axis in position and is very soft. Increasing Kp stiffens the axis and improves its disturbance torque rejection. However, too large a value of Kp often results in instability.

  • Integral Gain

    The integral gain (Ki) determines the contribution of restoring force that increases with time and thus ensures that the static position error in the servo loop is forced to zero. This restoring force works against constant torque loads to help achieve zero position error when the axis is stopped.

    Each sample period, the position error is added to the accumulation of previous position errors to form an integration sum. This integration sum is scaled by dividing by 256 prior to being multiplied by Ki. Therefore, the formula for calculating the integral contribution in the 16-bit DAC command output is as follows:


       where LIMIT is shorthand for the effects of the integration limit described in the following sections.

    Note  The scaling by 1/256 allows the use of integer values for the integral gain even when only a small amount of integral contribution is required.

    In applications with small static torque loads, this value can be left at its default value of zero (0). For systems having high static torque loads, this value must be tuned to minimize position error when the axis is stopped.

    Non-zero values of Ki, while reducing static position error, tend to increase position error while accelerating and decelerating. This effect can be mitigated through the use of the Integration Limit parameter. Too high a value of Ki often results in servo loop instability. For these reasons, it is recommended that Ki be left at its default value of zero until the servo system operation is stable and then you can add a small amount of Ki to minimize static position errors.

    Note  Ki has no effect when Ilim is equal to zero.
  • Integration Limit

    The integration limit (Ilim) is used to clamp the contribution of the integral term in the PID loop. The scaled integration sum is compared to the integration limit and the lesser of the two values is multiplied by Ki to produce the integral term of the control output. This limiting function is indicated with LIMIT() in the following integral term output equation:

    You can use Ilim to limit excessive restoring forces and to minimize the adverse effects that integral compensation has during acceleration and deceleration.

    Note  Ilim has no effect when Ki is equal to zero.
  • Derivative Gain

    The derivative gain (Kd) determines the contribution of restoring force proportional to the rate of change (derivative) of position error. This force acts much like viscous damping in a damped spring and mass mechanical system (for example, shock absorber).

    The PID loop computes the derivative of position error every derivative sample period (a multiple of PID sample period; refer to the following section, Derivative Sample Period). This derivative term is multiplied by Kd every PID sample period to produce the derivative component of 16-bit DAC command output.

    The formula for calculating the derivative contribution is as follows:
       
    where the time between t1 and t0 is the derivative sample period.

    A non-zero value of Kd is required for all systems that use torque block amplifiers (where the command output is proportional to motor torque) for the servo loop operation to be stable. Too small a Kd value results in servo loop instability.

    With velocity block amplifiers (where the command output is proportional to motor velocity) you typically set Kd to zero or to a very small value.

  • Derivative Sample Period

    The derivative sample period parameter (Td) is used as a multiplier of the PID sample period (PID update rate). For information about setting the PID update rate, refer to the Enable Axes VI. Td determines how often (in update samples) the derivative of position error is calculated.

    The formula for calculating the derivative sample period from Td is as follows:
       Derivative Sample Period = (Td + 1) x PID Sample Period

    Because the range for Td is 0 to 63, the shortest derivative sample period is as follows:
       Derivative Sample Period = 1 × 62.5 µs = 62.5 µs

    The longest derivative sample period is as follows:
       Derivative Sample Period = 64 × 500 µs = 32 ms

    Adjusting Td provides greater flexibility in tuning the PID loop derivative term. As Td is increased, you can use a proportionally lower value of Kd for similar results. You must start the Td parameter at its default value of 2 and make small adjustments as required by the motion system configuration.

    For low inertia systems, Td must be set to a small value (0 or 1) so that the derivative is calculated often enough to provide adequate damping for servo loop stability.

    Systems with higher inertia can benefit from larger values of Td. Because the higher inertia means that the position error cannot change quickly, it is acceptable to calculate the derivative less often. This means you can use a lower value of Kd, have the same effective amount of damping and the system is smoother with less torque noise from the derivative term.

    In higher inertia systems, using a Td of zero and therefore a larger value for Kd results in increased torque noise and motor heating without any improvement in system stability.

  • Velocity Feedback Gain

    You can use a primary or secondary feedback encoder for velocity feedback. Setting velocity feedback gain (Kv) to a value other than zero (0) enables velocity feedback using the secondary encoder, if configured, or the primary encoder if a secondary encoder is not configured.

    Kv is used to scale this velocity feedback before it is added to the other components in the 16-bit DAC command output. Kv is similar to derivative gain (Kd) except that it scales the velocity estimated from encoder resources only. The derivative gain scales the derivative of the position error, which is the difference between the instantaneous trajectory position and the primary feedback position. Like the Kd term, the velocity feedback derivative is calculated every derivative sample period and the contribution is updated every PID sample period.

    The formula for calculating the velocity feedback contribution is as follows:

    where the time between t1 and t0 is the derivative sample period.

    Velocity feedback is estimated through a combination of speed dependent algorithms. At high speeds, velocity is simply the change in position per sample. At low speeds, the estimator seamlessly transitions to a 1/T method that measures the time between encoder counts and then calculates the inverse. This method is used for smoother performance when estimating velocities less than one encoder count per sample derivative sample period.

    Using Kv and a secondary feedback encoder creates a minor velocity feedback loop. This is very similar to the traditional analog servo control method using a tachometer and a velocity block amplifier and is commonly referred to as dual-loop feedback. Dual-loop feedback is most useful when the primary position sensor (encoder or analog transducer) is located on the end-effector for improved accuracy, and is separated from the motor by gears, ballscrews, belt drives, and/or other mechanical apparatus with potentially poor dynamics. In this case, it can be difficult to achieve a high performance, stable control system without using the minor loop velocity feedback from an encoder mounted directly on the back of the motor.

    Typically, Kd is set to zero when Kv is used. However, NI-Motion allows you to use both Kv and Kd terms simultaneously for improved performance.

    Note  Operating with zero derivative gain (Kd) and either velocity feedback or a velocity block amplifier is often referred to as PIVff mode.

    You can operate NI-Motion in PID mode, PIVff mode, or in a combination of both modes, by using Kd, Kv, or both.

  • Acceleration Feedforward

    The acceleration feedforward gain (Aff) determines the contribution in the 16-bit DAC command output that is directly proportional to the instantaneous trajectory acceleration. Aff is used to minimize following error (position error) during acceleration and deceleration and can be changed at any time to tune the PID loop.

    Using acceleration feedforward is an open-loop compensation technique and cannot affect the stability of the system. However, if you use too large a value of Aff, following error during acceleration and deceleration can reverse, thus degrading rather than improving performance.

  • Velocity Feedforward

    The velocity feedforward gain (Vff) determines the contribution in the 16-bit DAC command output that is directly proportional to the instantaneous trajectory velocity. This value is used to minimize following error during the constant velocity portion of a move and can be changed at any time to tune the PID loop.

    Using velocity feedforward is an open-loop compensation technique and cannot affect the stability of the system. However, if you use too large a value of Vff, following error during the constant velocity portion can reverse, thus degrading rather than improving performance.

    Velocity feedforward is typically used when operating in PIVff mode with either a velocity block amplifier or substantial amount of velocity feedback (Kv). In these cases, the uncompensated following error is directly proportional to the specified velocity. You can reduce this following error by applying velocity feedforward. Increasing the integral gain (Ki) also reduces the following error during constant velocity but only at the expense of increased following error during acceleration and deceleration and reduced system stability. For these reasons, increased Ki is not the recommended solution.

    Velocity feedforward is rarely used when operating in PID mode with torque block amplifiers. In this case, because the following error is proportional to the torque required (not to the velocity), it is typically much smaller and velocity feedforward is not required.