Is my logic correct?
lardom
Posts: 1,659
I'm trying to find a solution for the occasional false reading I get from my Ping sensor. I want two or three values to match out of four returned from the sensor. I decided to try to copy four ping return values to four variables, test all combinations and increment a fifth variable for each match. Is there a better way?
PUB Test_combinations | a, b, c, d, temp a := sensordata b := sensordata c := sensordata d := sensordata if a == b temp := a temp += 1 if a == c temp := a temp += 1 if a == d temp := a temp += 1 if b == c temp := b temp += 1 if b == d temp := b temp += 1 if c == d temp := c temp += 1 if temp => 2 call_method
Comments
My first attempts filled almost four pages.
Not sure whether this is a good idea for measuring movement, as the latest measurement will always be smaller than the measurement before if you move towards something. If your move away from something the latest measurement is always bigger. With this kind of filter in both cases you would ignore the latest reading. might be fine if the robot only moves at a constant speed, as then you simply have to bias the value calculated. But if it has variable speed you also need a variable bias.
What happens if a object crosses the robots track? It decreases the reaction time, as you at least need a number of samples which rapidly change the average.
@lardom:
The last code you posted (#7) looks a bit strange. What you need is an array of sensor-readings which is filled up as a ring-buffer. Then you loop over all elements and sum them up, meanwhile find the max- and min-value and subtract them in the end.