Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   PID Controller Code (http://www.chiefdelphi.com/forums/showthread.php?t=113283)

Nathan Powell 11-02-2013 17:58

PID Controller Code
 
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?

Ether 11-02-2013 18:01

Re: PID Controller Code
 
Quote:

Originally Posted by Nathan Powell (Post 1231813)
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.



Nathan Powell 11-02-2013 18:18

Re: PID Controller Code
 
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::

Ether 11-02-2013 18:31

Re: PID Controller Code
 
Quote:

Originally Posted by Nathan Powell (Post 1231828)
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.



Nathan Powell 11-02-2013 18:32

Re: PID Controller Code
 
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.

SuperBK 11-02-2013 22:23

Re: PID Controller Code
 
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/Firs...sers_Guide.pdf

BradAMiller 12-02-2013 10:53

Re: PID Controller Code
 
Quote:

Originally Posted by Nathan Powell (Post 1231828)
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::

There is some screen steps documentation here: http://wpilib.screenstepslive.com/s/...rs-pid-control and here http://wpilib.screenstepslive.com/s/...in-pid-control 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

virtuald 12-02-2013 11:28

Re: PID Controller Code
 
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/

Jefferson 12-02-2013 11:32

Re: PID Controller Code
 
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?

virtuald 12-02-2013 11:35

Re: PID Controller Code
 
Quote:

Originally Posted by Jefferson (Post 1232130)
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:

Code:


class MyCustomPidSource : public PIDSource
{
    double PIDGet()
    {
      return SmartDashboard::GetNumber("whatever you need here");
    }
};


Jefferson 12-02-2013 14:32

Re: PID Controller Code
 
Quote:

Originally Posted by virtuald (Post 1232133)
Sure. Create something like this:...

Yep. That ought to do it. Thanks!


All times are GMT -5. The time now is 13:24.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi