Need help with the Average.h library

Hi there. I'm having some strange problems with what seems to be the Average.h library. I get the following errors:

         float lat1 = mean(lataverage, latslice);

                                               ^

C:\Users\3570\Documents\Arduino\V02\V02.ino: In function 'void GoToWaypoint(float, float)':

V02:222: error: 'mean' was not declared in this scope

           float lat1 = mean(lataverage, latslice);

                                                 ^

V02:244: error: 'mode' was not declared in this scope

           float bearing = mode(average, slice);

                                              ^

C:\Users\3570\Documents\Arduino\V02\V02.ino: In function 'float GetBearing()':

V02:361: error: 'mode' was not declared in this scope

   return mode(average, compassavg);

The code is too big to be posted here, so click for Google Docs.

Thanks a lot!

And where did Average.h magically appear form?

septillion: And where did Average.h magically appear [u]from[/u]*?

From here.

Please do go past my humor if you find it. I really need to know why I'm having this problem.

EvhCo2000: From here.

Please do go past my humor if you find it. I really need to know why I'm having this problem.

Your Google is not my Google. I could be in a different country to you. Just googling for a relatively common name will give totally different results for different people.

WHERE DID YOU GET THAT LIBRARY?

Besides the country (and the fact I'm singed in to Google) which alters the results, there is no guarantee there is only one Average library (because, come on, the name is a bit generic) and we downloaded the same.

But I do get the humor of LMGTFY, use it myself as well. But damn, the new style is ugly.... Why did they integrate a browser window??? And macOs...

Ow, and to solve the problem. That's also part of where did you get it ;) Cause if you meant Arduino.cc Average and downloaded the code form GitHub you now also spot the problem with the "tell the source part". As a hint, have a look at the example folder ;)

Okay, screw it, spoiler. They changed the library ;)

septillion:
Cause if you meant Arduino.cc Average and downloaded the code form GitHub you now also spot the problem with the “tell the source part”. As a hint, have a look at the example folder.

That’s actually exactly where I downloaded it (the GitHub code). I glanced at the examples folder and, after some testing, I replaced every mean with ave.mean.

Also added Average ave(10); and I got

no matching function for call to 'Average<float>::mean(float [latslice], int&)'

EDIT:
Also tried with average=mean and I got “average not declared in this scope”. It’s been some time since I last laughed that bad.

let's try this a different way.

what are you REALLY trying to do ?

you have us running in circles without offering any possibiliy of help to your REAL need.

are you trying to average a temperature reading that you are taking once per hour ?

if your only TRUE goal is to learn that specific library, then we are on the right track. if your only TRUE goal is to get your project working, we may find you do not need to average anything because your devices or code can be altered.

dave-in-nj: if your only TRUE goal is to learn that specific library, then we are on the right track. if your only TRUE goal is to get your project working, we may find you do not need to average anything because your devices or code can be altered.

The code itself, as you would have noticed if you took a look at the Google Docs link, is from an autonomous oceangoing ship I intend to build for the Microtransat race blah blah blah. The average library is used mostly for codes like

float lat1 = mean(lataverage, latslice);

As I didn't write the code, I didn't want to alter the code much as it could break the boat's "behavior".

EvhCo2000:
I glanced at the examples folder

Then stop glancing and open the example and study it :wink: Then you’ll notice more then the name changed :wink:

septillion: Then stop glancing and open the example and study it ;) Then you'll notice more then the name changed ;)

I almost pasted the code into mine. Same thing. It's the first time I've ever made "contact" with the average.h library.

Also, let me put in simple english one thing:

I. Did. [u]NOT[/u]. Write. The. Code. This is why I have [u]no idea[/u] what's wrong with it or what average.h does in this code, nor do I know how to modify it in such way that average.h is no longer needed.

Okay, looks like I managed to remove the average.h library. Now I get this:

'class HMC5883L' has no member named 'SetMeasurement'

Case closed I guess. I’ll simply use the more complex and complicated variant of the code (the one that requires two Arduinos. Like I wasn’t bankrupt enough). Thanks to everyone who tried to help.

If anyone needs me, I’ll be in my room ripping the flesh of my face.

EvhCo2000: I. Did. [u]NOT[/u]. Write. The. Code.

That's not. our. problem!

EvhCo2000: This is why I have [u]no idea[/u] what's wrong with it

There is NOTHING wrong with it. You simply try to use it wrong.

EvhCo2000: or what average.h does in this code,

What about averaging?

Two options to fix the problem, a) change the code in a way the downloaded code wants you to b) Or simply use the version used in the passed which you should have got with the code in the first place!

EvhCo2000: Case closed I guess. I'll simply use the more complex and complicated variant of the code (the one that requires two Arduinos.

Why? Simply read more what the error, the documentation, the people here, the comments in the code (at least you do have some) and the code tells you ;) And don't just play code monkey and button bash keys...

septillion: Simply read more what the error, the documentation, the people here, the comments in the code (at least you do have some) and the code tells you ;) And don't just play code monkey and button bash keys...

I'll sure give more time and try and figure out what the heck is wrong with it, at least for the sake of programming if not for the boat itself. This is getting frustrating.

septillion: There is NOTHING wrong with it. You simply try to use it wrong.

Explain, please. All I'm doing is hit the "Verify" button. What am I doing wrong?

septillion: Triggered

( ͡° ͜ʖ ͡° )

Very rarely code does what you want if you just hit keys or put in random words...

The mean() method doesn't accept parameters anymore. It only gives you the mean from the current set. Which, you apparently have to put there with the push() method.

But because it's existing code, just get a copy of the old version. I don't know who wrote it and how you got it but in my opinion the libraries used in the project should have been included in the first place.

I'm seeing a "throw everything at the wall and see if it sticks" approach. You need to build up understanding in small doses.

For any new library or sensor, I will always create a small program in a "test" subfolder. Just the basics to see if the sensor is working. Usually this will be one of the examples that came with the library, modified for my pin numbers. I will return to that test program many times during development. If my big program stops working, then I'll upload the test, just to reassure myself that the wires are still working.

From that test, then I will usually work outwards: add more sensors and more libraries. Occasionally, I will try to copy-paste the test code into the "big" program.

septillion_the_triggered: Very rarely code does what you want if you just hit keys or put in random words...

The mean() method doesn't accept parameters anymore. It only gives you the mean from the current set. Which, you apparently have to put there with the push() method.

But because it's existing code, just get a copy of the old version. I don't know who wrote it and how you got it but in my opinion the libraries used in the project should have been included in the first place.

And why on earth didn't you say so the first time? Why? Just why?

Decided to switch to the 2-Arduino version of the code, because the board is simply too slow to update the rudder according to the GPS by itself. In the middle of the ocean, this could be a problem. I'll still modify the code with your information and upload it for the sake of anyone who will try and use this code nowadays. Guess I can call this a day.

Do you know what makes it slow? Floats! (Bit ironic on a boat...) Why is the GPS data a damn float?

septillion:
Do you know what makes it slow? Floats! (Bit ironic on a boat…) Why is the GPS data a damn float?

Probably lazy programmers.

The OP could switch to a different Arduino board entirely. There exist different models of Arduino, some of which may well be better at handling floating-point numbers than others.

As for calculating an average: you don't know how to do this? Just add up the numbers you intend to average, then divide by how many numbers there are.

Example: Average these numbers: 2.82, 2.83, 2.9 Method: 2.82 + 2.83 + 2.9 = 8.55 8.55 divided by 3 (because there are 3 numbers) = 2.85 Answer: 2.85

Writing your own code to do this is a relatively simple exercise.