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
Aug 7, 2020
I love the clickety-clackety sounds of split flap displays, but -- in the case of this kinetic clock -- I'€™m enthralled by its sedately silent revolutions and evolutions....
Aug 7, 2020
HPC. FinTech. Machine Learning. Network Acceleration. These and many other emerging applications are stressing data center networks. Data center architectures evolve to ensure optimal resource utilization and allocation. PECFF (PCIe® Enclosure Compatible Form Factor) was dev...
Aug 7, 2020
[From the last episode: We looked at activation and what they'€™re for.] We'€™ve talked about the structure of machine-learning (ML) models and much of the hardware and math needed to do ML work. But there are some practical considerations that mean we may not directly us...
Aug 7, 2020
This is my second update post where I cover things that I have covered before, and where there is some news, but no enough to make a completely new post. The first update was Weekend Update .... [[ Click on the title to access the full blog on the Cadence Community site. ]]...

featured video

Product Update: DesignWare MIPI C-PHY/D-PHY IP

Sponsored by Synopsys

Get the latest update on Synopsys' DesignWare MIPI C-PHY/D-PHY IP solution and how the 24 Gbps total bandwidth can enable your camera, display, automotive, drone, and image sensor SoCs implemented in advanced FinFET processes.

Click here for more information about Synopsys' DesignWare MIPI C-PHY/D-PHY IP solution

Featured Paper

Improving Performance in High-Voltage Systems With Zero-Drift Hall-Effect Current Sensing

Sponsored by Texas Instruments

Learn how major industry trends are driving demands for isolated current sensing, and how new zero-drift Hall-effect current sensors can improve isolation and measurement drift while simplifying the design process.

Click here for more information

Featured Chalk Talk

Microchip SAM11L KPH

Sponsored by Mouser Electronics and Microchip

Adding connectivity to your embedded design opens up a whole new realm of security challenges. Inviting your device to the IoT requires careful attention to building a secure foundation. In this episode of Chalk Talk, Amelia Dalton chats with Anand Rangarajan from Microchip about the SAML11-KPH MCU and how it can help you develop your application without worrying about security.

Click here for more information about Microchip Technology SAM L10/L11 ARM® Cortex®-M23 MCUs