View Single Post
  #11   Spotlight this post!  
Unread 21-03-2004, 23:34
Max Lobovsky's Avatar
Max Lobovsky Max Lobovsky is offline
Fold em oval!
FRC #1257 (Parallel Universe)
Team Role: College Student
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Scotch Plains, NJ
Posts: 1,026
Max Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant futureMax Lobovsky has a brilliant future
Send a message via AIM to Max Lobovsky
Re: PID control loops - closed loop feedback

Quote:
Originally Posted by Jay Lundy
We use 2 PI loops to maintain target velocities on our 2 arm joints. The integral is essential for our loop because it is what keeps the arms from falling due to gravity. For the proportional to work, it needs to have a speed error. So in order for the proportional to prevent the arm from dropping, the arm needs to drop a little first. The integral is non-zero when the arm is stationary, which is what keeps the motor at stall torque.

Here's the code for the PI loop for our elbow.

Code:
 //Joystick dead zone
 ELBOW_CONTROL = (ELBOW_CONTROL >= 127 - ELBOW_CONTROL_DEAD_ZONE && ELBOW_CONTROL <= 127 + ELBOW_CONTROL_DEAD_ZONE) ? 127 : ELBOW_CONTROL;	
  
  //Calculate velocities
  elbowVelocity = (long)(elbowCurrPosition - elbowPrevPosition) * 1000 / (long)(elbowCurrTime - elbowPrevTime);
  targetVelocity = ((int)ELBOW_CONTROL - 127) * ELBOW_MAX_POT_SPEED / 127;
  
  //Check for target position mode
  if (elbowPositionMode) {
  	targetVelocity = RepositionElbow();
  }
  
  //Calculate speed error
  speedError = targetVelocity - elbowVelocity;
  
  //Calculate proportional and integral
  proportional = speedError * ELBOW_PROPORTIONAL; 
  elbowIntegral += speedError * ELBOW_INTEGRAL;
  
  //Limit integral
  elbowIntegral = MIN_MAX(elbowIntegral, -127, 127);
  
  //Output to motors
  ELBOW_MOTORS = 254 - MIN_MAX(127 + (proportional + elbowIntegral), 0, 254);	
  
  //Set prev values to current values
  elbowPrevPosition = elbowCurrPosition;
  elbowPrevTime = elbowCurrTime;
The thing is, none of our programmers had any prior experience with PID loops. We just had an engineer come in for 2 hours one day and explain the theory to us, but he didn't provide any code. I'm curious if our implementation is correct, or if there are any improvements we should make.

By the way, our P and I constants are both 1 / 8 on our competition robot, and our elbow loop runs at 10 Hz.

Oh we also have a target position mode which feeds a target velocity into our PI loop. That's the RepositionElbow() function that you see in there.
as i understand it, the code sums the integral from start to finish, but every iteration of the loop it limits the integral. This seems like a very bad idea. essentially, the effective length of time that sum occurs is changing as the integral is being limited when it grows large. Also, for errors that continue in one direction, the integral error will not change because it will reach its max and keep trying to exceed that. This brings me back to my first question in this post. how long in iterations or in time should the integral sum over?
__________________
Learn, edit, inspire: The FIRSTwiki.
Team 1257


2005 NYC Regional - 2nd seed, Xerox Creativity Award, Autodesk Visualization Award
2005 Chesapeake Regional - Engineering Inspiration Award
2004 Chesapeake Regional - Rookie Inspiration award
2004 NJ Regional - Team Spirit Award