If no one has noticed yet- my weakpoint in robotics is software (I only took a half year course in C++, and tried to reach myself the rest). My question regards making an Ultrasonic sensor more reliable. The sensor takes readings about 22 times a second, and since its going so fast ever so often it has a bogus reading. Right now to kinda smooth out the readings, I take and average the first 10 readings then convert that into my usable inches foramt. But sometimes for instance- it might take 9- 14inch readings and 1- 230inch reading, and that obviously throws off the average by a good amount, causing a false trigger, or no trigger when it should have.
I am wondering if there is an efficient way to analyze the first 10 values, then allow only like the ones that fall within say 80%-90% of the mean. I think I could do this on my own with a few hundred lines of repetitive- extraneous code, but does anyone know of a function that already exists that could do this, or a way to do it with as little effort as possible?
I am using the Arduino language, so if anyone could help in that format or a similar C++ format I can understand that would be terrific.
Thanks in advance- Brandon