| Configuring PID Control | Index |
This page has some tips for choosing a PID mode for an application. It also has instructions for setting the initial PID configuration for analog and encoder control modes and has some tips for tuning PID parameters.
Position or Velocity Control?
The Moto board performs both position and velocity control. In a velocity control mode, the result of the PID equation is added to the current PWM output. In a position control mode, the result of the PID equation becomes the new PWM output. The two types of feedback produce different results. It is up to the user to pick the best control mode for an application. In general, a velocity control mode is required when zero error should create zero change in the output and a position control mode is required when zero error should create zero output. Zero change in the output means the motor speed will stay the same. Zero output means the motor position will stay the same. The ENCPID and A2DPID modes are position control modes. The ENCVEL and A2DVEL modes are velocity control modes.
Tuning PID Parameters
Tuning PID systems is both a science and an art form. Proper parameters depend entirely on the system being tuned. A thorough discussion of the theory behind PID tuning is beyond the scope of this document. Some "rule of thumb" guidelines are provided instead. Scaling conventions will differ depending on a particular PID implementation. The guidelines described below are only relevant to the Moto board.
The default parameters for any PID mode are P =1, I =0, D =0. This is sufficient for determing if the system is functional and if inputs or outputs need to be inverted. Based on experiments with a few different systems here at Acroname, a D component that is 2* P tends to work fairly well for providing crisp control. Increasing P and D proportionally will decrease response time. If P gets too big, the motor will oscillate. If the motor stops at an incorrect position, try adding an I component that is a small fraction of the P component. This may eliminate such "steady-state" errors which tend to occur in a position control mode. Making I too big will make the motor oscillate. An I component is usually not necessary for a velocity control mode since the output continues to change as long as the error is non-zero.
If the PID loop still lacks effectiveness after repeated tuning attempts, try decreasing the PID period and start over again. Position control modes usually need a smaller period than velocity control modes. Before tuning a position mode, it may be best to set the PID period to a small value.
Configuring A2DPID Mode
This control mode is useful for making a custom servo motor application. To use this mode, a DC motor must have some type of device on its output shaft that provides an analog voltage that is proportional to shaft position. Such a system is identical to that of a hobby servo, which has a potentiometer on the output shaft that provides analog feedback. The instructions below tell how to set the initial configuration of such a system.
1. Run the Moto 1.0 application.
2. Select "PWM - A/D" mode for the channel.
3. Move the output slider up and down and see if your motor moves appropriately. Watch the "A/D" display to see if you are getting proportional input from the feedback device.
4. If everything seems normal, hit the "Stop" button and select "A/D PID" mode. The control loop will try to drive the motor to the current setpoint.
5. Change the setpoint in the "Delta" box by typing in a new value and hitting enter. Since the Stems have 10-bit A/D converters, valid values range from 0 to 1023. If the output response seems backwards, check the "Invert Output" box.
6. Tune the PID parameters and test the response of your system.
7. Apply a default setpoint. Save the settings.
Configuring A2DVEL Mode
This control mode is useful for controlling velocity based on an analog input. To use this mode, a DC motor must have some type of device on its output shaft that provides an analog voltage that is proportional to motor velocity. When using a 3A Back-EMF bridge, the motor itself can provide analog voltage velocity feedback. This mode was designed specifically for use with that h-bridge. The instructions below tell how to configure such a system.
1. Run the Moto Application.
2. Select "PWM-A/D" mode in the drop down box for the desired channel.
3. Determine a latency value. 5 (0.5ms) is a good starting value. Enter the value in the "Latency" box and hit enter.
4. Enable the "Auto Brake". This makes it possible to measure the back-EMF voltage on the 3A h-bridge during the latency period.
5. Move the slider up and down and observe the range of values in the A/D display. (With a 12V supply, it should idle around 400 and have extremes of around 100 and 700.)
6. Estimate the average idle A/D value since it will probably fluctuate a bit.
7. Type the negative of the average idle A/D value into the "Input Offset" box and hit enter.
8. Select "A/D Velocity PID" mode in the drop down box.
9. Move the slider up and down and see if the "A/D" display tracks the "Set" display. If you put a load on the motors, the PWM should increase to compensate.
10. Tune the PID parameters and test the response of your system.
11. Apply a default setpoint. Save the settings.
Configuring ENCPID Mode
This control mode is useful for making a custom servo motor application. To use this mode, a DC motor must have a quadrature encoder. Such a system will enable the motor to be moved to an arbitrary position or moved a relative number of encoder ticks.
1. Run the Moto 1.0 application.
2. Select "PWM - Encoder" mode for the channel.
3. Move the output slider up and down and see if your motor moves appropriately. Watch the "Enc" display to see if you are getting appropriate input from the encoder. If the signs between the "Enc" and "PWM" displays differ, invert either the input or output.
4. If everything seems normal, hit the "Stop" button and select "Encoder PID" mode. The control loop will try to drive the motor to the current setpoint.
5. Change the setpoint in the "Delta" box by typing in a new value and hitting enter. See if the PID control loop attempts to drive the motor to the setpoint.
6. Tune the PID parameters and test the response of your system. Decreasing the PID period may help if tuning is difficult.
7. Apply a default setpoint. Save the settings.
Configuring ENCVEL Mode
This control mode is useful for controlling velocity based on an encoder input. To use this mode, a DC motor must have an encoder. A single-channel encoder will work, but quadrature encoders provide the most stable results.
1. Run the Moto Application.
2. Select "PWM - Encoder" mode for the channel.
3. Move the output slider up and down and see if your motor moves appropriately. Watch the "Enc" display to see if you are getting appropriate input from the encoder. If the signs between the "Enc" and "PWM" displays differ, invert either the input or output.
4. If everything seems normal, hit the "Stop" button and select "Enc. Velocity PID" mode. The control loop will try to drive the motor to the current setpoint.
5. Change the setpoint with the slider. See if the PID control loop attempts to drive the motor at the desired speed by comparing the "Enc" display and slider position.
6. Tune the PID parameters and test the response of your system. Decreasing the PID period may help if tuning is difficult.
7. Apply a default setpoint. Save the settings.