Go Down

Topic: RunningAverage Class on playground (updated) (Read 6 times) previous topic - next topic

Rocketboy

Rob, Thanks for that, the compiler gets past that, but now comes up with another problem,  error : request for member 'clr' in 'myRA', which is of non-class type 'RunningAverage ()()'.
This occurs also for member 'add' and 'avg' when I comment out the other problem lines.

I know zip about C++ so I'm at a loss .

Thanks Rock.

robtillaart

Please post your sketch so I can check this one too.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Rocketboy

Rob, I found the problem , I had not deleted the .o file and restarted the IDE after changing the .h file.

compiles OK now.

Thanks for your help.

Rock.

robtillaart


Found a newer versio of the runningAverage class by Yuval Naveh here

- http://stromputer.googlecode.com/svn-history/r74/trunk/Arduino/Libraries/RunningAverage/RunningAverage.cpp -

most important addition:
Code: [Select]
void RunningAverage::trimToValue(float value)
{
clr();
add(value);
}


TODO: update the playground
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

robtillaart

#9
Dec 30, 2012, 11:59 am Last Edit: Dec 30, 2012, 12:03 pm by robtillaart Reason: 1
Finally found some time to update the runningAverage lib on the playground: - http://playground.arduino.cc//Main/RunningAverage -

changes:
1) There are some breaking changes in the method names to make them more descriptive;
// clr()  => clear()
// add(x) => addValue(x)
// avg() => getAverage()

2) new is the fillValue() function, based upon the trimValue() of Yuval Naveh  - see previous post
Code: [Select]
// fill the average with a value
// the param number determines how often value is added (weight)
// number should preferably be between 1 and size
void RunningAverage::fillValue(float value, int number)
{
clear();
for (int i = 0; i < number; i++)
{
addValue(value);
}
}

It fills the internal array with a number of identical values to get a starting value for average.
By adding more than one value, the initial average gets a certain weight.
This extends the original trimValue() so that's why I gave another name.

3) some small refactoring and added comments

as always comments, remarks and ideas are welcome
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up