We have been asked several times which was the best method to detect someone approaching, for example to automatically turn on the screen of an interactive terminal. One relatively intuitive solution is to use a telemeter such as the Yocto-RangeFinder. This can work in most cases, but there are some pitfalls that you should avoid...
The usual working principle for telemeters is to send pulses, either acoustic or laser, and to measure the time they take to come back to the sensor after being reflected against an obstacle. A laser diode is used in the Yocto-RangeFinder.
The Yocto-RangeFinder is a tiny telemeter based on a laser diode
The sensor uses specific pulses which are recognized during the detection phase, even when the environment is relatively noisy with variable ambient light, or with the presence of identical telemeters in the immediate surroundings.
In the opposite to what one may imagine intuitively, the hardest case to manage is the absence of reflection, when there is no object to be measured. Indeed, the system works by looking for the best correspondence between the emitted signal and all the signals received. But when there is no target, the best answer is a false-positive, which can look like a low reflection but which is not really one. To detect the absence of a target, one must be able to distinguish between a maximum produced by a very low reflection and a maximum produced by the ambient noise.
Let's take a concrete example to illustrate this issue. The application consists in detecting as soon as possible a person who approaches in a relatively narrow room.
Inside test environment
Intuitively, we are going to configure the Yocto-RangeFinder in long range mode, to detect the person from as far as possible. Here is the raw result.
Raw measures in long range mode
This result illustrates quite well the subject matter. With a target up to 1m50, the raw measure is very good. Beyond that, we sometimes have an absence of measure, and then false positives without target. The reason is simple: the long range mode is the one which tries to detect the weaker reflections, to measure targets from as far as possible. It's also therefore the most sensitive mode to false reflections. In our relatively narrow environment, we incur a large risk of parasitic reflections against the white walls, creating these issues.
There is a solution to this issue. As the measures are very quick (>20Hz), and as long as you don't need a reactivity within a few hundredths of a second, we can allow ourselves to perform a statistical estimation of the measure quality and to filter out false reflections. By the way, we release this week a new firmware for the Yocto-RangeFinder which directly integrates this feature, so that you don't need to implement it yourself in your code.
Concretely, you have with this new firmware a get_quality method enabling you to evaluate the level of trust of the measure, based on the variance of the measure in the analysis window. And you now have a set_timeFrame() method to configure the statistical analysis window, and which is also used to compute an averaged value, and thus to have a more stable measure. To maintain compatibility with previous firmware, the default behavior remains an instant value. Here is the result of this new firmware for the same experiment (blue and green lines below).
Raw and filtered measures in long range mode
You can note that filtered measure are now directly usable, even if the price to pay is a small additional latency, as we expected. The quality measure is indeed able to detect uncertainty areas, when the target is at the limit of the detection range.
A few tests
Let's take this opportunity to repeat this experiment in different conditions, in order to validate the detection distances indicated in the documentation for the different working modes of the Yocto-RangeFinder. Let's start with the default mode, with a light target: the person who is approching is wearing a light grey shirt.
Default mode, light target (inside)
We notice that filtering is not required in this environment in default mode, even if it improves the measure stability. Let's see what happens with a dark target, when the approaching person is wearing black fleece:
Default mode, dark target (inside)
The good news is that the detection works almost as well, up to 1m20. The difference is seen only on the measured quality, which is not quite as good. For this reason, the documentation qualifies measures on dark targets only up to 70cm, but in real life, if the target is not fully black, distances up to 1m20 are quite okay inside.
The high speed mode is less accurate, as expected:
High speed mode, light target (inside)
The statistical analysis makes up for this imprecision with averaging, but there is therefore no great advantage in using the high speed mode. So, unless the optimal speed is really essential, you should rather use the default mode which goes almost as fast.
And what about outside?
As indicated in the documentation, outside measures are much harder because the surrounding light is much stronger, and so the contrast margin of the optical sensor is weaker. Without filtering, the measure is hardly of use, but filtering at 1 second allows you a good detection up to 60cm:
Default mode outside
We wondered whether using the "high accuracy" mode would improve the measure quality outside, or if the "long range" mode would enable us to measure from father afar outside as well. This is unfortunately not the case, because, outside, the high accuracy mode tends to reject too many measures, while the long range mode is too noisy to be of use.
The high accuracy and long range modes are not useful outside
These observations confirm the indications of the documentation: outside, use the default mode and don't expect to detect farther from 50-60cm. For detection from farther away, you need to use an ultra-sonic telemeter, a light barrier, a mechanical detection device, or otherwise invest in a more powerful laser telemeter, but which is also much more expensive...