Thread: PID crossing 0
View Single Post
  #2   Spotlight this post!  
Unread 26-05-2011, 04:28
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
Team Role: Engineer
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: PID crossing 0

I think I see what you're getting at, but if I've interpreted your question incorrectly, please clarify.

In the standard formulation of a PID controller, all three controllers (proportional, integral, derivative) use an error signal defined as
Code:
<error> = <set point> - <measured>
Using this with solely positive angle values will, as you say, cause the controller to never command the system past zero (assuming a perfect controller, anyway). To correct this, I would apply some sort of modulus to keep the error signal within -PI<=err<PI (radians, or -180<=err<180 degrees). In C code:
Code:
float computeError(float setPoint, float measurement) {
   float err = setPoint - measurement;
   err -= (2*M_PI) * rint(err / (2*M_PI));
   return err;
}
Replace instances of (2*M_PI) with 360.0 for degrees. rint(...) rounds to nearest integer value.

The issue with this is you now have discontinuities in your error function, so you'll want to provide some sort of protection so your derivative term doesn't blow up (e.g. if your error signal jumps from -3.14 to +3.14, derr/dt ~= 6.28 / (0.0333 sec) = 188.4).

--Ryan

P.S. If someone needs helping converting into Java or LabVIEW (or Python or ...), let me know
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor

Last edited by RyanCahoon : 26-05-2011 at 04:30.
Reply With Quote