NXC: how to calibrate the HT Compass sensor?

Discussion specific to the intelligent brick, sensors, motors, and more.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: how to calibrate the HT Compass sensor?

Post by afanofosc »

From the HiTechnic page for this device:
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):
CalCompass.zip
(1.25 KiB) Downloaded 307 times
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: how to calibrate the HT Compass sensor?

Post by HaWe »

thank you John, it's the same program published above, and it's working fine!

jasonlh, nice video, rather impressive! :)
aswin0
Posts: 201
Joined: 29 Sep 2010, 06:58

Re: NXC: how to calibrate the HT Compass sensor?

Post by aswin0 »

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.
My blog: nxttime.wordpress.com
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXC: how to calibrate the HT Compass sensor?

Post by nxtreme »

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.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: how to calibrate the HT Compass sensor?

Post by HaWe »

build me a NXT-plugable one, please, and sell it to me, if you please! ^^
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: how to calibrate the HT Compass sensor?

Post by mattallen37 »

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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: how to calibrate the HT Compass sensor?

Post by mattallen37 »

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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXC: how to calibrate the HT Compass sensor?

Post by nxtreme »

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
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC: how to calibrate the HT Compass sensor?

Post by mattallen37 »

nxtreme wrote:
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.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
nxtreme
Posts: 246
Joined: 29 Sep 2010, 03:53
Location: 192.168.1.2

Re: NXC: how to calibrate the HT Compass sensor?

Post by nxtreme »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest