So we have a lot of sensors and a micro controller. How do we get to our event signals? That is what this page is all about. One component of our event signal for a given magnetic source is its distance from the sensor. We will start right there and firstly look at the relationship of magnetic field and distance.
Distance - magnetic field - relationship
The strength of the magnetic field of a permanent magnet decreases with increasing distance from the sensor. This decrease is non-linear and the equations involved are non-trivial, it depends on the material and form of the permanent magnet. As a general rule, a cubic relationship is assumed. Nowadays, magnetic fields can be approximated with finite-element calculations, this however is overkill and not at all possible in realtime on a microcontroller. To approximate the distance of a given magnet from the sensor based on the sensed magnetic field flux at the latter in realtime it is therefore best to do some non-linear curve fitting for the given pair of sensor and magnet before-hand. In realtime, the fitted distance-function is simply applied to the sensed magnetic field flux.
Instead of distance, we use the concept of vicinity ( ) because in the end we are interested in how near we are to the sensors and not how far away from them. The following simple function to get normalized vicinity from the normalized magnetic flux has been shown to be adequate for the type of sensors and magnets (Neodymium) we use:
Measured and least-squares estimate between magnetic field at and vicinity to the sensor.
The relationship can vary considerably between different types of permanent magnets, the Chimaera therefore can be calibrated on-the-fly to different types of permanent magnets. This is done with a five point least squares fit and leads to an analytical solution with the help of some linear algebra.
Get familiar first with the hardware of the Chimaera sensor unit, it will help a lot to understand all the following.
Although we now know the relationship between magnetic flux and vicinity we cannot yet approximate the distance of a magnet from its sensor. From the sensor unit we get a voltage which is linearly related to the magnetic flux the currently active sensor is in. However, the sensors do not all have the exactly same sensitivity and quiescent output, their values scatter over a given range. We have to take care of this firstly.
An ideal linear hall-effect sensor outputs a voltage dependent on its sensitivity and magnetic flux relative to its quiescent voltage output .
Both and vary between sensors. To make the voltage output of sensors comparable to each other (which is a prerequisite to interpolate between them later on), we need to calibrate them and apply the calibration data in a normalization step. But before we can do that we also have to consider the amplification of the voltage signal at the sensor unit.
The voltage output after the amplification is dependent on the sensor voltage , the reference voltage at the OpAmp, and the amplification factor of the OpAmp.
is what we measure with the analog-to-digital converters at the microcontroller. This is the only thing we can measure directly. We now have to apply some simple math to get to one value we want in the end: the relative vicinity normalized relative to the whole sensor array.
In the case of no magnetic field, we can measure the amplified quiescent voltage of each sensor from which we can solve for and rewrite .
we can measure, we can measure, too. we want to know finally. The next therefore is to decipher and . For this we define a new single parameter . With a known we could already calculate the latter, but we want to calculate it over both polarization domains concurrently to be more robust. We therefore look at the output voltages for an arbitrary magnetic field strength, once south polarized and once north polarized .
So, with measured at and at a arbitrary , we get to . But how do we know ? It’s quite simple, we can numerically approximate it with the inverse of the magnetic-field-distance relationship, because vicinity is something we can easily measure, too. By doing so, we also have to define what the normalized magnetic flux actually is.
Let us get one step further. In the end we want vicinity to be mapped continuously from . will be at a threshold magnetic flux , in turn at the maximal to expect magnetic flux . will be the normalized measured magnetic flux between the two extremes and depends on the three constants , and :
and are different for each sensor (so they are actually two arrays of constants each), is the same for the whole sensor array. By calibrating them once, we get from the sensor unit voltage output directly to the normalized magnetic field strength with only 3 mathematical operations (efficiency is important as we are on a microcontroller, e.g. we have to cope with limited computation power).
From the normalized magnetic flux we then get to the vicinity . As those vicinities are comparable over the whole sensor array, we are now ready to interpolate the position of the magnetic source along the sensor array axis.
Blob event handling
With a blob we refer to a recognized magnetic field source (e.g. permanent magnet) that is to be tracked over space and time. Blob event handling can be divided into several stages: decipher polarity, narrowing down the area of interest on the sensor array, actual blob detection, interpolation of blob position, group association and blob tracking.
Magnetic flux polarity
First thing that is to be done is to discriminate between the polarities of the potentially present magnetic field sources. For each sensor value, we therefore subtract the previously calibrated quiescent value, so we get the difference of the present raw sensor value from its quiescent value. The sign of this difference gives us the polarity of the magnetic source we are encountering here, e.g. south and north polarity. The absolute value of the difference gives us the strength of the magnetic field (which is to be normalized with previously calibrated factors in a later step).
Area of interest
After each scan of the whole sensor array, areas of interest are marked on the array. These are regions, where the sensor value exceeds the threshold magnetic flux . The rest of the sensors are not of interest for the further steps. We do not apply the distance-magnetic-field relationship over all sensors at this step, as it would be computationally too costly. During calibration, for each sensor we precalculated its raw value corresponding to threshold magnetic flux . This then can be efficiently checked against for each sensor at each update step to find out whether the threshold has been exceeded or not.
In the next step, we search for peaks in the areas of interest. A peak will correspond to an individual magnetic field source and is simply defined as a sensor with an absolute value which is greater than the values of a given number of adjacent sensors in the same area of interest. We save all found peaks along the sensor array for the blob’s positional interpolation in the next step.
As always more than one sensor is excited by an individual magnetic source, we can decipher its real position by interpolation around the peak sensor. We therefore fit curves over a varying number of sensor values around the peak and find the maximum by finding the cross point of the curve’s derivative. Only at this step we convert the sensor values into normalized vicinities based on calibration data. For efficiency reasons, we use a precalculated lookup table for the distance-magnetic-field relationship, because the cube root and square root functions would be too costly.
We can use varying numbers of adjacent sensors to the peak and fit linear, quadratic, cubic or spline functions through the values. The coordinates of the maximum will be the current position of the blob on the sensor array.
Vicinities of four adjacent sensors and no fit (order 0), e.g. the highest value is its own fit.
Vicinities of four adjacent sensors and a linear fit (order 1) between the two highest values.
Vicinities of four adjacent sensors and a quadratic, aka hyperbolic fit (order 2) betwwen the three highest values.
Vicinities of four adjacent sensors and a cubic fit with Catmull-Rom splines (order 3) between all four values. Only the spline segment between the highest values is shown.
Vicinities of four adjacent sensors and a fit with a Lagrange polynomial (order 3) between all four values.
For convenience, we have introduced a concept of groups. Each blob has not only a given position on the sensor array, but is also affiliated to a group. A group is defined by a range ( ) on the sensor array and magnetic field flux polarity (south, north or both). Only blobs with a position in the range of - and a polarity corresponding to a given group will be associated with the latter.
Groups can overlap, e.g. there can be two groups for the same range with differing polarities. A blob can only be part of one group at a time though and will be affiliated to the first matching one.
Up to now, everything we have done was based on the current state of the sensor array. However, to track blobs over time, there needs to be a means to associate identified blobs in the current iteration to blobs found in previous iterations to decipher whether new blobs have appeared or old ones have disappeared.
To link current blobs to previous blobs they are matched by position on the sensor array. Each new blob gets a unique ID, which will persist over time as long as the blob can be linked to itself in a previous iteration step, until the blob disappears. In the special case when a blob can be linked but has exited its previous group, it will be regarded as a new one, too.
Out of the blob tracking, we get a stream of event signals: When a new blob has appeared, an on event is triggered. When a blob could be linked to a previous iteration step, a set event is triggered to update the blobs position. When a blob has disappeared, an off event is triggered. All event signals will be triggered with complete set of current parameters: position , polarity (south or north) and group association.
So, what the firmware does in the end is: converting a raw array of sampled sensor values into a stream of blob event signals. The event signals now can be translated into a given transport protocol and sent over the network to drive other software or hardware. This is elaborated upon in a dedicated section, the usage.