NiVO / BY TECHNOGISGermany · Indonesia
Rangefinder telemetry tutorial

MAVLink DISTANCE_SENSOR: Distinguish Unknown Quality from an Invalid Signal

Interpret DISTANCE_SENSOR signal-quality markers and distance units on constructed decoded fields, retaining unknown variance without inventing sensor confidence.

MAVLink DISTANCE_SENSOR: Distinguish Unknown Quality from an Invalid Signal

Read the status marker before interpreting a distance

A distance column can look reassuringly precise while an adjacent quality field says something entirely different from what a dashboard label suggests. In MAVLink DISTANCE_SENSOR, the lowest quality codes have special meanings. Treating every integer as an ordinary percentage hides the difference between information that was not supplied and a signal that the sender marked invalid. Before interpreting a rangefinder record, retain the original field names, raw values, sender identity, and the message definition used to decode it.

This tutorial works with three invented, already decoded values: current_distance, covariance, and signal_quality. It does not connect to a drone, parse a packet, measure an obstacle, or determine which rangefinder a NiVO aircraft carries. The catalogue photograph supplies separate product context. The local function converts declared units and gives the quality markers distinct labels. Its output is a representation trace for a telemetry review, not a decision about flight readiness, safe clearance, ground height, survey accuracy, or sensor installation.

Keep the three documented field meanings distinct

The MAVLink common definition gives current_distance in centimeters. It describes the field named covariance as measurement variance in square centimeters, with the maximum unsigned byte value identifying unknown variance. The signal_quality extension is sensor specific: zero means unknown or unset, one means invalid signal, and one hundred is the documented perfect-signal endpoint. Those meanings belong to different fields. A distance number, a variance marker, and a quality label should not be collapsed into a single confidence percentage.

For the constructed distance of twelve hundred thirty-four centimeters, the unit conversion gives twelve point three four meters. With covariance equal to two hundred fifty-five, variance remains unknown rather than becoming a large physical variance. With signal_quality equal to zero, the quality label is unknown or unset rather than measured zero quality. Changing only that field to one must change the label to invalid signal while leaving the original distance and unknown-variance record intact. The function reports what was supplied without repairing it.

NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips
NiVO VTOL V7 with a white fuselage, lift rotors, and yellow wing tips.Source: NiVO / TechnoGIS catalogue materials supplied by the site owner · Catalogue photo
Product context only; this photograph does not depict the constructed examples in this article.

Run an explicit decoded-field profile locally

Use the following Python function only after obtaining the decoded fields and their correct definition. It accepts an unsigned sixteen-bit distance, an unsigned byte covariance field, and a quality value from zero through one hundred. Booleans and other input types are rejected. That quality interval is an explicit teaching profile: higher byte values are rejected rather than given an invented interpretation. The function preserves the complete raw triple so another reviewer can reproduce its interpretation.

The returned signal_percent is intentionally absent for the two special markers. Ordinary values above one retain their supplied percentage number, including the documented endpoint at one hundred, with a separate state label. A covariance value other than the unknown marker is converted from square centimeters to square meters by dividing by ten thousand. This is a dimensional conversion only. The code does not calculate a standard deviation, infer a maximum sensor error, validate a statistical model, or promote a reported variance into a calibrated accuracy statement.

def describe_distance_fields(distance_cm, covariance, signal_quality):
    fields = (distance_cm, covariance, signal_quality)
    limits = (65535, 255, 100)
    if any(type(x) is not int or not 0 <= x <= limit
           for x, limit in zip(fields, limits)):
        raise ValueError("Expected decoded fields within the teaching profile")
    if signal_quality == 0:
        state, percent = "unknown_or_unset", None
    elif signal_quality == 1:
        state, percent = "invalid_signal", None
    else:
        state = "perfect_signal" if signal_quality == 100 else "reported_percent"
        percent = signal_quality
    return {"raw_fields": fields, "distance_m": distance_cm / 100,
            "variance_m2": None if covariance == 255 else covariance / 10000,
            "signal_state": state, "signal_percent": percent}

# Constructed decoded fields; no aircraft communication.
print(describe_distance_fields(1234, 255, 0))
print(describe_distance_fields(1234, 255, 1))

Test sentinel boundaries without rewriting the measurement

Test quality zero, one, two, ninety-nine, and one hundred independently. The first two must remain separate states with no ordinary percentage. The next two keep their numeric percentages, while one hundred retains its endpoint label. Test covariance zero, thirty-six, and two hundred fifty-five independently of those quality values. Thirty-six square centimeters becomes zero point zero zero three six square meters; the unknown marker becomes None. None is an explicit missing interpretation, not a replacement distance or a claim that variance is zero.

Include the distance endpoints zero and sixty-five thousand five hundred thirty-five as arithmetic boundary cases, without assigning either a universal valid-reading meaning. Also test negative numbers, fractions, Booleans, and quality values above the chosen profile. A successful conversion confirms only that this function followed its input contract. The real receiving workflow must still investigate device limits, message availability, timing, decoding, and the circumstances under which the sender populated these fields. A conversion test cannot establish the validity of a physical measurement.

Preserve orientation, device identity, and message availability

A range value is not automatically vertical height. The full message includes sensor identity and orientation information that this narrow function does not consume. Preserve those fields separately with the sender system and component. Do not rename distance_m as altitude or clearance merely because it is expressed in meters. The direction and geometry of the measurement need their own documented evidence, and a single record does not establish a surface reference or an obstacle-free volume around an aircraft.

Signal quality is also an extension field. A reader needs the actual dialect, protocol, sender implementation, and decoding context before deciding why a received field is zero. The local output deliberately says unknown_or_unset; it does not distinguish an omitted extension from an explicitly reported unknown value. Keep that unresolved question visible rather than supplying an ordinary percentage from a default. Likewise, do not carry a quality value from a neighboring sensor or record into this triple without documenting that separate association and its timing basis.

A percentage label should not be silently reinterpreted as the probability that a distance is correct. The message describes sensor-specific signal quality, so comparing two sensor streams also requires the relevant device definitions and operating context. This example deliberately leaves those comparisons undone. Do not average special markers with ordinary percentages, or replace unknown variance using a quality score. Such operations would add a new model that the function neither implements nor validates. Keep any proposed aggregation separate, state its assumptions, and test it against the actual receiving requirement before presenting a combined indicator.

Deliver the interpretation trace beside the original log

For an actual handoff, retain the unchanged log identity, record position, sender, sensor ID, timestamp interpretation, selected message definition, reader version, three raw fields, converted units, and distinct quality and variance states. Include one small independently checked example and list the fields deliberately left outside the function. If a report applies an acceptance threshold, document that policy separately with its technical basis. The existence of a numeric percentage does not itself supply an acceptance rule for a mapping or inspection deliverable.

In a NiVO-related telemetry discussion, this method explains why an unknown quality marker should not look like a measured zero-percent signal, and why an invalid-signal marker should not look like an ordinary one-percent score. It makes no claim about actual aircraft equipment, firmware behavior, customer logs, or sensor performance. Preserve the raw record and continue the independent checks required by the real task. The useful result is a reproducible distinction between supplied distance, reported signal state, and missing variance information.

Technical references

  1. MAVLink DISTANCE_SENSOR: units, quality markers, and extension fields ↗
  2. MAVLink original common.xml message definitions ↗
← All articles

Related articles

All articles ↗
LET’S TAKE FLIGHT

Your next mission
starts with a conversation.

Talk to our team