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
Apr 25, 2024
Cadence's seven -year partnership with'¯ Team4Tech '¯has given our employees unique opportunities to harness the power of technology and engage in a three -month philanthropic project to improve the livelihood of communities in need. In Fall 2023, this partnership allowed C...
Apr 24, 2024
Learn about maskless electron beam lithography and see how Multibeam's industry-first e-beam semiconductor lithography system leverages Synopsys software.The post Synopsys and Multibeam Accelerate Innovation with First Production-Ready E-Beam Lithography System appeared fir...
Apr 18, 2024
Are you ready for a revolution in robotic technology (as opposed to a robotic revolution, of course)?...

featured video

MaxLinear Integrates Analog & Digital Design in One Chip with Cadence 3D Solvers

Sponsored by Cadence Design Systems

MaxLinear has the unique capability of integrating analog and digital design on the same chip. Because of this, the team developed some interesting technology in the communication space. In the optical infrastructure domain, they created the first fully integrated 5nm CMOS PAM4 DSP. All their products solve critical communication and high-frequency analysis challenges.

Learn more about how MaxLinear is using Cadence’s Clarity 3D Solver and EMX Planar 3D Solver in their design process.

featured paper

Designing Robust 5G Power Amplifiers for the Real World

Sponsored by Keysight

Simulating 5G power amplifier (PA) designs at the component and system levels with authentic modulation and high-fidelity behavioral models increases predictability, lowers risk, and shrinks schedules. Simulation software enables multi-technology layout and multi-domain analysis, evaluating the impacts of 5G PA design choices while delivering accurate results in a single virtual workspace. This application note delves into how authentic modulation enhances predictability and performance in 5G millimeter-wave systems.

Download now to revolutionize your design process.

featured chalk talk

Reliable Connections for Rugged Handling
Sponsored by Mouser Electronics and Amphenol
Materials handling is a growing market for electronic designs. In this episode of Chalk Talk, Amelia Dalton and Jordan Grupe from Amphenol Industrial explore the variety of connectivity solutions that Amphenol Industrial offers for materials handling designs. They also examine the DIN charging solutions that Amphenol Industrial offers and the specific applications where these connectors can be a great fit.
Dec 5, 2023
18,705 views