View Single Post
  #2   Spotlight this post!  
Unread 13-01-2016, 21:52
mark219 mark219 is offline
Programmer/Driver
AKA: Mark Szewczuk
FRC #0219 (Team Impact)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2015
Location: United States
Posts: 12
mark219 is an unknown quantity at this point
Re: Application of PID in code/real world

Quote:
Originally Posted by Justin Buist View Post
There are uses for PID in teleop; it's just not an auton thing. In this game I could see mashing a button to put the robot into a crawler mode where you could put a speed limit on a tank tread when crawling over some of the obstacles. Going over the rumble wall you may want to reduce power to one side when it's entirely in the air so that when it does make contact it doesn't spin the robot to one side, but you would also want to it to come back up to speed quickly once it's under load.

The code is incredibly simple and so is the math. Tuning your PID values is not. Here's the crux of simple PID calculation code:
Code:
double error = target-current;
double errorChange = error-lastError;
double correction = Kp*error + Ki*errorSum + Kd*errorChange;
lastError = error;
return correction;
Figuring out what the values for Kp, Ki, and Kd are is the tricky bit. Let's try an example. Say you're driving a car and you only open your eyes every second or so and make a rash decision about how to jerk the wheel about. This is your Kp value. Assume your steering wheel works at a 1:1 ratio to your tires here. If you open your eyes and find you're driving 5 degrees left of the line you want you'd jerk the wheel 10 degrees right to get you back on track. When you open your eyes again you might be just slightly right of the line, say 3 degrees, so you jerk 6 left, and you kinda keep doing this until you oscillate around the line. That would be how a robot would respond if you give it a Kp value of 2.0. It would double the response to the immediate error. I'm not saying Kp of 2.0 is ever a good idea it's just an example. But first you have to find a Kp value that gives you that subtle and sane oscillation around your target. Once that's done you work on Ki which, as an integral, represents your general inability to keep on track. Once dialed in that dampens the oscillation in that it reduces the effect Kp has on the correction. If you keep correcting solely on Kp but your'e 10% off each time you dampen it down. Finally you define Kd to fix what you can't compensate for with Kp and Ki. Kd is generally going to be 0 unless you want to get really freaking precise about something.

Hope that helps.
Thank you,
This actually does help me quite a bit in terms of visualizing an implementation of PID. I am more of a model based learner, so reading text off of wikipedia trying to learn it doesn't work for me. The video that Ether posted above also helped in learning what PID does/is. Towards the end it has a slide about tuning Kp, Ki, and Kd, however it states that the way that these are found are not really 100% precise but will generally work for most implementations of PID. (For reference: )
Just curious, is this how you guys also tune your Kp/Ki/Kd values, or do you just estimate based off of guess and check. Also, wouldn't guess and check error also have to be tweaked differently for different surfaces (i.e. testing a robot drive PID system on school hallway floor v.s. testing robot drive PID system on competition carpeting)?
Reply With Quote