top of page

Subsystems designed by Zach Tomberg

Compass (MPU 92/65)

I chose to use an MPU 9265 9-axis magnetometer/accelerometer/gyro module because it is a reliable and accurate module. I first tried a QMC5883 but found it was far too slow and sensitive.

The basic use of the sensor involves reading the raw magnetometer data from the X and Y axis sensors. I let out the Z axis because our use was mainly on level ground and it didn't seem necessary.

Interpretation of this data involves using trig functions to derive how a 360 degree angle corresponds to two axis magnitudes.

MPu.JPG
Compass_Ex.png
Azimuth_Code.JPG

The fundamental code for the MPU Magnetometers are shown to the left. It simply reads value from the Mag address and I've add a loop to help with stability by averaging 30 values.

The real direction however gets calculated in my Heading() function.

Due to the orientation of the module on the droid the X axis gets flipped and it also is in line with the front of the bot. In this code I've used some if statements to simply define all eight possible positions of the direction.

​

Heading_Code.JPG

Here's a short video of me testing the compass on my robot with an added OLED display.

The next important piece to make this compass functional is calibration. I first calibrated this compass in my bedroom and found the X axis was offset by 57 and the Y axis was offset by -201. I'm sure the units of these values relate to gauss or something, but it's really unimportant for our purpose because the compass hinges on the ability to compare X and Y.

​

Calibrate_Code.JPG

To properly calibrate the magnetometers in this module, the highest and lowest values of each axis must be obtained. To get these values you simply read the magnetometer output while turning the module 360 degrees and in theory there should be directions with the highest and lowest magnetic field strength and these correspond to north and south.

To the left is the function I use to calibrate the magnetometers. I have an function in here called Mx_My and that function is identical to the Azimuth function but without the heading calculation as its simply to get raw data. This function spins the robot to the right for 20 seconds and simultaneously grabs the highest and lowest values it can find. It then stops the robot and calculates the necessary offsets. It calculates the offset by finding the half the span of the values and shifting the values towards zero by that half span. The point is to have equal positive and negative values that can be used in the Heading() function.

Here is a demonstration of the droid trying to find magnetic north and south before and after calibration.

bottom of page