HM55B Digital Compass - How do I program the controller to read it?

Here’s the story:
It’s Sunday before the ship date, and I’m out in the shop trying to get our gear tooth sensors to work, yet the robot had a tendency to veer left and attempt to crash into the virtual lane divider which composed of some tables. I’m very certain the code for the gear tooth sensors work, but one side drags a little more due to some meshing issues in the gears. I’m sure that both gear tooth sensors work, and these are not those provided in the kit.
So to sum that up, 2 days before ship, and autonomous doesn’t work at all.

In week 2, I did some research on digital compasses, and found the Parallax HM55B. So after waiting 4 more weeks, I decided to buy it and try it out. Well… it finally came in last week, and I took it home and played with it on a BOE-bot, and it worked great. Very accurate, and I was able to drive the BOE-bot down our 20’ hall way in my house without it getting off course at all. Of course, the BOE-bot uses PBASIC, and our IFI controller is C. I did some research around the internet for source code for the HM55B, and was able to come up with a few sources, but I do not understand how they work or how to implement them into our system.

Right now I have Kevin’s 3.0 code installed on our controller. The compass works through the TTTL port on our controller. I also believe I understand how to wire the compass in… I just need help on the programming side. I’m a 1st year programmer, and have never been introduced into serial communications or how Kevin’s code can be used to communicate with the compass.

Any help is greatly appreciated!
Thanks,
RyanN

I’d be very careful using any kind of compass on your robot–the magnetic fields produced by your motors and even in the straight wiring connections of your robot will produce a large magnetic field simply because of the amperage they are using. The earths magnetic field is only .05 mT which will easily be overwhelmed by the magnetic fields created by your robot.

A brief calculation
the magnetic field generated by a 80Amps flowing through a long straight wire (a situation which approximates the wiring on your robot under low load) from .5m (assuming optimal mounting of your compass) away is

B=uI/(2(pi)r)
B=1.256
10^-6
80/(2*(3.14)*.5)
B=.03mT which is more than enough to throw off your compass.

This calculation also does not take into account windings in your motors and other sources of a magnetic field which will make your compass essentially useless.

To solve your problem it might be better to try using the gyro which measures change in angle and driving straight by measuring change in angle and correcting.

RyanN,

I would use the yaw-rate sensor before the compass. I saw a robot try to use a compass at a Seattle Robotics Society competition 8 years ago. It had a hard time getting though a maze (the Trinity Firefighting Building actually). All of us robot people stood around to try to figure out what was going on.

The best we could come up with is that the compass was reacting to the rebar in the floor. We even went so far as turning the maze to be in line with the rebar that did work when the robot moved in the “x” direction but it still did weird things in the “y”.

I then played around with a copy of his just to see how they work. Compasses sound like a good idea on a robot but in my playing around with them I could not get it working as well as I wanted. If you orientate your robot with a plain old compass around the four rose points and then read the electronic one you will find a great amount of deviation from 90 degrees. Of course over 360 they re-line up, but 90 degrees is not really 90 degrees to them.

-Jim

As a counterpoint, I’ve used the Devantech CMPS03 digital compass on a non-FIRST robot to do outdoor navigation. The compass is mounted about 18 inches away from my drive motors (a pair of Taigenes), on top of a piece of PVC. I expected that I would encounter magnetic field issues, but the output values don’t seem to vary by more than a degree or two when I turn the motors on and off. To be fair, Taigenes don’t draw quite as much current as CIMs, but I would venture that using a digital compass in this application is quite feasible, so long as you make some effort to keep the sensor reasonably isolated from your motors and power leads.

I was able to get it to work on the robot using the “Board of Education (BOE)” I hooked up the PWM cables to 2 of the 3 pin headers, and it was able to work pretty good. I believe I’m going to put the compass near the back of the robot at the bottom of the battery, or way up high on our fork lift. I may consider the gyro later, but we haven’t ever used it before as well…

Also when I tested it with the BOE, I had it right over our T-Shirt shooter’s battery selector switch, which didn’t cause any issue, but did hole the BOE-bot in place very well while I went on the crazy ride…

The problem of veering right happened with our robot too, and what happened was our chains were not the same length. Causing the robot to move slightly to the right when both controllers were forward.

If you continue to have issues, consider doing this:

encoder_error = left_encoder_count - right_encoder_count;
encoder_output = encoder_error * encoder_gain;
if (encoder_output > 127)
encoder_output = 127;
else if (encoder_output < -127)
encoder_output = -127;

Left_Drive = 127 + <insert_your_left_drive_value> - encoder_output;
Right_Drive = 127 + <insert_your_right_drive_value> + encoder_output;

Adjust your gain until it drives roughly straight. It won’t be perfect, but it might work well enough for you.

We already have code that does this, and it will increase the change if it does not see a fix, but our gear tooth sensors aren’t as sensitive as I would wish, and they skip values when going fast. By the way, I’m using MPLAB.

OK, now you have me curious. What GTS’ are you using? :confused:
Not sensitive enough and skipping counts doesn’t sound like a sensor problem. It sounds more like an alignment issue.

We’re using the Honeywell 1GT101DC Hall Effect Sensors that some thread recommended. Our gear depth is about .1" and the sensor says it should have .4", but they do work… sort of. It’s only at higher speeds where the left side seems to skip, and we’ve tried to adjust it some, but with no avail. I’m really just looking for some help with the compass. I’m really tired of messing with gear tooth sensors.

OK, that’s the same sensor we used this year.
May I suggest you re-position your sensor closer to the teeth. Ours id currently approximately .5 to 1mm from the teeth and works perfectly.
Here is a picture. In fact, it is too far out in this picture. We ended up moving it in even closer.

If you look closely, you can see two washers used as spacers. We removed the thicker one and our intermittents went away.

We will try it when we get to the Bayou Regional, but 2 days before shipping, we measured it with a feeler, and it was pretty much right on what it called for, and one of our engineers doesn’t want to get it “too close.”

I absolutely understand your engineers concerned about getting it too close. We too tried to have the encoder positioned exactly according to the spec. sheet. The result was we were having intermittent tooth counts. So I pulled out my old, ancient, barely working oscilloscope. When I looked at the signal I can see that he was not a consistent waveform. I’ve been unmounted the sensor from the transmission and manually positioned it by hand while the motor was running at about 50%. I move I moved the sensor in until it made contact with the gear. At that point I immediately backed it out to prevent damage, then at least I had a reference as to how far we could put it in. I’ve been carefully moved the sensor in and out and suddenly I got a perfect square wave, with the duty cycle of 50%. I was able to determine exactly how much shim was needed to reproduce that position. I then repositioned the encoder, solidly mounting it to the transmission with the correct amount of shim in place. I was then able to run the motor at full speed forward and full speed reverse without missing a single count.

For us, trial and error turned out to be the best way to go. If you have access to an oscilloscope, use it to determine the correct position to get a consistent results.