Chapter 19. Magnetometer

Back in Chapter 9, we talked about adding a magnetometer to the mix to prevent drift in the yaw axis. When you start doing navigation, knowing your absolute direction becomes more important. You may know where you are and where you want to be, but if you don’t know which way you are pointing, you can’t get there.

Humans have been using magnetic sensing devices for centuries, and animals perhaps for millennia. We’ve come a long way from floating bits of iron, both in our apparatus and in our understanding. Humans have learned, often by crashing ships onto rocks, about deviation and variation, and about the change in variation over time. The magnetic variation of my local airport has changed over half a degree during my lifetime, as noted on the aeronautical charts.

Practically, in the drone world, the hardware has become pretty simple. A single chip with a convenient I2C interface gives us a three-axis measurement of the local magnetic field. Operationally, compasses remain, as they have always been, a bit of trouble. They must be calibrated (in our case by doing the “magnetometer dance”—just wait!), and sometimes we must compensate for changes in the fields due to the current of the motors.

We have already installed a magnetometer along with the GPS unit, so this chapter will be a discussion of how it works and how best to use it.

The Earth’s Magnetic Field

We’ve all seen the basic picture of how the magnetic field lines flow through the Earth (Figure 19-1). And if you have played much with magnets, you know that they like to line up a certain way, north to south and south to north. So, if we let a magnet move freely without any other magnets nearby, it will line up with the huge but weak magnet that is the Earth. Humans have long known how to float a lodestone (a naturally magnetic rock), or later iron pins, so that they would point toward magnetic north.

Figure 19-1. The Earth’s magnetic field is not quite aligned with the geographic north pole

Notice the term magnetic pole. The first thing you need to know in order to make use of a compass for navigation is that the magnetic north pole is currently several hundred kilometers from the geographic north pole, the axis that the Earth rotates around. And the magnetic north pole moves over 50 kilometers per year, lately heading northward out of Canada. Geologists tell us that the Earth’s magnetic field has flipped north for south several times in its history, though we don’t expect this to affect navigation any time soon.

We, or perhaps our computers on our behalf, must pay attention to the difference between magnetic and geographic north when trying to fly a magnetic course and track ourselves on a geographically oriented map. To get this right requires an understanding of not just the global but also the local differences between maps and compass readings.

Declination and Deviation

Declination, more commonly called variation, measures the local difference between magnetic and true north. This includes both the difference because of the different positions of the poles and the local differences caused by things like differences in the thickness of the Earth’s crust of local deposits of iron ore. Humans have learned about declination the hard way, often paying with the lives of mariners.

Christopher Columbus noted that the difference between magnetic and true north changed considerably as he crossed the Atlantic in the fifteenth century. By the seventeenth century, it was understood that this difference also changes over time, and that there will be purely local differences. But it wasn’t until the nineteenth century that accurate and useful maps of the resulting compass variation were available.

Deviation, as opposed to declination or variation, describes our attempt to measure the Earth’s magnetic field, not the field itself. It has long been known, for example, that any iron in a ship can throw a compass off—a real problem once the hulls began to be made of it! In the 1800s John Gray and then Lord Kelvin came up with systems to correct for this effect. Lord Kelvin’s system places two large balls of iron, one on either side of the ship’s binnacle or compass stand, which can be moved to compensate for the error. Traditionally painted red and green (Figure 19-2), these are commonly known as Kelvin’s balls.

Figure 19-2. The red and green balls on this ship’s binnacle correct for the presence of iron in the ship

In modern aircraft, we still carry a basic magnetic compass, and it will also include a set of small magnets placed around it to correct for the presence of iron in the structure of the plane. But this correction is never perfect, so aircraft compasses also come with a so-called compass card. This small card, placed next to the compass, lists the remaining error at different angles so the pilot can correct that last degree or two. When you’re traveling at 500 miles an hour, a small angle can become a big distance in a hurry!

Magnetoresistance

Of course, our drones don’t carry an iron needle floating in oil. They carry solid-state devices using a property known as magnetoresistance. Scientists and engineers have discovered many different mechanisms by which the electrical resistance of a material can be made to vary with the magnetic field around it. As they found ever larger effects they had to make up ever sillier names, like “giant magnetoresistance,” “colossal magnetoresistance,” and even “extraordinary magnetoresistance.” The magnetometer chips in our drones generally use anisotropic magnetoresistance (AMR), which means that the change in resistance varies with the direction of the magnetic field—a useful property when you are trying to find direction.

Each of the named types of magnetoresistance may, in fact, be produced by a combination of multiple underlying physical mechanisms. Without going into all the details, one outcome of the way AMR works also has a fun name that you may hear used to describe these systems: barber-pole sensors. AMR sensors start with a thin strip of permalloy, a nickel-iron alloy. But by itself this will only tell you, in effect, how close you are to pointing to north, not whether you are a bit east or west. By placing a series of aluminum strips across the permalloy at 45-degree angles, the response to the left and right become different, and the resulting chip looks something like a barber pole, as seen in Figure 19-3.

Figure 19-3. The aluminum strips help determine left from right and make the structure look like a barber pole

Use in Drones

Putting a modern magnetometer into our drone control system is easy. Choose a chip like the HMC5883L three-axis magnetometer that shares the puck with our GPS receiver. Now connect power and the I2C interface, and you’re done. But building compasses was always the easy part. Learning to use them is the problem.

All of the things we’ve just talked about show up in our flight software and calibration processes. When you’re setting up a drone using ground control station software, the system can read your position from the GPS receiver and, using the Internet, find your local magnetic declination. Alternatively, you can enter the value by hand.

Next comes what we call compass calibration. Just as they still swing whole ships and planes around to determine the deviation of their compasses, we get to swing our drone around in what is known as “the compass dance.” You start the process by choosing the compass calibration option in your ground control station software, then follow the instructions as you point the drone in different directions and twirl around. Figure 19-4 shows a complete calibration using QGroundControl.

Figure 19-4. This compass calibration screen guides you as you do the compass dance

This process compensates for the presence of lots of strong permanent magnets in the motors—one type of deviation in our compass reading. But we also have electric magnets in those motors and high currents running through our power system, which can create magnetic fields that change during flight. Our large drone design, like many, places the compass and GPS receiver on a mast, several inches above the power system and other radios. This minimizes the interference with the compass, in our case to acceptable levels (as we shall see). To test this and compensate for it if necessary, we can perform the compassmot test.

To perform a compassmot, you must first remove all your props (we’ll talk about choosing and installing props in the next chapter) and put them back on so that they will push down instead of up. Either swap pairs or move them each around by one arm. Then, in a safe location with no other people too close, start the compassmot calibration, which will instruct you to move the throttle up and down. The system will monitor the current being used and the resulting magnetic interference and compute a correction factor for later use. Figure 19-5 shows the results I got: less than 10 percent interference. This low result is not surprising since we have a compass up on a mast.

Figure 19-5. These compassmot results show insignificant interference

Given that I have demonstrated the very low level of interference with this design, I would actually not recommend running this test on this drone unless you have reason to suspect compass problems. First of all, it is dangerous to run these props up to full speed anywhere near people, including yourself. There is also the hassle of and room for error when switching the props around. And finally, it could happen that a bad test result gives a calibration that flies significantly worse than not having done this at all. I’ve done the test, so you don’t have to. This is engineering at work.

We have hardly touched on the fascinating history of the compass, but hopefully you have learned enough to know why you must do that funny dance when setting up your drones. And, of course, you should repeat it if you change the hardware, especially when adding things with more motors, like a gimbal, or if you change locations by more than a few miles. But enough theory for a while. We’re almost ready to fly!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.44.108