i have a HM55B that gives a wrong reading when tilted forward/backward. is there a way to rectify this? or is there a better compass that can give the reading of its upright position?
All compasses are intended to remain level in all directions. This is why they're often gimbal mounted when used on a mobile platform, like a boat, automobile or airplane.
The problem might possibly be rectified by combining the compass chip with an accelerometer chip (e.g. the MX2125 2-axis device that Parallax sells). The compass would then have to be calibrated over two axes of motion, instead of just one. This is something I'm working on this week, in fact. I've got an HM55B mounted on a "crawling bug" bot which is almost never level. Stay tuned...
Here's some data I took with the HM55B pointed close to North. Mounted next to the compass was an MX2125 tilt-sensor. I took a number of readings as I slowly tilted the platform first up, and then down. The attached graph plots the compass reading in the forward direction against the pitch-axis tilt reading from the MX2125. As you can see, it's nearly a straight line. What this means is that applying a correction factor to the direction, based on tilt, may be fairly simple. More to come...
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 11/10/2006 7:17:36 AM GMT
Here's some more info regarding the fusing of compass and tilt data to yield a corrected compass reading. Below is a graph that shows compass readings from the forward axis, plotted against tilt readings along that same (pitch) axis, over the entire range of pitch: horizontal to vertical in both directions. During this time, the HM55B chip was pointed either north or south.
····
As you can see, these points describe a highly eccentric, inclined ellipse. And, as we shall see further, it's both the high degree of eccentricity and the angle of inclination that will help us.
The next graph shows compass readings from the HM55B plotted against pitch (-45° to 45° this time) for each of the color-coded cardinal directions: North EastSouthWest.
····
Although the points of each appear to lie along a straight line, they are really the mid portions of the ellipse shown above. As the sensor axis moves more nearly perpendicular to the horizontal projection of the magnetic field lines (i.e. East or West, in this case), the ellipse becomes more eccentric, degenerating into a straight line at maximum (as Don King might say) "perpendicularity". But what makes this interesting for us is that we have four nearly straight lines, merely shifted up and down, depending on the direction the compass is pointed. What's more, the slopes of these lines are virtually the same. Now this is serendipitous to the max! What it means is that to compute what the compass reading would be if the compass were level, all we have to do is add a constant, multiplied by the tilt sensor reading, to the compass's actual reading, and — badda bing! badda boom! — we've got it. The constant factor is the negative of the lines' slopes which, in this case, is +0.095. So the formula is:
····Level direction component = Tilted direction component + 0.095 * Tilt sensor reading
Try it. Pick a point in the graph and read both its Tilt (x-axis) and Direction component (y-axis). Then apply the formula. What should result is a y-value very near where the straight line intersects the y-axis. And this is what the compass reads, pointed the same direction, when it's level.
Below is the same set of graphs for the transverse compass axis versus tilt on the roll axis. Except for a different sign, the results are very similar.
····
What this means is that a compass can have the tilt calibrated out of it by taking forward readings at maximum and minimum pitch and transverse readings at maximum and minimum roll. These readings can then be used to compute the slopes of the tilt "lines", the negative of which are then used to correct for the tilt when an actual reading is taken.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 11/10/2006 6:55:23 AM GMT
Thanks! I wrote the program in Perl and made use of a graphing module (Chart::Plot) and a stats module (Statistics::LineFit) downloaded from CPAN.org. CPAN is a repository for Perl modules, much like the Propeller Object Exchange in philosophy. My own code was only 56 lines long.
The data was just copied from the DEBUG window and pasted after the end of the program.
And, yes, there is some non-linear regression stuff on CPAN. But you have to program in Perl to use it.
Comments
All compasses are intended to remain level in all directions. This is why they're often gimbal mounted when used on a mobile platform, like a boat, automobile or airplane.
Regards,
Bruce Bates
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<!--StartFragment -->
The problem might possibly be rectified by combining the compass chip with an accelerometer chip (e.g. the MX2125 2-axis device that Parallax sells). The compass would then have to be calibrated over two axes of motion, instead of just one. This is something I'm working on this week, in fact. I've got an HM55B mounted on a "crawling bug" bot which is almost never level. Stay tuned...
-Phil
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 11/10/2006 7:17:36 AM GMT
····
As you can see, these points describe a highly eccentric, inclined ellipse. And, as we shall see further, it's both the high degree of eccentricity and the angle of inclination that will help us.
The next graph shows compass readings from the HM55B plotted against pitch (-45° to 45° this time) for each of the color-coded cardinal directions: North East South West.
····
Although the points of each appear to lie along a straight line, they are really the mid portions of the ellipse shown above. As the sensor axis moves more nearly perpendicular to the horizontal projection of the magnetic field lines (i.e. East or West, in this case), the ellipse becomes more eccentric, degenerating into a straight line at maximum (as Don King might say) "perpendicularity". But what makes this interesting for us is that we have four nearly straight lines, merely shifted up and down, depending on the direction the compass is pointed. What's more, the slopes of these lines are virtually the same. Now this is serendipitous to the max! What it means is that to compute what the compass reading would be if the compass were level, all we have to do is add a constant, multiplied by the tilt sensor reading, to the compass's actual reading, and — badda bing! badda boom! — we've got it. The constant factor is the negative of the lines' slopes which, in this case, is +0.095. So the formula is:
····Level direction component = Tilted direction component + 0.095 * Tilt sensor reading
Try it. Pick a point in the graph and read both its Tilt (x-axis) and Direction component (y-axis). Then apply the formula. What should result is a y-value very near where the straight line intersects the y-axis. And this is what the compass reads, pointed the same direction, when it's level.
Below is the same set of graphs for the transverse compass axis versus tilt on the roll axis. Except for a different sign, the results are very similar.
····
What this means is that a compass can have the tilt calibrated out of it by taking forward readings at maximum and minimum pitch and transverse readings at maximum and minimum roll. These readings can then be used to compute the slopes of the tilt "lines", the negative of which are then used to correct for the tilt when an actual reading is taken.
-Phil
Post Edited (Phil Pilgrim (PhiPi)) : 11/10/2006 6:55:23 AM GMT
Another fantastic job! This only serves to prove _again_ that you are one of the most valuable and prolific contributors to the Parallax Forums.
You certainly have my thanks for all your hard work.
Regards,
Bruce Bates
Chris
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Thanks! I wrote the program in Perl and made use of a graphing module (Chart::Plot) and a stats module (Statistics::LineFit) downloaded from CPAN.org. CPAN is a repository for Perl modules, much like the Propeller Object Exchange in philosophy. My own code was only 56 lines long.
The data was just copied from the DEBUG window and pasted after the end of the program.
And, yes, there is some non-linear regression stuff on CPAN. But you have to program in Perl to use it.
-Phil