Page 1 of 1
Docu about Filtersize HC-SR04 Plugin
Posted: 14 Sep 2020, 15:50
by Sasch600xt
Hello,
coiuld someone explain the filtersize settings to me ?
I can´t find a docu about it.
Thank you so much and have a great day
Sascha
- Screenshot 2020-09-14 154711.jpg (69.15 KiB) Viewed 4752 times
Re: Docu about Filtersize HC-SR04 Plugin
Posted: 14 Sep 2020, 16:57
by TD-er
It is the first parameter of this function in the NewPing library:
Code: Select all
unsigned long NewPingESP8266::ping_median(uint32_t it, unsigned int max_cm_distance) {
unsigned int uS[it], last;
uint32_t j, i = 0;
unsigned long t;
uS[0] = NO_ECHO;
while (i < it) {
t = micros(); // Start ping timestamp.
last = ping(max_cm_distance); // Send ping.
if (last != NO_ECHO) { // Ping in range, include as part of median.
if (i > 0) { // Don't start sort till second ping.
for (j = i; j > 0 && uS[j - 1] < last; j--) // Insertion sort loop.
uS[j] = uS[j - 1]; // Shift ping array to correct position for sort insertion.
} else j = 0; // First ping is sort starting point.
uS[j] = last; // Add last ping to array in sorted position.
i++; // Move to next ping.
} else it--; // Ping out of range, skip and don't include as part of median.
if (i < it && micros() - t < PING_MEDIAN_DELAY)
delay((PING_MEDIAN_DELAY + t - micros()) / 1000); // Millisecond delay between pings.
}
return (uS[it >> 1]); // Return the ping distance median.
}
It looks like the number of pings performed and returning the median value. (for even number of pings it does not average 2 values, so strictly speaking it is only the median value for odd number of pings)