flex_load_single_pid_parameter

NI-Motion Functions

flex_load_single_pid_parameter

Device Compatibility

Device Compatibility
7330
N
7340
Y
7344
Y
7350
Y
7390
N
NI SoftMotion Controller for CANopen—Xenus
N
NI SoftMotion Controller for CANopen—Accelnet
N

Load Single PID Parameter

Usage

status = flex_load_single_pid_parameter(u8 boardID, u8 axis, u16 parameterType, u16 PIDValue, u8 inputVector);

Purpose

Loads a single PID control loop parameter for an axis.

Parameters

Name Type Description
boardID u8 assigned by Measurement & Automation Explorer (MAX)
axis u8 axis to configure
parameterType u16 selects PID parameter to load
PIDValue u16 PID value to load
inputVector u8 source of the data for this function

Parameter Discussion

axis is the axis for which to load PID parameters. Valid values are NIMC_AXIS1 through NIMC_AXIS30. On motion controllers that support fewer than thirty axes, configuring non-existent axes returns error –70006 (NIMC_badResourceIDOrAxisError). Refer to Axes for axis resource IDs.

parameterType is the selector for the PID parameter to load.

parameterType Constant parameterType Value
NIMC_KP 0
NIMC_KI 1
NIMC_IL 2
NIMC_KD 3
NIMC_TD 4
NIMC_KV 5
NIMC_AFF 6
NIMC_VFF 7

PIDValue is the value to load for the selected PID parameter.

PID Parameter Abbreviation Data Ranges 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

inputVector indicates the source of the data for this function. 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.

Using This Function

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

Example

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

  •    axis = NIMC_AXIS2
  •    parameterType = NIMC_KP
  •    PIDValue = 1,000
  •    inputVector = 0xFF (Immediate)

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 functions to load the second set of PID values. Instead of using regular axis constants, such as axis 1 = NIMC_AXIS1, axis 2 = NIMC_AXIS2, and so on, use the following alternate constants: axis 1 = NIMC_SECOND_PID1, axis 2 = NIMC_SECOND_PID2, up to NIMC_SECOND_PID30.

Use the Load Advanced Control Parameter function 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.

PID Loop Parameters

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 = 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). Refer to the Enable Axes function for information about setting the PID update rate. 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.