Encoder Front Page
SRS Home | Front Page | Monthly Issue | Index
Google
Search WWW Search seattlerobotics.org

Electronic Compasses – Vector and Dinsmore

 

 

Don Carveth   Oct, 2002     don@botgoodies.com       www.botgoodies.com

 

Electronic compasses are an essential component of the solution to one of the longstanding robotics problems “Where Am I Going?”.  My robot, Fred, now has an operational, useful measurement of rotational angle – he knows where he’s headed.  In conjunction with dead reckoning distance measurement and, now, bar code location confirmation, he knows where he is and where he is going.  Major steps forward.  This article describes and compares the Vector 2X and Dinsmore electronic compass modules.

 

This adventure did not begin as a comparison between two types of compass modules.  I purchased a Dinsmore module about a year ago.  I was able to get it interfaced and operational fairly easily but was stymied by what seemed to be a large dead spot in its range.   In the meantime I acquired a Vector 2X and decided, that, due to the difficulties I was having with the Dinsmore, I would give it a shot.  Interfacing the Vector was a little more challenging but I managed to get it working, only to find it behaved exactly the same way.  A little experimentation and I realized that by mounting the sensor on my main circuit I was affecting the magnetic fields and altering the readings.  By mounting the sensor about 6” away on a short pedestal the effects were eliminated.

 

I decided, since both units seemed to be working, that I would install both and see which worked out the best.  My final decision?  They both work but my preference is the Dinsmore.

 

The Vector (left, green board) and Dinsmore (white cylinder) modules mounted

on a pedestal and connected to the robot main board.

 

General Issues

 

The compasses use different methods to measure the earths magnetic field at two right angles parallel to the earths surface.  This would be great if :

 

  1. Your sensor was always level so that no vertical component entered the picture
  2. There were no local items that affect the magnetic flux.

 

The compasses are quite sensitive to level.  This problem is aggravated if you happen to live in a far North (or South) location, like I do in Alaska.  You may find, that if you live somewhere in the normal civilized world, you will not have the non-linearity issues that I had to deal with.  Vector makes a 2XG model that has up to 15% tilt compensation.  For accurate measurement in a robot environment this would be good, but it doubles the cost.

 

I found that the compasses were insensitive to large ferrous items or to small magnets if they were more than a foot away.  I concluded that that would be acceptable for my purposes.  I mounted the sensors on a 6” high pedestal in the center of my robot which isolated it from the robot itself and created a 7” radius all round for isolation.  Be sure to keep any ferrous metals and magnets away from the modules.

 

Each compass has regions of rotational angles that it had difficulty with.  The curve became much steeper in these areas and repeatability was poorer.

 

Both compasses exhibited more hysteresis than I would have expected.  Hysteresis means that the readings taken while rotating in a CW direction are different from those taken in a CCW direction.   This was most noticeable in the difficult regions and was recorded at up to 25 degrees differential.

 

Neither compass had a linear curve that could be used without linearization.  I used lookup tables for both the Dinsmore and the Vector.  As a consequence do not expect a plug-and-play solution.  You will have to spend some time calibrating your compass by creating a specific lookup table for your situation.

 

I would rate the accuracy of the Dinsmore at plus/minus 10 degrees (3%) and the Vector at plus/minus 17 degrees (5%).  These results were not based on exhaustive testing and it was difficult to determine how level the sensors were.  And this was done in Alaska.  I would expect better results in farther south locations.

 

The Vector was tested on my breadboard using an ATMEGA163 before being moved to the robot where it was connected to an ATMEGA128.  The Dinsmore was tested on the robot only and therefore a test program is not provided, just the functions.

 

Testing and Calibration

 

Direction is a relative concept.  I selected a “House North” direction (actually about NE) and set that as 0 degrees.  I used a calibration table (actually a rotating plastic computer monitor stand) that I set my robot on and could rotate while watching the readout on my monitor.  I marked the edge of the stand at 1” increments that I converted to rotational angles.  I set up an Excel spreadsheet that I used to collect and graph the calibration runs and final results.

 

The “Results” worksheet shows some test runs and analyzes the errors.  Here is the summary report:

 

                                                           Dinsmore   Vector        Dinsmore    Vector

                                                                CW           CW            CCW           CCW

Average error (degrees)

4.0

6.0

4.9

6.5

Max error

 

8.0

17.0

10.0

17.0

Average Hysterisis Error

8.4

7.4

 

 

Max Hysterisis Error

15.0

27.0

 

 

 

 

 

 

 

 

Average error (%)

1.1%

1.7%

1.4%

1.8%

Max error

 

2.2%

4.7%

2.8%

4.7%

Average Hysterisis

2.3%

2.1%

 

 

Max Hysterisis Error

4.2%

7.5%

 

 

 

 

My calibration table.

 

 

The Dinsmore Compass

 

Dinsmore Instrument Co.    http://www.dinsmoresensors.com/

 

c code  functions for Dinsmore

 

The Dinsmore compass uses a hall effect sensor to detect rotation of what is in effect a compass needle.  The modules are very small (1/2” diameter x ¾” high), easily interfaced to a microcontroller using two analog inputs and relatively inexpensive (mine cost $35 in early 2001).  Dinsmore is more than happy to sell you a single module directly. 

 

The model I used was the Model 1655 which gives a swing of about 1.3 volts using a 5 volt supply.  The 5 volt supply must be reference voltage quality as the output is a ratio of this voltage.

 

The output from the sensor consists of two sin waves offset by 90 degrees.  The top and bottom sections of the waves are fairly flat and the readings are not accurate, therefore you use the linear ramping sections to make you calculations.  This can be done using cos and sin functions (I have provided that code uses this method) or by assuming the ramping section is linear.  In either case the math is not too difficult.  The AVR has 10 bit A/D inputs so the incoming signals are scaled from 0 to 1023.

 

In the real world, at least here in Alaska, the result using sin/cos methods was not close to linear because the curves are not at all ideal sin waves.  If you look at worksheet “DinChart” in the spreadsheet you can see the mapping of the raw values.  I initially used the sin/cos method, and the code is included, but I abandoned that in favor of lookup table linearization using the raw values.  I divided the scale up into 4 segments and used a separate table for each.  The reported results are based on this method.

 

Two problems affect the accuracy of the Dinsmore.  Stability – the reading would bounce around plus/minus 3 degrees max.  This could perhaps be improved by paying more attention to the analog input circuitry.  The other issue is hyteresis.  The readings, in some sections of the curve, will differ by as much as 20 degrees depending on whether you are moving CW or CCW.  I ended up using lookup table values that were an average of the CW and CCW runs.

 

Other than the problems noted, the compass is very repeatable.  The output is supposedly damped but it reacted about as quickly as the Vector.  About 80% of a step change was evident in ½ second, 100% after 1 second.  This is plenty good enough for my application.

 

I did not supply a test program for the Dinsmore as it was integrated into my robot.  I did, however supply all of the c routines I used.  The routines describe both the sin/cos method and the four lookup table method.

 

Overall conclusion:  the Dinsmore compass will work for this application.  I would use lookup tables to linearize the raw signal, however.  The Dinsmore advantages are simple interface, small size and low cost with reasonable accuracy.

 

 

The Vector Compass Module

 

Precision Navigation      www.precisionnav.com

 

Sample program in GCC c version 3.2 for Vector

 

The Vector compass uses a small (about 1 ½” by 1 ½”) circuit board on which two right angle coils are mounted with some support circuitry.  Cost is about $50 for the 2X model that I used and they are available from Jameco and Digikey.  The interface uses SPI communications and is considerably more complex that the Dinsmore. 

 

As with the Dinsmore, I found that in my world, the signal was not close to linear.  I used table lookup to linearize the signal.  After that the compass worked fairly well.

 

Since my robot was using the SPI port, in slave mode, for other purposes, I decided to bit bang an SPI port to talk to the Vector.  This is not really that difficult, and, in fact, I’ve found that the flexibility this gives sometimes makes interfacing easier.  I was talking to the Vector pretty much from the first couple of tests.  I had much more difficulty with the reset routines.  If the Vector does not power up correctly, that is certain pins are at certain levels at power up, it will hang.  I played around with reset routines for quite a while and finally got it working almost every time, but I was never satisfied that it did what was expected.  I also was never able to get the internal calibration routine working right, but it’s not needed since I do my own mapping in the microcontroller.

 

There are a total of  7 microcontroller I/O points that need to be connected.  CAL is not required if you don’t plan to use the internal calibration feature and EOC is not required if you use time delays instead of external interrupts (see below).  EOC must be connected to an external interrupt pin.

 

 

Communicating with the Vector consists of a number of steps.  The Vector documentation has a timing chart that shows the sequence.  First send a 10+ ms initiation pulse to P/C.  Wait for 100+ ms for the EOC signal.  Wait 10+ ms.  Drop the SS line to initiate the SPI transfer.  Read the SPI data.  The delays required can be implemented with sleep delays or by using interrupts and I have included code for doing it both ways.  In my busy robot environment I cannot tolerate waiting around for 10 ms therefore all of my delays are generated using interrupts.  I use the free running RTC timer and flags for the 10 ms delays and have EOC connected as an external interrupt for the EOC to signal End Of Calculation.

 

Repeatability is very good outside the troublesome segments, stability is better than the Dinsmore but it does have the same hysteresis problem that the Dinsmore has and the accuracy decreases substantially over certain segments.

 

Overall conclusion:  I would rate accuracy as not quite as good the Dinsmore.  It does require a linearization look-up table (at least in Alaska), although only one.  Interface is more complex and requires more microcontroller resources.  Cost is a little higher.  A tilt compensated model is available.

 

Conclusion

 

My recommendation is the Dinsmore.  Performance is somewhat better than the Vector, it costs less, is smaller, uses fewer microcontroller resources and is much easier to interface.  Now that I have both operational I intend to use the Dinsmore.  I’ll save my Vector for my next bot.

 

If you have any questions or comments contact Don Carveth at don@botgoodies.com.  The latest version will be posted at www.botgoodies.com.