View Single Post
  #14   Spotlight this post!  
Unread 31-01-2006, 09:53
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,078
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Manual Velocity PID, anyone successful?

Quote:
Originally Posted by Mike Shaul
Here is some basic P control code, let me know if anyone catches an error!

Code:
#define GAIN       10    //This will need to be tuned

u8 p_control(u16 desired, u16 actual)
{
    s16 error, control;

    error = desired - actual;
    control = error * GAIN;
    if( control > 504 )
		control = 504;
    else if( control < -504 )
   		control = -504;
    
    control /= 4;   /* Convert to 8-bits */

    return (u8)(control +127);   /* PWM Output */
}
You can replace the line:

control /= 4;

with:

control >> 2;

But that's about it - otherwise it works.