LSB meanings and provenance

Supporting Browser-based Javascript and Node.js
Post Reply
gallantoss
Fresh meat
Posts: 2
Joined: Mon Oct 29, 2018 7:29 am
Contact:

LSB meanings and provenance

Post by gallantoss »

I'd like to calculate the compass bearings but I have an interogation on what is LSB data and how to find it with my phidget spatial 3/3/3 basic


This is an exemple I found on how to use a magnetometer to calculate the compass headings. If you could help me on the LSB thing it would really help.

//------------------------------------------------------

Calculate the real Gauss value for the X and Y axes from the amount of LSBs returned where the LSB value by default is 0.48828125 mG, resulting in 2048 LSBs per Gauss.
xGaussData = xDataLSB∗0.48828125 mG

yGaussData = yDataLSB∗0.48828125 mG
Calculate the direction D by first checking to see if the X Gauss data is equal to 0 to prevent divide by 0 zero errors in the future calculations. If the X Gauss data is 0, check to see if the Y Gauss data is less than 0. If Y is less than 0 Gauss, the direction D is 90 degrees; if Y is greater than or equal to 0 Gauss, the direction D is 0 degrees.
If the X Gauss data is not zero, calculate the arctangent of the Y Gauss and X Gauss data and convert from polar coordinates to degrees.
D = arctan(yGaussData/xGaussData)∗(180/π)
If the direction D is greater than 360 degrees, subtract 360 degrees from that value.
If the direction D is less than 0 degrees, add 360 degrees to that value.
The compass heading can then be determined by the direction value D:
If D is greater than 337.25 degrees or less than 22.5 degrees – North
If D is between 292.5 degrees and 337.25 degrees – North-West
If D is between 247.5 degrees and 292.5 degrees – West
If D is between 202.5 degrees and 247.5 degrees – South-West
If D is between 157.5 degrees and 202.5 degrees – South
If D is between 112.5 degrees and 157.5 degrees – South-East
If D is between 67.5 degrees and 112.5 degrees – East
If D is between 0 degrees and 67.5 degrees – North-East
User avatar
mparadis
Site Admin
Posts: 660
Joined: Fri Oct 28, 2011 12:17 pm
Contact:

Re: LSB meanings and provenance

Post by mparadis »

Based on the comments in that code, it looks like this is assuming the use of a different magnetometer chip. "LSB" typically means "Least significant bit" and it looks like if you're using the magnetometer that this code sample is made for, a conversion is required in order to turn the value given from the magnetometer into gauss.

For Phidgets, we already give you the magnetometer values in mG, so you can skip those versions and treat the values you get a "xGaussData" and "yGaussData" directly.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests