PID Controller

Aug 25, 2011   //   by sam   //   Blogs, FIRST Tech Challenge  //  No Comments

Scenario: You have built a robot that has encoder motors on the wheels. You turn on PID control in RobotC to make sure that the motors are spinning at the correct speed, yet when you run your program the robot doesn’t seem to drive at the correct speed, nor does it drive straight.

Issue: Your robot doesn’t drive straight, even though you have PID control turned on.

Fix: Turn robot off, turn NXT off. Turn robot on, turn NXT on in that order. Or, you can add code to the beginning of the code to make sure that PID control turns on.

Explanation: Proportionate Integration Derivative (PID) control creates a closed loop with the motors, to make sure that the motors are going at the correct speed. This works by reading the speed from the encoder, and comparing the speed to the speed that has been sent to the motor controllers. If the speed of the motor is larger than the speed sent, the motors slow down, and if the speed of the motor is less than the speed sent, the motors speed up.

Hitechnic Motor Controller

Hitechnic Motor Controller

PID control is control is managed by the Hitechnic Motor Controllers, which are plugged into the NXT. When you write the #pragma in the configuration setting in RobotC, you are telling the NXT to tell the Hitechnic Motor Controllers to turn on PID control. When you run your code on the NXT, the NXT tells the motor controllers to turn on PID control, then the NXT starts up the rest of your code. But, if you restart your program, the NXT assumes that since it has already told the motor controllers to turn on PID control, it doesn’t tell the motor controllers to turn it on again. Sending the information only once saves time, yet if you have turned off the motor controllers (flicking the switch for the robot) between the times of running your program, PID control has been turned off by default by the motor controllers. This means that the NXT thinks that the motor controllers have already turned on PID control, yet the motor controllers haven’t. An easy fix for this is to write

nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg;

into the beginning of your program to make sure that PID control is turned on. This line of code forces the NXT to send the “PID control ON” information to the motor controllers. Another simple fix is to make sure that the robot is always turned on before the NXT is turned on. Our team uses the first technique, because we might forget to turn the robot on in the correct order. Good luck, and I hope that you have learned a little about how PID control works, and how to use its functionality correctly.

Leave a comment

Yes, you can buy cheap seroquel