The HiTechnic compass sensor will only operate correctly in a horizontal plane so you must keep the compass level for it to read correctly. This is very important so remember this when you build it into your robot.
I've attached a compass calibration program that I got from HiTechnic (written in NXC):
Compasses are very sensitive to tilt. How sensitive depends on the location on earth and the position in relation to magnetic north. The reason for this is that the magnetic north is a spot in a 3D space (below the surface of the earth). An electronic compass uses two, or three, perpendicular sensors that measure magnetic force. (That is why they are called magnetometers). North is determined by taking the arctangens of these forces. When you rotate the compass the force on each of the sensors change and so does the arctangens. Tilting the compass is the same as rotating the compass, only the axis of rotation is different, the effect on the sensor is the same.
So, if you have a robot that is free to tilt, or when the environment can cause a tilt, you have a problem using a simple electronic compass. The only way to overcome this is to use a compass that measures magnetic force over three axes and an accelerometer that can give tilt info over three axis. You then need to use tilt info to convert magnetic force readings to the earth frame of reference. Only then you can use arctangens to calculate heading. Some of the more expensive electronic compasses have a built in accelerometer for this reason.
For those of you wanting accurate compass readings regardless of tilt, SparkFun Electronics just released a three axis magnetometer broken out for $15 US. Sure, it requires a bit of hacking as it's not directly plug and play with the NXT, but it is cheap as far as magnetometers go!
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
I am quite sure it is a raw device, so you would need to do all the calculations on the NXT (no automatic "heading" output).
I think you want something more like this one. It should be fairly easy to get it working with the NXT. The only HW you probably need is a cut NXT wire and a couple resistors.
Here is another related item. It is a triple axis magnetic sensor combined with a triple axis accelerometer. You would still need to do all the calculations on the NXT, but it would take care of the need for an accel sensor.
doc-helmut wrote:build me a NXT-plugable one, please, and sell it to me, if you please! ^^
I've actually contemplated that very thing many, many times. Creating NXTified breakout boards for sensors exactly like this one*. However, I don't have the time and I don't live in a country that ships cheaply or nicely. In fact, one book seller once said that the country I live in is the absolute worst when it comes to shipping. I'll keep it in mind though and if I ever can, I will.
mattallen37 wrote:I am quite sure it is a raw device, so you would need to do all the calculations on the NXT (no automatic "heading" output).
I think you want something more like this one. It should be fairly easy to get it working with the NXT. The only HW you probably need is a cut NXT wire and a couple resistors.
That's the point of having an ARM processor under the hood, isn't it? 48MHz should be more than enough to do the calculations on board, even if the code is running in a VM! And the compass you linked to is ten times the cost...
*In fact, that'd be my dream job. Not a great paying one, but money's not everything anyways...
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.
mattallen37 wrote:I am quite sure it is a raw device, so you would need to do all the calculations on the NXT (no automatic "heading" output).
I think you want something more like this one. It should be fairly easy to get it working with the NXT. The only HW you probably need is a cut NXT wire and a couple resistors.
That's the point of having an ARM processor under the hood, isn't it? 48MHz should be more than enough to do the calculations on board, even if the code is running in a VM! And the compass you linked to is ten times the cost...
Oh, indeed I know that, and I have no doubt it could do an excellent job at that. What I would be much more concerned about though, is writing the right code, and making it work like it should.
Yes I did see the price, but I meant that more as a reference.
Yes, I do understand how the price could be worth it to some people. Maybe even doc, who appears to be anemic to writing I2C functions (no offense intended!), would prefer a "fully cooked" compass module. Now, if someone would just buy me a house in Canada, a hotplate (for reflowing boards) and Eagle license, doc would have his board in three weeks!
One King to rule them all, One King to find them,
One King to bring them all and in the darkness bind them
On Earth where Shadows lie.