Go to Post For We Will Rock You, we quit counting Saturday morning when it got to 12 times. - Gary Dillard [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 11-01-2010, 22:11
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
PID Control

I'm new to PID controlling, and am looking to learn. Anyone have a suggestion as to where to start?

As far as I understand, it seems as if a PID is to verify that a variable is actually where it's supposed to be by checking, such as rotational velocity with a motor and an encoder or angle with a drivetrain and a gyro, etc. Is that right?
  #2   Spotlight this post!  
Unread 11-01-2010, 22:16
Happy Birthday! Akash Rastogi Akash Rastogi is offline
Jim Zondag is my Spirit Animal
FRC #2170 (Titanium Tomahawks)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Manchester, Connecticut
Posts: 7,003
Akash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond reputeAkash Rastogi has a reputation beyond repute
Re: PID Control

Not PID but very useful for controls for autonomous mode.

http://www.wildstang.org/main/stangps.php
__________________
My posts and opinions do not necessarily reflect those of my affiliated team.
['16-'xx]: Mentor FRC 2170 | ['11-'13]: Co-Founder/Mentor FRC 3929 | ['06-'10]: Student FRC 11 - MORT | ['08-'12]: Founder - EWCP (OG)

Last edited by Akash Rastogi : 11-01-2010 at 23:13.
  #3   Spotlight this post!  
Unread 11-01-2010, 22:24
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: PID Control

Unless I missed something, I don't think I saw anything about PID in that presentation. Very informative though.
  #4   Spotlight this post!  
Unread 11-01-2010, 22:38
DMetalKong's Avatar
DMetalKong DMetalKong is offline
Registered User
AKA: David K.
no team
Team Role: College Student
 
Join Date: Jan 2008
Rookie Year: 2006
Location: Bridgewater
Posts: 144
DMetalKong is a jewel in the roughDMetalKong is a jewel in the roughDMetalKong is a jewel in the rough
Send a message via AIM to DMetalKong
Re: PID Control

Wikipedia has a rather helpful article on the subject. Even has some pseudo-code to look over:
Code:
previous_error = 0
integral = 0 
start:
  error = setpoint - actual_position
  integral = integral + (error*dt)
  derivative = (error - previous_error)/dt
  output = (Kp*error) + (Ki*integral) + (Kd*derivative)
  previous_error = error
  wait(dt)
  goto start
  #5   Spotlight this post!  
Unread 11-01-2010, 22:44
apalrd's Avatar
apalrd apalrd is offline
More Torque!
AKA: Andrew Palardy (Most people call me Palardy)
VRC #3333
Team Role: College Student
 
Join Date: Mar 2009
Rookie Year: 2009
Location: Auburn Hills, MI
Posts: 1,347
apalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond reputeapalrd has a reputation beyond repute
Re: PID Control

PID stands for Proportional-Integral-Derivative
Each is a "term" and the result of each is added to get the motor motion or change.
Proportional is, well, proportional to the difference between where you are and where you want to be. Basically, you say error = want - at, and then multiply that by a constant that testing reveals to be correct (the highest number without too much overshoot). Integral is the integration (sum) of the already corrected error, and gives the offset that should have been previously corrected.Derivative adjusts the rate of change by determining the slope of the error, the rate of change. This helps to even out noise.
Each term is multiplied by a gain that is statically set and manually tuned - this determines how much affect each term will have on the final output. It is also possible to switch from several gains based on set conditions, for example if you have a multi-jointed arm you might change the gain of the shoulder based on how far out the end-effector is from the shoulder, to prevent tippage when far out but allow it to move fast when tucked in.
PID is used in closed-loop control, basically you set a setpoint and it actively works to achieve it. This can implement itself in various ways, such as checking the angle of a potentiometer and adjusting it with a motor (used for angle control), checking the speed of a motor using an encoder and making it correct (useful for shooter wheels or such that must run at a certain speed), or even during autonomous to get the accumulated angle of a gyro and turn the chassis to acheve the desired angle, or setting the distance to travel and actively trying to get there without overshoot.
The standard FRC LabVIEW installation includes a PID toolkit - that can help. All you need to do is set the gain of each term.
If you want to learn how to do I would recommend implementing the simple Proportional control, tuning it, and seeing how it works. If you have problems, add either I or D depending on the problem. If you still have problems, add the other one.
One very very important thing to remember when working with potentiometers - if you turn them past their limit, they will break. Make sure that a positive motor direction = positive change in voltage. If this is not so, multiply the output by -1 or swap the wires on the OUTPUT side of the speed controller or the motor input. You could also swap the RED and BLACK wires on the pot.

As for where to start....
If you have large articulating structures on your robot, the most useful would be to use a potentiometer and a motor to control the angle. This would allow you to baically have a giant servo.
If you want to do autonomous stuff, then try to control the rotation (X on an arcade drive) using a gyro and a desired angle. When you get close to the desired angle, it will automatically slow down as the gain decreases and you will have a perfect turn.
And one last tip:
Always limit the output to -1 to 1. This is the range of the output and it is always good practice to do so. Do not rely on the WPIlib to do it for you.

And wikipedia has an article on the subject.
__________________
Kettering University - Computer Engineering
Kettering Motorsports
Williams International - Commercial Engines - Controls and Accessories
FRC 33 - The Killer Bees - 2009-2012 Student, 2013-2014 Advisor
VEX IQ 3333 - The Bumble Bees - 2014+ Mentor

"Sometimes, the elegant implementation is a function. Not a method. Not a class. Not a framework. Just a function." ~ John Carmack
  #6   Spotlight this post!  
Unread 11-01-2010, 22:48
Ian Curtis Ian Curtis is offline
Best Available Data
FRC #1778 (Chill Out!)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 2004
Location: Puget Sound
Posts: 2,520
Ian Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond reputeIan Curtis has a reputation beyond repute
Re: PID Control

Matt Krass' White Paper on PID Control Theory

I'm no software guy, but I understood it once I finished that paper.
__________________
CHILL OUT! | Aero Stability & Control Engineer
Adam Savage's Obsessions (TED Talk) (Part 2)
It is much easier to call someone else a genius than admit to yourself that you are lazy. - Dave Gingery
  #7   Spotlight this post!  
Unread 11-01-2010, 22:49
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,058
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 Control

I made a spreadsheet to model an ideal PID system. Its useful for understanding some of the basics, and how changing the parameters affects the output of the system.

http://www.virtualroadside.com/blog/...n-spreadsheet/
__________________
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
  #8   Spotlight this post!  
Unread 11-01-2010, 22:51
goodsky's Avatar
goodsky goodsky is offline
Programming Mentor
AKA: Skyler
FRC #1902 (Exploding Bacon)
Team Role: College Student
 
Join Date: Sep 2007
Rookie Year: 2005
Location: Orlando
Posts: 55
goodsky has a spectacular aura aboutgoodsky has a spectacular aura aboutgoodsky has a spectacular aura about
Re: PID Control

I agree the Wikipedia is very helpful on the subject, and if you want even easier to read guides all I did was google "simple PID"

Also often I find that a PD or just a P loop will work for many simple actions. So starting with those to determine if you need the added complexity of a full PID is a good place to start.
__________________
OINK OINK BOOM!!!
  #9   Spotlight this post!  
Unread 11-01-2010, 22:56
Geek 2.0 Geek 2.0 is offline
Registered User
FRC #0107
Team Role: Programmer
 
Join Date: Sep 2009
Rookie Year: 2008
Location: Holland, MI
Posts: 120
Geek 2.0 will become famous soon enough
Re: PID Control

awesome, I'll take a look at all of those. I haven't looked myself, but does the WPILibJ (that is, Java) include code for PIDs?
  #10   Spotlight this post!  
Unread 12-01-2010, 00:16
kamocat's Avatar
kamocat kamocat is offline
Test Engineer
AKA: Marshal Horn
FRC #3213 (Thunder Tech)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 2008
Location: Tacoma
Posts: 894
kamocat is just really nicekamocat is just really nicekamocat is just really nicekamocat is just really nicekamocat is just really nice
Send a message via AIM to kamocat Send a message via MSN to kamocat
Re: PID Control

Well, I know there's a PID toolkit provided with the FRC LabVIEW software.
However, there's a bit about it I don't understand.
I'm used to dealing with Proportional gain, Integral gain, and Derivative gain.
With the NI functions, the inputs are Proportional gain, Integral time, and Derivative time.
What are Integral time and Derivative time, and why would those be used as constants instead of the gain being used as constants?
__________________
-- Marshal Horn
  #11   Spotlight this post!  
Unread 12-01-2010, 01:15
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: PID Control

Quote:
Originally Posted by kamocat View Post
Well, I know there's a PID toolkit provided with the FRC LabVIEW software.
However, there's a bit about it I don't understand.
I'm used to dealing with Proportional gain, Integral gain, and Derivative gain.
With the NI functions, the inputs are Proportional gain, Integral time, and Derivative time.
What are Integral time and Derivative time, and why would those be used as constants instead of the gain being used as constants?
Have you read the PID Control Toolkit User Manual?
  #12   Spotlight this post!  
Unread 12-01-2010, 07:33
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: PID Control

As Joe said, they are convertible. Kp equals Kc, Ki equals Kc/Ti, and Kd equals KcTd.

If you understood that without the manual, you are amazing.
Greg McKaskle
  #13   Spotlight this post!  
Unread 12-01-2010, 11:07
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: PID Control

Quote:
Originally Posted by iCurtis View Post
Matt Krass' White Paper on PID Control Theory

I'm no software guy, but I understood it once I finished that paper.
This is how I learned PID as well. Just note that the source code in it is a bit out of date. It's from back in the days when we wrote in C, and PWM outputs were unsigned char values instead of wonderful floats.
__________________
  #14   Spotlight this post!  
Unread 12-01-2010, 15:10
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: PID Control

I have not used it, but WPILib (and presumably J and LV too) has a few Pid classes, so you shouln't have to completely write a PID loop
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
  #15   Spotlight this post!  
Unread 12-01-2010, 20:39
Phoenix Spud's Avatar
Phoenix Spud Phoenix Spud is offline
Everyone. Everywhere.
FRC #3132 (Thunder Down Under)
Team Role: College Student
 
Join Date: Jan 2009
Rookie Year: 2004
Location: Sydney, Australia
Posts: 703
Phoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond reputePhoenix Spud has a reputation beyond repute
Re: PID Control

Last year I was on 2343 (back in the USA) and was the lead on Autonomous. We used a PID loop, and in 6 weeks I went from knowing nothing about them, to programming one. I used the WPIlib documentation, as well as FIRST wiki, and the experience of my mentors. Between those three sources, I got a good understanding how the PID class works.
__________________
Sarah Heimlich
Outreach Mentor | Business Mentor
FIRST® TEAM 3132
Closed Thread


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
PID traction Control dpeterson3 C/C++ 5 26-01-2009 21:11
PID Control John Gutmann Programming 12 15-04-2007 18:52
Generic PID control code Uberbots Programming 3 26-02-2007 16:59
PID Control Chris Bright Programming 9 26-03-2005 19:44
PID Control Loops ttedrow Programming 7 05-12-2002 12:03


All times are GMT -5. The time now is 01:10.

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