Tuning a PID controller can seem more like an art than a science at times. Thankfully, Motion Studio has the ability to automatically tune the three PID controller coefficients. We’ll be looking at how to use this functionality and how to do any additional fine tuning necessary.
The P, I and D terms in PID stand for proportional, integral and derivative. Each of the terms is used to compensate for errors between a setpoint and the actual value measured. The proportional term corrects for the current error, the integral corrects for past error and the derivative corrects for future error.
Auto Tune Velocity
Auto tuning for velocity control will configure the PID values so the motor controller can maintain a given speed with minimum error.
1. Connect your motors and encoders to the motor controller
If you are unfamiliar with connecting motors and encoders to either the RoboClaw or MCP see this App Note
2. Verify Proper Motor Operation
Select “PWM Settings” from the left-hand side of BasicMicro Motion Studio. Now locate the motor sliders labeled “Motor 1” and “Motor 2”. Move the slider for each motor up and then down. When moving the slider up the motor should turn in the forward direction and in the backwards direction when moving the slider down. If the motors do not move in the proper direction disconnect power from the RoboClaw and reverse the motor wiring and check again.
Figure 1: Motor sliders in the PWM Settings panel. [Motion Studio version 188.8.131.52]
3. Verify Proper Encoder Operation
Once again go to “PWM settings”. Move the slider for each motor up and this time check to see if the count in the boxes labeled “M1 Encoder” and “M2 encoder” boxes at the top of the windows increases. If the encoder count does not increase in the forward direction you’ll need to power down the RoboCLaw and reverse the encoder wiring at the “ENC1” or “ENC2” header depending on which encoder is not operating properly.
Figure 2: LiPO battery specifications labeled. [Motion Studio version 184.108.40.206]
4. Determine Maximum QPSS
While still in “PWM Settings” run each motor at 100% speed and note the value in the “M1 Speed” and “M2 Speed” boxes at the top of the windows. You’ll need these values for the next step.
Figure 3: Where to locate the value for maxiumum QPSS. [Motion Studio version 220.127.116.11]
5. Autotune Velocity
Now select “Velocity Settings” from the left-hand side of the application. You’ll now be presented with the settings for tuning the PID controller for velocity. Enter the QPSS value from the previous step in the box labeled QPSS, be sure to enter it the the proper box for the motor channel you ate tuning. After you’ve done this click on either “Tune M1” or “Tune M2”. The motor will cycle back and forth while the RoboClaw figures out the values for P, I and D. When the auto tuning is finished the PID values will be populated. Repeat this step for the second motor if you have one attached.
Figure 4: The velocity auto tuning panel. [Motion Studio version 18.104.22.168]
Figure 5: Video showing the steps in auto tuning velocity in Motion Studio. [Motion Studio version 22.214.171.124]
6. Testing the Velocity Controller
A first initial test of the tuned controller is whether or not the motor operates smoothly when responding to changes. You can test this from the same window where you tuned the controller. Move the “Motor1” and “Motor2” sliders up and down and observe the behavior of the motors. They should respond quickly and smoothly without any chatter or vibration.
A second check of the controller can be performed by using the graph available above the auto tuning settings. Select one channel to be set to “Motor1 setpoint” and another channel set to “Motor1 velocity”. Now operate the motor slider and observe how the two graphs of setpoint and velocity correspond to each other. In a well tuned controller the two graphs will track each other closely as you make changes in the motor speed.
Figure 6: Graph showing velocity versus setpoint. [Motion Studio version 126.96.36.199]
If you observe any problems with the tuning of the controller move on to the next section.
7. Post Tuning
You can manually adjust the PID parameters from what the autotune set them to. The first problem you may encounter is an overly aggressive tuning, this is seen when the motor vibrates and chatters. To fix this you can lower the P and I settings until the problem goes away. When you lower the values try and keep the ratio of P and I values the same. Another problem, seen with the graph, is a steady state error between the setpoint and the actual speed. Increasing the I values tends to solve this problem.
8. Save Settings
Once you have finished tuning the velocity controller click on “Device” in the menu at the top of the window then select “Write Settings” to save the tuning parameters to your RoboClaw.
Auto Tuning Position
Auto tuning for position control will configure the PID values so the motor controller can maintain a given position with minimum error.
1. Wire the motors and encoders
First carry out wiring your motors and encoders, verifying they operate properly and determining the QPSS as described in the previous section about velocity tuning.
2. Auto Tune Position
Select “Position Settings” from the left-hand side of Motion Studio, you’ll now see the options and settings for tuning the PID values for position control. Enter the QPSS value from the previous step in the box labeled “QPSS”, if you have previously tuned for velocity this box should already be filled out for you. Now select the type of auto tune you would like to perform. The options are “PD”, “PIV”, and “PID”. We recommend you select either “PD” or “PIV” as they are tend to require little to no tweaking after the auto tuning. After you selected the type of tuning click on “Tune M1” or “Tune M2” depeding on which motor you’re trying to tune. As with velocity tuning the motor will cycle itself while tuning. When the tuning is done the PID values will be populated with values. Depending on what type of tuning you did some of the values may still be set to zero, this is normal.
Figure 7: The position auto tuning panel. [Motion Studio version 188.8.131.52]
Figure 8: Video showing the motors running during auto tuning. [Motion Studio version 184.108.40.206]
3. Testing the Position Controller
You can use the motor sliders to make a quick check of the position control after tuning. However you will first need to set values for min and max encoder values. These boxes can be found below the PID boxes. For a small range of motion set lower values, for a larger range of motion set larger values. May might also need to zero the “M1 Encoder” and “M2 Encoder” boxes at the top of the windows before you test the motors. You can now move the sliders up and down and see if the motor’s response is quick, smooth and free of vibration or cogging. If you have problems with the tuning see the next section.
As a second check you can use the graph available in the current view. Set one channel to “Motor1 setpoint”
or “Motor2 setpoint” and the second channel to “Motor1 position” or “Motor2 position”. Operate the sliders and check to see it the two graphs plotted track each other reasonably. The two lines should have no gap between the vertically, they should respond together in a reasonable amount of time and there should be no oscillation around the setpoint. If you observer any problems with the tuning see the next section.
4. Post Tuning
If the tuning is too aggressive, as evidenced by vibration or roughness in the motor, you can solve this by lowering the P value if you did PD tuning or lower both P and I in proportion to each other in the case of PIV tuning. Adjust these values until the motor operates smoothly and the graph shows no oscillation. If there is a large amount of overshoot in your graph the D value can be increased if you did a PD tune.
5. Save Settings
Once you have finished tuning the position controller click on “Device” in the menu at the top of the window then select “Write Settings” to save the tuning parameters to your RoboClaw.