|
Re: Servo 'smoothing'
Quote:
Originally Posted by Alan Anderson
Code:
// DISCLAIMER: THIS CODE IS UNTESTED
// declare some variables at the beginning of the code
char incount = 0; // this will count the input values being accumulated
int accumulator = 0; // this will accumulate input values
char smooth = 128; // this will hold the smoothed input value
// ....
// do this each time a new OI value is available
accumulator += (int)potval; // replace 'potval' as appropriate, e.g. p1_aux
if( incount++ == 8 ) // is this the eighth sample?
{
smooth = accumulator << 3; // a quick and sneaky way to divide by 8
incount = 0; // set to count another eight samples
accumulator = 0; // reset accumulator
}
|
Does the incount++ action actually happen? I mean, when you check if the "if" statment is true, does the Microprocessor increase the valuce of incount? If it doesn't work, this should be done in a for loop, but if this "if" statment counts as a loop, then OK (it's just a method of a loop i've never seen before  ).
__________________
TEAM 2230 ZECHARIA'S ANGELS
2009 Microsoft Israel FRC Regional Winners!
2009 Microsoft Israel FRC Regional Chairman's Award Winners!!! --------------------------------- 2008 Microsoft Israel FRC Regional semi-finalist. 2008 Microsoft Israel FRC Regional Delphi's "Driving Tommorow's Technology" Award winner. 2008 Robot Driver --------------------------------- 2007 GM/Technion Israel FRC Regional semi-Finalist.
2007 GM/Technion Israel FRC Regional Xerox Creativity Award winner.
2007 Robot Driver.
|