Thread: PID Control
View Single Post
  #5   Spotlight this post!  
Unread 07-04-2007, 15:39
The Lucas's Avatar
The Lucas The Lucas is offline
CaMOElot, it is a silly place
AKA: My First Name is really "The" (or Brian)
FRC #0365 (The Miracle Workerz); FRC#1495 (AGR); FRC#4342 (Demon)
Team Role: Mentor
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Dela-Where?
Posts: 1,564
The Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond reputeThe Lucas has a reputation beyond repute
Send a message via AIM to The Lucas
Re: PID Control

First a couple tips
First of all I would look at Kevin's 2005 navigation code . It has files in it (pid.c & pid.h) that can serve as a good base (I moded it significantly) for generic PID control, plus the structs make it easy to reuse for multiple loops.

Second if you are going to try to install this in Atlanta I recommend using pots or the EEPROM (if you already have that working) to set the P, I & D constants since time is a major factor and it take too long to redownload to change constants.

Third if you are using the Camera as your main sensor, realize that the camera doesn't give you data every loop (about every 3 loops) so set the last error and error only when you get new data from the camera so it calculates the D error correctly.

Fouth, the on the Victor 884s the deadzone center point is 132 or 133 (PWM_ZERO is 132 in Kevin's code) not 127. Keep this in mind so your robot doesn't favor forward or backward. Also be careful reversing direction of motors in code (for simplicity I just swap wires)

Quote:
Originally Posted by sparksandtabs View Post
Is that what majority of code does for the Intergral part, just reset it once the target is reached? This is one of the only parts I have always been consfused about, because you you have a huge buildup (even if it is capped) your always going to overshoot. Becuase I would still like to have it in there incase lets say i get stuck on a piece of string (just an example) then it will increase the motors until the string breaks.
I personally set the I error to 0 when it is on target and when it overshoots (error changes direction since it may never be "on target" when it goes past).
You may want to use I only when your close to target as has been suggested (I prefer not to).
Quote:
Originally Posted by sparksandtabs View Post
The other thing I need more help with is the derivative constant, should I make the constant negative? because if it it positive then when you have a big change your just gonna add even more to the output.

thanks,
John
The derivative term works in the oppose direction as the other 2 term. It damps oscillation and effectively sets a speed limit on your motion (it will also resist external impulse but that was more important last year). Be careful not to "overdamp" the system to where you need to set P and I very high to overcome D.

Good luck I'll be in Atlanta if you need any help,
-Brian
__________________
Electrical & Programming Mentor ---Team #365 "The Miracle Workerz"
Programming Mentor ---Team #4342 "Demon Robotics"
Founding Mentor --- Team #1495 Avon Grove High School
2007 CMP Chairman's Award - Thanks to all MOE members (and others) past and present who made it a reality.
Robot Inspector
"I don't think I'm ever more ''aware'' than I am right after I burn my thumb with a soldering iron"

Last edited by The Lucas : 07-04-2007 at 15:42.