Hi, I just connected an ultrasonic range sensor to my arduino and it works pretty well. However, when im changing from a flat surface to an uneven survace, a value of 3200 cm appears once (which is a false reading). My question is: Is there a function like read.ignore(3200) or does it only work with if...else . I have searched and not found an answer and im asking because I need to optimize the code and make it simpler.
No there is no function like that, but it is extremely simple for you to just compare the value you got and treat it differently if it is outside the range of expected values.
you might try averaging several readings and when you get one that seems to be out of range you would ignore it and decide whether to average it in. Or you might have to running averages, one that does not average the outliers and one that does, and if the outlier average its tracking with you readings then you update the main running average with the secondary running average.
there would be some lag in the response when there is a large step change, but if this is not a normal condition, it gives you an automatic way of handling them.
Euh... Not sure I follow, if my sensor has "normal" values between 0-100 and a random value of 350 appears once in a while, wont the constrain function ignore it?
Theelectronicguy:
Euh... Not sure I follow, if my sensor has "normal" values between 0-100 and a random value of 350 appears once in a while, wont the constrain function ignore it?
Hmmm... not sure what you mean by "ignore" in this context ?
Well, it shoulndt really matter in my case as the value only appears for a split second. I am trying(or will be trying) to make my quadcopter auto-land.
Ah, ok. Anyway, I think we can say is that "ignoring" an input is not something that you look a function for. It's a matter of how your algorithm(s) deal with certain input values. IMHO, obviously
Theelectronicguy:
Well, it shoulndt really matter in my case as the value only appears for a split second. I am trying(or will be trying) to make my quadcopter auto-land.
That may be a problem mate... Don't ignore something so simple to solve that can destroy your project!