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
Oct 20, 2020
In 2020, mobile traffic has skyrocketed everywhere as our planet battles a pandemic. Samtec.com saw nearly double the mobile traffic in the first two quarters than it normally sees. While these levels have dropped off from their peaks in the spring, they have not returned to ...
Oct 20, 2020
Voltus TM IC Power Integrity Solution is a power integrity and analysis signoff solution that is integrated with the full suite of design implementation and signoff tools of Cadence to deliver the... [[ Click on the title to access the full blog on the Cadence Community site...
Oct 19, 2020
Have you ever wondered if there may another world hidden behind the facade of the one we know and love? If so, would you like to go there for a visit?...
Oct 16, 2020
[From the last episode: We put together many of the ideas we'€™ve been describing to show the basics of how in-memory compute works.] I'€™m going to take a sec for some commentary before we continue with the last few steps of in-memory compute. The whole point of this web...

featured video

Demo: Low-Power Machine Learning Inference with DesignWare ARC EM9D Processor IP

Sponsored by Synopsys

Applications that require sensing on a continuous basis are always on and often battery operated. In this video, the low-power ARC EM9D Processors run a handwriting character recognition neural network graph to infer the letter that is written.

Click here for more information about DesignWare ARC EM9D / EM11D Processors

featured paper

An engineer’s guide to autonomous and collaborative industrial robots

Sponsored by Texas Instruments

As robots are becoming more commonplace in factories, it is important that they become more intelligent, autonomous, safer and efficient. All of this is enabled with precise motor control, advanced sensing technologies and processing at the edge, all with robust real-time communication. In our e-book, an engineer’s guide to industrial robots, we take an in-depth look at the key technologies used in various robotic applications.

Click here to download the e-book

Featured Chalk Talk

Innovative Hybrid Crowbar Protection for AC Power Lines

Sponsored by Mouser Electronics and Littelfuse

Providing robust AC line protection is a tough engineering challenge. Lightning and other unexpected events can wreak havoc with even the best-engineered power supplies. In this episode of Chalk Talk, Amelia Dalton chats with Pete Pytlik of Littelfuse about innovative SIDACtor semiconductor hybrid crowbar protection for AC power lines, that combine the best of TVS and MOV technologies to deliver superior low clamping voltage for power lines.

More information about Littelfuse SIDACtor + MOV AC Line Protection