Schlüsselwortarchiv

Du betrachtest das Archiv des Tags Sensor Fusion.

• On integration drift

While imple­ment­ing a sen­sor fusion algo­rithm I stum­bled across the prob­lem that my well-cal­i­brat­ed gyro­scope would yield slow­ly drift­ing read­ings for the inte­grat­ed angles.
There are at least two rea­sons for this behav­iour: It is pos­si­ble that the gyro bias was not removed exact­ly — not so much because it’s a sto­chas­tic quan­ti­ty, but more because it’s a machine pre­ci­sion prob­lem after all — and drift induced dur­ing numer­ic inte­gra­tion due to round­ing errors.

Fouri­er states that every (infi­nite and peri­od­ic) sig­nal can be assem­bled by using only cosine and sine func­tions. Gauss­ian noise has a mean ampli­tude in all fre­quen­cies, but still a gauss­ian ampli­tude dis­tri­b­u­tion. In oth­er words: Gauss­ian noise con­tains dif­fer­ent­ly strong sine and cosine sig­nals for every fre­quen­cy.

Now the inte­gral of the sine and cosine func­tions is defined as fol­lows:

\begin{align}
\int cos(2 \pi f t) &= \quad \frac{1}{2 \pi f} sin(2 \pi f t) \\
\int sin(2 \pi f t) &= -\frac{1}{2 \pi f} cos(2 \pi f t)
\end{align}

What that means is that for every high fre­quen­cy sine-like sig­nal (i.e. $f \geq 1 \mathrm{Hz}$ ) , the ampli­tude of that sig­nal will be low­ered by fac­tor $2 \pi f$ . For every low fre­quen­cy sig­nal (i.e. $f \lt 1 \mathrm{Hz}$ ) the fre­quen­cy will be ampli­fied by $2 \pi f$ .

Now it’s just a ques­tion if your sig­nal con­tains gauss­ian noise or if your sys­tem oscil­lates. In any way, if there is a low fre­quen­cy com­po­nent, inte­gra­tion will turn it into a strong, slow sine wave shape — drift.

• To tilt compensate, or not to tilt compensate

When div­ing into the field of atti­tude detec­tion from sen­sor read­ings a cou­ple of answers seem omnipresent:

• You need an accelerom­e­ter and a mag­ne­tome­ter.
• You need to tilt com­pen­sate.
• You need to low-pass fil­ter.
• Or use the com­pli­men­ta­ry fil­ter.
• Or bet­ter still, use the mys­ti­cal Kalman fil­ter (but it’s too com­pli­cat­ed to explain).

Start­ing from the above and hav­ing an accelerom­e­ter and a mag­ne­tome­ter at hand, the old ques­tion a wise man once asked is:

To tilt com­pen­sate, or not to tilt com­pen­sate, that is the ques­tion—
Whether ’tis Nobler in the mind to suf­fer
The Slings and Arrows of out­ra­geous Stack­Over­flow answers,
Or to take Arms against a Sea of trou­bles,
And by using the atti­tude matrix, end them? To tilt: to roll.

In oth­er words: Is tilt com­pen­sa­tion required? Weit­er­lesen »

• libfixkalman: Fixed-Point Kalman Filter in C

In need for a Kalman fil­ter on an embed­ded sys­tem I was look­ing for a lin­ear alge­bra library. It turned out that there are quite a bunch of libraries writ­ten in C++, most­ly tem­plate based, yet noth­ing lean and mean writ­ten in ANSI C. I end­ed up port­ing parts of EJML to C and picked only what I need­ed for the Kalman fil­ter (see the result, kalman-clib, if you are inter­est­ed). The result was a work­ing, rel­a­tive­ly fast library using floats. Or dou­bles, if the user prefers.

How­ev­er, a big prob­lem is that many embed­ded tar­gets (say, ARM Cor­tex-M0/3) don’t sport a float­ing-point unit, so the search went on for a fixed-point lin­ear alge­bra library. Thanks to a hint on Stack­Over­flow it end­ed at lib­fix­math, which imple­ments Q16 num­bers (i.e. 16.16 on 32bit inte­ger) and is released under an MIT license.

Luck­i­ly, some oth­er guy cre­at­ed a lin­ear alge­bra library around it, called lib­fix­ma­trix (MIT, too). I start­ed to port my Kalman library to lib­fix­ma­trix and, voilà, lib­fixkalman was born (you can find it in the lib­fixkalman GitHub repos­i­to­ry).