editor's blog
Subscribe Now

Quaternion and Kalman

If you’re new to the world of motion and navigation (as I feel I still am, even after a couple of years of digging in), there are a couple words that come up a lot. And they’re usually tossed about casually in that, “If you have to ask, you’re not cool enough for the answer” kinda way. (Mostly, when I sport that attitude, it’s because I don’t really know what I’m talking about and I want to dissuade anyone from calling me on it…)

Those two words are “quaternion” and “Kalman.” I’ll give you a few seconds to repeat them quietly to yourself, Mr. Rogers style.

Let’s take them one at a time, since they’re not really related.

The context in which you might find “quaternion” is in the output of a motion sensor. Now, with the increase in sensor fusion and higher-level abstraction, many of you might not need that output – you’ve already got software that hides this low-level information.

But here’s what it’s about: the math of rotations, although that’s not how it started. Way back in the 1800s, a guy named Hamilton noted that, using standard three-dimensional math, points were easy to add and subtract in space, but multiplication and division were cumbersome. He invented a way of handling this by adding a fourth dimension and, effectively, extending the complex numbers as we know them to include a j and k along with the more familiar i*.

The defining characteristic is

                i2 = j2 = k2 = ijk = -1

But, as the tale is told, vector calculus overtook this method and it dropped out of sight until much more recently. Because, among other things, rotations – which require three moves using standard Euler angles and rotation matrices – can be accomplished in a single move using quaternions. This mathematical efficiency allows calculation of rotations in less time.

There’s another problem that quaternions solve: that of “gimbal lock.” There seem to be a bunch of ways of describing this, but mathematically it means more or less that one of your independent dimensions becomes degenerate with another.

From a practical standpoint, here’s how it feels to me. Let’s say you’re watching an airplane pass nearly overhead. You tilt your head back as it approaches, and, if it passes to your left, your head (and body) rotate around towards your left until you’re facing the opposite direction as the plane continues on, with your head now descending gradually as the plane disappears.

All of those movements are “predictable” (for lack of a better word). But assume the plane goes right over your head. You tilt your head back with no rotation (because it’s neither to the left nor the right of you). But once you’re looking straight up as it passes over your head, what do you do? You effectively have to make an infinitely fast rotation to face backwards, and it’s not well defined (or “predictable”) what that rotation should be (because it’s infinite) nor whether you would do it to the right or the left. That is one manifestation of gimbal lock: at that point when you’re looking straight up, you effectively lose a dimension.

Or something.

Therefore, once expressed in quaternions, it becomes easier to calculate orientation as objects move and rotate through space.

What about that Kalman dude? You typically hear about a Kalman filter, and you typically hear it in contexts that make no sense for what you might think a filter does. Like figuring out where you are based on where you’ve been and whatever move you just made. How the heck does a filter get involved with that?

Well, I’m not sure I can justify the word “filter” so I won’t try (I’m sure there’s a good – probably historical – reason). But here’s what it’s about, and to make sense of it you have to own up to a couple of realities that might shake your faith a bit.

  • The models we have for how the world works are approximate. Using them unquestioningly (like doing anything unquestioningly) will lead to errors. This one you probably knew already.
  • Real-world measurements of things, which you would assume to reflect the “gold standard” for what’s real (as opposed to a model), are riddled with errors. At best, there’s going to be noise in the measurement, and you don’t really know which part of a given measurement is the noise and which part is accurate.

In other words, you can’t trust your model and you can’t trust your measurements. You might as well toss up your hands and go home.

But… not so fast.

A Kalman filter can act as an arbiter between model and measurement. Generically speaking, you build an engine that takes a current value – let’s say it’s a position – and evaluates both the model and the last measured position (or “update”) and, from that information, calculates what it thinks the next position will be. The filter operation is a steady sequence of predict/update steps. You might imagine that this has figured large in space exploration (which I believe was the first solid use).

The concept is very generic: the models and next-state prediction are specific to a problem (which might have nothing to do with position), and numerous parameters might be involved. For instance, your model might not simply predict position using x, y, and z coordinate measurements; it might come from double-integrated acceleration measurements, cross-checked by gyroscope measurements to guard against gravity leakage, which is itself cross-checked by a magnetometer, and you might toss a pressure gauge in there as well as a second-opinion indicator of the z dimension.

These can all be munged together in the model and calculation. The “gain” of the filter has to do with how much trust is placed in the actual measurement. A high gain indicates highly credible measurements; a gain of 0 means the measurement is ignored.

Those are my takes on quaternions and Kalmans. Feel free to amplify, contradict, or whatever in the space below.

 

 

* i, for some reason, got transmuted to j in all of my engineering studies… one of those things that just happens in some class, you scratch your head wondering what happened, and no one else – not even the prof – appears to notice or explain why we suddenly made this arbitrary change.

Leave a Reply

featured blogs
Jun 18, 2021
It's a short week here at Cadence CFD as we celebrate the Juneteenth holiday today. But CFD doesn't take time off as evidenced by the latest round-up of CFD news. There are several really... [[ Click on the title to access the full blog on the Cadence Community sit...
Jun 17, 2021
Learn how cloud-based SoC design and functional verification systems such as ZeBu Cloud accelerate networking SoC readiness across both hardware & software. The post The Quest for the Most Advanced Networking SoC: Achieving Breakthrough Verification Efficiency with Clou...
Jun 17, 2021
In today’s blog episode, we would like to introduce our newest White Paper: “System and Component qualifications of VPX solutions, Create a novel, low-cost, easy to build, high reliability test platform for VPX modules“. Over the past year, Samtec has worked...
Jun 14, 2021
By John Ferguson, Omar ElSewefy, Nermeen Hossam, Basma Serry We're all fascinated by light. Light… The post Shining a light on silicon photonics verification appeared first on Design with Calibre....

featured video

Kyocera Super Resolution Printer with ARC EV Vision IP

Sponsored by Synopsys

See the amazing image processing features that Kyocera’s TASKalfa 3554ci brings to their customers.

Click here for more information about DesignWare ARC EV Processors for Embedded Vision

featured paper

What is a Hall-effect sensor?

Sponsored by Texas Instruments

Are you considering a Hall-effect sensor for your next design? Read this technical article to learn how Hall-effect sensors work to accurately measure position, distance and movement. In this article, you’ll gain insight into Hall-effect sensing theory, topologies, common use cases and the different types of Hall-effect sensors available today: Hall-effect switches, latches and linear sensors.

Click to read more

featured chalk talk

TDK Magnetic Sheets For EMI and NFC Applications

Sponsored by Mouser Electronics and TDK

Today’s dense, complex designs can be extremely challenging from an EMI perspective. Re-designs of PCBs to eliminate problems can be expensive and time consuming, and a manufacturing solution can be preferable. In this episode of Chalk Talk, Amelia Dalton chats with Chris Burket of TDX about Flexield noise suppression sheets, which may be just what your design needs to get EMI under control.

Click here for more information about TDK Flexield Noise Suppression Sheets