Go to Post It's up to veteran teams and mentors to help keep the original spirit of FIRST alive. - It's up to us to make these boards exemplify the FIRST principals in every post. - Ben Mitchell [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 44 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 11-02-2013, 17:58
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
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?
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2013, 18:01
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Controller Code

Quote:
Originally Posted by Nathan Powell View Post
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.


Reply With Quote
  #3   Spotlight this post!  
Unread 11-02-2013, 18:18
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 11-02-2013, 18:31
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,098
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: PID Controller Code

Quote:
Originally Posted by Nathan Powell View Post
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?
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.


Reply With Quote
  #5   Spotlight this post!  
Unread 11-02-2013, 18:32
Nathan Powell's Avatar
Nathan Powell Nathan Powell is offline
The Prime Function
FRC #2582 (PantherBots)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Lufkin, TX
Posts: 37
Nathan Powell is an unknown quantity at this point
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.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-02-2013, 22:23
SuperBK's Avatar
SuperBK SuperBK is offline
Registered User
AKA: BrianK
FRC #1225 (Amperage Robotics)
Team Role: Mentor
 
Join Date: Jan 2007
Rookie Year: 2006
Location: Henersonville, NC
Posts: 358
SuperBK is just really niceSuperBK is just really niceSuperBK is just really niceSuperBK is just really nice
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
__________________
Brian K
Team 1225 Robotics Mentor
Reply With Quote
  #7   Spotlight this post!  
Unread 12-02-2013, 10:53
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 591
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: PID Controller Code

Quote:
Originally Posted by Nathan Powell View Post
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?
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
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #8   Spotlight this post!  
Unread 12-02-2013, 11:28
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,082
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
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/
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #9   Spotlight this post!  
Unread 12-02-2013, 11:32
Happy Birthday! Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 258
Jefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond repute
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?
Reply With Quote
  #10   Spotlight this post!  
Unread 12-02-2013, 11:35
virtuald's Avatar
virtuald virtuald is offline
RobotPy Guy
AKA: Dustin Spicuzza
FRC #1418 (), FRC #1973, FRC #4796, FRC #6367 ()
Team Role: Mentor
 
Join Date: Dec 2008
Rookie Year: 2003
Location: Boston, MA
Posts: 1,082
virtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant futurevirtuald has a brilliant future
Re: PID Controller Code

Quote:
Originally Posted by Jefferson View Post
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");
    }
};
__________________
Maintainer of RobotPy - Python for FRC
Creator of pyfrc (Robot Simulator + utilities for Python) and pynetworktables/pynetworktables2js (NetworkTables for Python & Javascript)

2017 Season: Teams #1973, #4796, #6369
Team #1418 (remote mentor): Newton Quarterfinalists, 2016 Chesapeake District Champion, 2x Innovation in Control award, 2x district event winner
Team #1418: 2015 DC Regional Innovation In Control Award, #2 seed; 2014 VA Industrial Design Award; 2014 Finalists in DC & VA
Team #2423: 2012 & 2013 Boston Regional Innovation in Control Award


Resources: FIRSTWiki (relaunched!) | My Software Stuff
Reply With Quote
  #11   Spotlight this post!  
Unread 12-02-2013, 14:32
Happy Birthday! Jefferson Jefferson is offline
Registered User
AKA: Jeff Clements
FRC #0016 (Bomb Squad)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Mountain Home, AR
Posts: 258
Jefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond reputeJefferson has a reputation beyond repute
Re: PID Controller Code

Quote:
Originally Posted by virtuald View Post
Sure. Create something like this:...
Yep. That ought to do it. Thanks!
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 03:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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