Category Archives: General

Building a virtual gyro

Originally posted by Michael E Stanley of Freescale Semiconductor in The Embedded Beat on Mar 12, 2013

In Orientation Representations Part 1 and Part 2, we explore some of the mathematical ways to represent the orientation of an object. Now we’re going to apply that knowledge to build a virtual gyroscope using data from a 3-axis accelerometer and 3-axis magnetometer. Reasons you might want to do this include “cost” and “cost”. Cost #1 is financial. Gyros tend to be more expensive than the other two sensors. Eliminating them from the BOM is attractive for that reason.  Cost #2 is power. The power consumed by a typical accel/mag pair is significantly less than that consumed by a MEMS gyro. The downside of a virtual gyro is that it is sensitive to linear acceleration and uncorrected magnetic interference. If either of those is present, you probably still want a physical gyro.

So how do we go from orientation to angular rates? It’s conceptually easy if you step back and consider the problem from a high level. Angular rate can be defined as change in orientation per unit time. We already know lots of ways to model orientation. Figure out how to take the derivative of the orientation and we’re there!

In our prior postings, we’ve discussed a number of ways to represent orientation. For this discussion, we will use the basic rotation matrix. Jack B. Kuipers has a nice derivation of the derivative of direction cosine matrices in his “Quaternions and Rotation Sequences” text – one of my most used textbooks.  It makes a good starting point.  Paraphrasing his math:

Let:

  1. vf = some vector v measured in a fixed reference frame
  2. vb = same vector measured in a moving body frame
  3. RMt = rotation matrix which takes vf into vb
  4. ω = angular rate through the rotation

Then at any time t:

  1. vb= RMt vf

Differentiate both sides (use the chain rule on the RHS):

  1. dvb/dt  = (dRMt/dt) vf + RMt(dvf /dt)

Our restrictions on no linear acceleration or magnetic interference imply that:

  1. dvf/dt = 0

Then:

  1. dvb/dt  = (dRMt/dt) vf

We know that:

  1. vf = RMt-1 vb

Plugging this into (8) yields

  1. dvb/dt  = (dRMt/dt) RMt-1 vb

In a previous posting (Accelerometer placement – where and why) , we learned about the transport theorem, which describes the rate of change of a vector in a moving frame:

dvf/dt = dvb/dt – ω X vb

Those who take the time to check will note that we have inverted the polarity of the ω in Equation 11 from that shown in the prior posting.  In that case ω was the angular velocity of the body frame in the fixed reference frame.  Here we want it from the opposite perspective (which would match gyro outputs).

And again,

  1. dvf/dt = 0 so
  2. dvb/dt = ω X vb

Equating equations 10 and 13:

  1. ω X vb = (dRMt/dt) RMt-1vb
  2. ω X = (dRMt/dt) RMt-1

where:

  1. 0 z ωy
    ω X = ωz 0 x
    y ωx 0

Going back to the fundamentals in our first calculus course and using a one-sided approximation to the derivative:

  1. dRMt/dt = (1/Δt)(RMt+1 – RMt)

where Δt = the time between orientation samples

  1. ωb X = (1/Δt)(RMt+1 – RMt) RMt-1

Recall that for rotation matrices, the transpose is the same as the inverse:

  1. RMtT = RMt-1
  2. ωb X = (1/Δt)(RMt+1 – RMt) RMtT

Equation 15 is a truly elegant equation.  It shows that you can calculate angular rates based upon knowledge of only the last two orientations.  That makes perfect intuitive sense, and I’m ashamed when I think how long it took me to arrive at it the first time.

An alternate form that is even more attractive can be had by carrying out the multiplications on the RHS:

  1. ωb X = (1/Δt)(RMt+1 RMtT – RMt RMtT)
  2. ωb X = (1/Δt)(RMt+1 RMtT – I3×3)

For the sake of being explicit, let’s expand the terms.  A rotation matrix has dimensions 3×3.  So both left and right hand sides of Eqn. 22 have dimensions 3×3.

  1. (1/Δt)(RMt+1 RMtT – I3×3)  = (1/Δt) W
  1. 0 W1,2 W1,3
    W = RMt+1 RMtT – I3X3 = W2,1 0 W2,3
    W3,1 W3,2 0

The zero value diagonal elements in W result from small angle approximations since the diagonal terms on RMt+1 RMtT will be close to one, which will be canceled by the subtraction of the identity matrix.  Then:

  1. 0 z y 0 W1,2 W1,3
    ω X = z 0 x =  (1/Δt) W2,1 0 W2,3
    y x 0 W3,1 W3,2 0

and we have:

  1. ωx= (1/2Δt) (W3,2 – W2,3)
  2. ωy= (1/2Δt) (W1,3 - W3,1)
  3. ωz= (1/2Δt) (W2,1 - W1,2)

Once we have orientations, we’re in a position to compute corresponding angular rates with

  • One 3×3 matrix multiply operation
  • 3 scalar subtractions
  • 3 scalar multiplications

at time each point.  Sweet!

Some time ago, I ran a Matlab simulation to look at outputs of a gyro versus outputs from a “virtual gyro” based upon accelerometer/magnetometer readings.  After adjusting for gyro offset and scale factors, I got pretty good correlation, as can be seen in the figure below.

image001.gif

You will notice that we started with an assumption that we already know how to calculate orientation given accelerometer/magnetometer readings.  There are many ways to do this.  I can think of three off the top of my head:

  • Compute roll, pitch and yaw as described in Freescale AN4248.  Use those values to compute rotation matrices as described in Orientation Representations: Part 1.  This approach uses Euler angles, which I like to stay away from, but you could give it a go.
  • Use the Android getRotationMatrix [4] to compute rotation matrices directly.  This method uses a sequence of cross-products to arrive at the current orientation.
  • Use a solution to Wahba’s problem to compute the optimal rotation for each time point.  This is my personal favorite, but I think I’ll save further explanation for a future posting.

Whichever technique you use to compute orientations, you need to pay attention to a few details:

  • Remember that non-zero linear acceleration and/or uncorrected magnetic interference violate the physical assumptions behind the theory.
  • The expressions shown generally rely on a small angle assumption.  That is, the change in orientation from one time step to the next is relatively small.  You can encourage this by using a short sampling interval.  You should soon see an app note that my colleague Mark Pedley is working on that discards that assumption and deals with large angles directly.   I like the form I’ve shown here because it is more intuitive.
  • Noise in the accelerometer and magnetometer outputs will result in very visible noise in the virtual gyro output.  You will want to low pass filter your outputs prior to using them.  Mark will be providing an example implementation in his app note.

This is one of my favorite fusion problems.  There’s a certain beauty in the way that nature provides different perspectives of angular motion.  I hope you enjoy it also.

References

  1. Freescale Application Note Number AN4248: Implementing a Tilt-Compensated eCompass using Accelerometer and Magnetometer Sensors
  2. Orientation Representations: Part 1 blog posting on the Embedded Beat
  3. Orientation Representations: Part 2 blog posting on the Embedded Beat
  4. getRotationMatrix() function defined at http://developer.android.com/reference/android/hardware/SensorManager.htmlWikipedia entry for “Wahba’s problem”
  5. U.S. Patent Application 13/748381, SYSTEMS AND METHOD FOR GYROSCOPE CALIBRATION, Michael Stanley, Freescale Semiconductor

MIG visits Tohoku University, Sendai, Japan

Contributed by Karen Lightman, Managing Director, MEMS Industry Group

My journey through Japan continued with a trip up to Sendai (which is 96 minutes north of Tokyo by Shinkansen), at the invitation of Professor Esashi-sensai at Tohoku University. Takeo Oita-san of NDK accompanied me at my visit to Sendai.  We were greeted at the station by Katou Hiroyuki –san and Ms. Emi Ooba, both with the Commercialization Support Sub-section, Industrial-Academic Collaboration Promotion Section, Economic Affairs Bureau, Sendai City.  Their focus is to promote Sendai as the “best location” for R&D. Along with their director, Hiroyuki Miyata, I was very humbled and impressed with their hospitality and graciousness. Continue reading

The Zen of Sensor Design

Contributed by Mike Stanley

Originally posted on Freescale’s Smart Mobile Devices Embedded Beat Blog

About two years ago, I joined the Freescale sensors team, which focuses on accelerometers, pressure sensors, and touch sensors.

Prior to that, I spent a number of years in the Freescale’s microcontroller solutions group, where I was an architect for several digital signal controller and microcontroller product families. One of the first things I learned when I moved into the sensors group was that certain “rules of the game” that relate to microcontroller design needed to be adapted when dealing with sensors. An example is package selection. With most microcontrollers, package selection is based upon number of functional and power pins required, PCB assembly processes targeted and (sometimes) thermal characteristics. Performance considerations are often secondary, if they exist at all. Sensors interact with the real world. Mechanical stresses introduced during both package assembly and PCB mounting can affect electrical performance of the device; often showing up as additional offset or variation of performance with temperature. Even the compound used for die attach has a demonstrable effect on sensor performance, and must be considered early in the design process. Continue reading

Evolving Intelligence with Sensors

Contributed by Michael Stanley, Freescale Semiconductor

Originally posted on Freescale’s Smart Mobile Devices Embedded Beat blog

I’ve always been fascinated by electronic sensors. The idea of being able to measure and interact with the physical world appeals to the ten-year-old inside me. Not so long ago, if you needed to measure some physical quantity as an input to your system, you bought an analog sensor, hooked up your own signal conditioning circuitry, and fed the result into a dedicated analog-to-digital converter. Over time, engineers demanded, and got, self-contained products which handled those signal conditioning and conversion tasks for them. Continue reading

What in the World is Contextual Sensing?

Contributed by Michael Stanley, Freescale Semiconductor

Originally posted on Freescale’s Smart Mobile Devices Embedded Beat blog

You can’t use your phone, drive your car or even nuke a sandwich without relying on one or more electronic sensors to help you complete the task.  Their use has become ubiquitous, and most people are blissfully unaware of just how much they depend on them in their daily lives. Continue reading

METRIC attendees think the future looks bright!

Contributed by Monica Takacs, Director of Marketing & Membership, MEMS Industry Group

Wow, what a week! I just got back from a whirlwind trip to San Jose for MEMS Industry Group’s annual members meeting, METRIC. It was great to see so many new faces and old friends at this year’s event.  It was really fun to mingle with the Bay Area MEMS Happy Hour group, as well as some of the attendees from MEPTEC’s MEMS Symposium. Continue reading

No More “Fear Factor” — Understanding MEMS Fabrication

Contributed by Monica L. Takacs, Director of Marketing and Membership, MEMS Industry Group

In the past, the ‘fear factor’ of MEMS’ complex fabrication processes restricted the widespread adoption of MEMS in many markets. Today, however, MEMS’ fabrication is keeping pace with market demand for mass-produced MEMS devices which are being fabricated in the millions. Early commercial successes in inkjet print heads and automotive air bags have given rise to widespread adoption in mobile handsets, video game hardware, laptop computers and reams of new automotive applications. Continue reading

My Visit to Bosch’s 8” MEMS Foundry, Reutlingen, Germany

Contributed by Karen Lightman, Managing Director, MEMS Industry Group

On Tuesday, April 20 I was able to jump on one of the only flights out of Hannover to Stuttgart. On a lovely flight via Air Berlin (totally recommend them as an airline, by the way, they gave me a heart-shaped Milka chocolate at the end of the flight), I was able to watch a gorgeous purple-infused sunset thanks to the Icelandic volcano ash.

My Bosch visit began when Dr. Frank Melzer, CEO of Bosch Sensortec graciously met me at the airport and we enjoyed a stunning dinner at a 4-star restaurant on the top of Stuttgart’s new art museum. How cool to be dining atop a modern cube-shaped modern art museum, looking out on Stuttgart’s main square with two Württemberg castles in the distance.

The following morning I was off to Bosch’s Reutlingen facility, just south of Stuttgart. Bosch’s impressive campus is a great combination of both old and new; part of the facility includes a 100+ year-old former garment factory as well as Bosch’s gorgeously techy three week-old new 8” MEMS/ASIC foundry. Again, how cool.

I had the pleasure of reconnecting with several old Bosch colleagues such as Markus Ulm, Wilhelm Frey and Udo-Martin Gomez and several new colleagues including Rolf Speicher, Frauke Ludmann, Leopold Beer, Frank Schaefer, and Boories Rost. Since I’d had a late night I was grateful for the ample supply of coffee (rivaling Leopold’s caffeine consumption, I was told), but was soon pleased that the conversations would be stimulating enough. I am always pleasantly surprised when I have a site visit and the hosts are not just proud and excited to show me their facility but also interested in hearing about MIG and its member benefits, programs and events! I especially appreciated that the Bosch team was eager to engage in heated debate about the growth and future of the MEMS Industry.

Some key takeaways from our conversations:

  • It’s no joke that the Bosch Process is an institution in MEMS. The entire Bosch philosophy is based on quality and reliability. Bosch as well as its subsidiary, Bosch Sensortec, are first interested in providing a market-needed product and secondly interested in providing that product at a competitive price. First, they focus on providing a quality product and then on providing a quality price. Their devices may be enabled by sophisticated software and algorithms, but Bosch does not overtly use these facts as their market differentiator. Instead, Bosch is selling you the Bosch quality and reliability. ‘Nuff said.
  • Bosch reinvests a considerable and steadily increasing percentage of their annual revenue into R&D. Clearly this investment in their future has paid off (and will continue to pay off) as Bosch is increasingly pushing the size, quality and capability of its CMOS, ASIC and MEMS chips. “Impressive” seems like a weak term here!
  • Though I knew that Bosch was a leader in automotive sensors, I quickly learned that Bosch Sensortec is clearly a leader in consumer MEMS. Their sensors are increasingly found in mobile handset throughout Asia–and you don’t have to be a market analyst to realize that the mobile handset market in Asia is HUGE and ever-growing (I think it’s not “one chicken in every pot” in China, but “one mobile handset in every hand”). Therefore, Bosch Sensortec’s market share is sure to grow stronger.
  • Lastly, really genuinely nice people work in Bosch MEMS. Perhaps it’s my inclination to gravitate towards engineers and my respect for those who are always looking for a better way to do something (and the fact that I married an engineer). But honestly, I was very taken by the authenticity and honesty of the Bosch team, who show a respect for one another that is unique.

I am grateful for Bosch for the great site visit. I really have enjoyed myself in Germany–both professionally and personally. I feel very fortunate to be “stuck” in Germany though I hope to return home on Friday. As on Monday it’s time to leave for the West Coast (of the US, that is) and host the MEMS Panel of MIG members at Globalpress Electronics Summit. Stay tuned for my next blog which will highlight panelist discussions of how MEMS is fueling the economic rebound.

Sensors, sensors everywhere: MEMS and the “Internet of Things”

Robert MacManus posted an interesting piece on ReadWriteWeb recently (see 2010 Trend: Sensors & Mobile Phones) in their series on the “Internet of Things”–where devices are connected to the Internet to provide us with more data and functionality. Although he doesn’t call it MEMS by name, he makes the point that cell phones are becoming much more than communications devices; cell phones and mobile devices are essentially pocket-sized platforms for sensors. And, yes, many of these sensors are MEMS devices! Continue reading

Will 2010 be the year of the MEMS gyroscope?

Tech writer R. Colin Johnson thinks so and has laid out 5 apps that could push gyros into the limelight. Colin has been attending MEMS Executive Congress for a couple of years now, so it’s no surprise that some of the really cool MEMS apps discussed there have made it onto his list.

“Gyroscopes have already proved themselves in the inertial guidance systems for aircraft, ships, spacecraft and ballistic missiles, but their use in consumer devices in 2010 will make gyroscopes a part of the common vernacular.”

See the full list and the rest of Colin’s article here: http://www.smartertechnology.com/c/a/Technology-For-Change/Five-Apps-That-Will-Make-2010-the-Year-of-the-Gyroscope/

Colin also frequently writes about MEMS on NextGenLog, his blog about next generation electronics and technologies.

So what do you think, MEMSbloggers? What will 2010 have in store for MEMS?

Follow

Get every new post delivered to your Inbox.

Join 181 other followers