简体   繁体   中英

why use accelerometer and magnetometer to get compass values

I found several examples and I know HOW to get the compass bearing using accelerometer and magnetometer. The problem is that i don't know WHY these two sensors should be used. can someone explain it to me? thanks

The need for a magnetometer is pretty obvious. What the compass (even a real one) shows as "north" is indeed the direction of magnetic field. Thus your Android needs to measure the magnetic field somehow in order to know in what direction to draw the arrow.

As per accelerometer, you need to know that accelerometers are not only used for measuring acceleration, as their name would suggest, but they also tell you in what direction gravity is pointing. Without one your device would not know where "down" is. For example, every smartphone capable of screen auto-rotation needs an accelerometer.

Now why need both for a compass? Because in determining the position of north, you need to know not only the direction of magnetic field but also the horizontal plane. You usually don't care whether north is above or below you. The knowledge of the "down" direction allows you to filter out the unneeded third coordinate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM