
Check the documented invalid-distance marker before averaging LRF50H reports. Exclude that marker from both the distance sum and the valid-sample count, and return an unavailable result when no valid samples remain. Replacing an invalid reading with zero, or treating an old reading as a new observation, can produce a plausible but misleading average.
Why a working serial link can produce a bad average
The documented LRF50H output expresses distance in centimetres and uses raw 65535 to indicate out of range. That marker is a status indication, not a measured distance of 655.35 m. ERDI’s documentation review for this note checked the model-specific protocol on 25 September 2026. Confirm that the delivered firmware and selected output format match that documentation.
A complete report that passes the protocol checks can still carry the out-of-range marker. Separate transport integrity from measurement validity. The existing high-rate integration guide discusses filtering, validity and data age; this note turns those principles into a small, repeatable acceptance exercise for an industrial distance display or logger.
One invalid value, three different averages
Use five synthetic decoded reports: 498, 500, 502, 500, 65535. The first four values are invented inputs around 5 m; the last is the documented LRF50H marker. Assume framing and checksum validation already passed, and that these five reports form one host-side calculation window. Five is an illustrative window size, not a module setting, output rate or recommendation for a control loop. No hardware measurements are claimed.
| Host treatment | Calculation in centimetres | Displayed result |
|---|---|---|
| Average all raw numbers | (498 + 500 + 502 + 500 + 65535) / 5 | 135.07 m |
| Replace the marker with zero | (498 + 500 + 502 + 500 + 0) / 5 | 4.00 m |
| Exclude the marked entry | (498 + 500 + 502 + 500) / 4 | 5.00 m; 4 valid of 5 reports |
The formula is mean_cm = sum(valid raw distances) / valid_count, followed by mean_m = mean_cm / 100. Evaluate it only when valid_count > 0. Masking one value while still dividing by five is equivalent to the zero-replacement mistake.
This exclusion rule has a direct software analogue: the official NumPy masked-array mean documentation states that masked entries are ignored. Your application must supply the validity mask; the finite integer 65535 does not identify itself as missing data to an ordinary averaging function. The arithmetic above requires no particular software library.
Repeating the previous 500 cm value in the invalid slot would also produce 5.00 m here, but would falsely turn four observations into five. An unchanged display alone therefore cannot demonstrate correct handling. Check the valid count and timestamps as well as the number on screen. Excluding the marker does not establish accuracy or make the remaining samples representative of a moving surface.
Make the window and its expiry explicit
For this exercise, maintain the last five complete, protocol-checked report slots. Every such report advances the window. A marked report occupies a slot with no distance; it still ages older slots out. Otherwise, a buffer that advances only on valid reports can retain old distances throughout a dropout.
Report both the number of valid distances and the number of checked reports in the window. The example’s 4/5 is a window statistic, not an optical confidence score or an end-to-end delivery rate. Count incomplete data, checksum failures and detected transport loss separately; they are not included in that denominator.
A report-count window stops advancing when the link goes silent. Add a separate freshness check using elapsed time from a monotonic clock. Record host reception time for each accepted valid distance, and retain the oldest and newest contributing times for the average. New invalid reports must not refresh the last-valid time. Host reception time does not establish the instant of optical measurement.
Define the maximum last-valid age and allowed age of contributing samples from the application’s needs. Check expiry even when no bytes arrive. Remove expired contributions and expose an unavailable or stale state when the application’s age or minimum-valid-count rule fails. No numerical timeout or minimum count is specified here as an LRF50H requirement.
Run these checks before accepting the display
- Mixed window: inject the five synthetic decoded reports above. Expect 5.00 m with four valid distances and five checked reports. This exercises the averaging layer after parsing.
- All invalid: inject five consecutive reports carrying 65535. Expect zero valid distances and no numerical mean. Do not divide by zero or report zero metres.
- Continued invalid reports: verify that report reception advances while the last-valid timestamp stays unchanged. Any retained display value must be labelled historical and subject to expiry.
- Silence: stop supplying reports after a valid window. Advance the test clock beyond the application’s age limits. Expect expiry without needing another receive callback.
- Recovery: supply one fresh, synthetic 500 cm report. Expect one new valid observation, not five copies of it. Resume a usable output only when the application’s count and age rules are met.
- Parser failure: test a damaged report separately at the parser boundary. It must not become a zero-distance sample or increment the accepted-report count. Record the transport failure independently.
These checks verify the software’s handling of the supplied cases. They do not validate optical performance, latency or suitability for a machine safety function. For a focused documentation check, contact ERDILRF with your model, output format and a short raw-report trace.