My team is using 3 PID contollers in our code this year, and after searching Chief Delphi, usfirst.org, and Google, I have been unable to find out how to write a PID control loop or another type of PID function. I have the pointers, enable and reset functions, and the input/output statements (the input is a potentiometer, and the output is a talon). Can anyone provide me with a base function for PIDs?
Look in the file “PIDController.cpp” in the WPILib source code folder that is installed on your C++ development computer.
Hey thanks for the information, we did not realize what was under our noses; however, might you know how to also apply such information to a theoretical arm, and if said arm is to run autonomously, whether it can be run directly in autonomous mode or must be linked from the teleoperated component of the code?::ouch:: ::rtm::
You can certainly control things with PID in autonomous and/or TeleOp. But I’m not a C++ guru so I’ll let someone with more hands-on experience answer your question.
Also, we believe we have the neccessary statements and pointers to begin writing the function itself, however we have found that the PID function is illusive and we do not know where to start…while the source files are useful, they are somewhat complicated to understand. We would appreciate a model function using variables, if possible, as opposed to the pseudocode we have found on the Internet. Thank you for your assistance.
Look in this programmers guide for an example of how the PidController class can be used. There is a code example in there.
http://first.wpi.edu/Images/CMS/First/WPI_Robotics_Library_Users_Guide.pdf
There is some screen steps documentation here: Operating the robot with feedback from sensors (PID control) | WPILib programming | 2014 FRC Control System and here PIDSubsystems for built-in PID control | Command based programming | 2014 FRC Control System that might help.
If you look here: http://www.youtube.com/user/bradamiller there is a video on command based programming (one with and one without using RobotBuilder). In either one there are a few examples of writing code that will control an arm using PID control. The RobotBuilder version of the video shows how you can tune the PID controller using the SmartDashboard test mode widgets.
Brad
When we were using C++, we used the PID controller class a few times. You can find our working 2009 code on my FRC resources page. The custom servo classes used it heavily if I remember correctly… http://www.virtualroadside.com/FRC/
Brad,
The PID controller requires a PID source for inputs. Is there a way to use the output of a SmartDashboard widget as the input to the PIDController?
Sure. Create something like this:
class MyCustomPidSource : public PIDSource
{
double PIDGet()
{
return SmartDashboard::GetNumber("whatever you need here");
}
};
Yep. That ought to do it. Thanks!