newPing, median timer, one sensor cycle method

Issue #69 resolved
Former user created an issue

bare with me, i'm a hobbyist here.

after performing ITERTIONS of sampling the sonar sensor, it'll call oneSensorCycle() correct?

This loops through, and insertion sorts all the samples one by one. But isn't that only if the cm[i] values aren't NO_ECHO? only inserts valid cm[] readings

if you get the first half the cm[] array filled with NO_ECHO, won't the variable "it" be decremented enough times as to not have a valid return via uS[it>>1]?

because the main FOR loop condition is "i < it". in the above scenario it will be half the array size, and "i" will no longer be below "it"

should you just iterate through all of cm[] by having the loop condition be i<ITERATIONS and have the uint_t "it" incrementing to be compared in the inner for loop that uses j? making "it" just mark the top of valid uS[] entries?

for (j = it; j > 0 && uS[j - 1] < cm[i]; j--) // Insertion sort loop.

start "j" off at "it" at the top of uS[]. because uS[] may be smaller than cm[] size because "i" won't necessarily be the same as "it", because of possible "NO_ECHO" entries in cm[].

sorry if I sound confused. I was just wondering if i'm misreading what happens.

I was just thinking that if you have over half of cm[] as "NO_ECHO" that, depending on the arrangement of the no_echo's, cm[it>>1] might not be filled with anything, or not the actual median.

this bug report says 1.9.1, but inside duino app (chromebook app) from the libraries browser says 1.9.4

and it++ before leaving the if(cm[i]

Comments (2)

  1. Tim Eckel repo owner
    1. The cm[] array is never filled with NO_ECHO (zero values). It doesn't store these values to the array and decrements the it value to accommodate.

  2. Log in to comment