Docu about Filtersize HC-SR04 Plugin

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
Sasch600xt
Normal user
Posts: 164
Joined: 10 Sep 2018, 16:37

Docu about Filtersize HC-SR04 Plugin

#1 Post by Sasch600xt » 14 Sep 2020, 15:50

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
Screenshot 2020-09-14 154711.jpg (69.15 KiB) Viewed 4609 times
"the flat earth society has members all around the globe"

TD-er
Core team member
Posts: 8749
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Docu about Filtersize HC-SR04 Plugin

#2 Post by TD-er » 14 Sep 2020, 16:57

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)

Post Reply

Who is online

Users browsing this forum: No registered users and 90 guests