Matthew Silic's Posts (3)

Sort by

Introduction

It can be difficult to get useful data from a magnetometer. It can be especially difficult if the data is used to estimate the yaw attitude of the vehicle. For example, the sensor may indicate the proper direction for certain attitudes, but a wrong direction for other attitudes. Or, the yaw estimate may be accurate one day and off the next.

In order for magnetometer data to yield the yaw attitude of a vehicle, the magnetometer must measure the direction of the geomagnetic field (i.e. the Earth's magnetic field). The geomagnetic field points north (more or less) and has been used for navigation for hundreds of years. The challenge is that the geomagnetic field is relatively weak. It is common for the geomagnetic field to be distorted or obscured by extraneous magnetic sources in the vicinity of the magnetometer. The purpose of magnetometer calibration is to extract an observation of the geomagnetic field vector from the sensor’s output, which is corrupted by various errors. 

Over the last several years, I have tinkered with the AK8963 magnetometer, which is part of the MPU-9250 IMU. Through trial-and-error, I eventually arrived at a dependable calibration procedure. The calibration procedure is repeatable and produces sufficiently accurate estimates of the yaw attitude. It is typical for the yaw attitude to have less than 2 degrees of error, provided the aircraft is in the wings-level configuration. Because of this work, the magnetometer now serves as the primary yaw attitude sensor within our autopilot system. 

In this article, I want to share four lessons I learned while integrating the magnetometer into an autopilot system. These lessons are probably familiar to those who work with magnetometers. However, for those who are new to magnetometers, this article may alert you to some common pitfalls. The four lessons are:

  1. Artificial errors impose special considerations on magnetometer calibration.
  2. Autocalibration methods have a fundamental flaw.
  3. Keep it simple with the compass swinging method.
  4. The throttle command can be related to a magnetometer bias.

In the remainder of this article, I will expand upon each of the previous points. For a more mathematical treatment of the proposed calibration procedure, the reader is referred to the attached PDF.

Artificial errors impose special considerations on magnetometer calibration

Magnetometers are subject to two types of errors: instrument errors and artificial errors. Instrument errors are associated with the sensor itself. Instrument errors are less noticeable in high-grade sensors than low-grade sensors. Artificial errors are extraneous magnetic sources that compete with the geomagnetic field. Artificial errors are associated with the environment. For this reason, you should calibrate the magnetometer in an environment that is similar to the sensor's operative environment. Practically, this means calibrating the sensor in its final configuration on the vehicle. This also means calibrating the sensor outdoors, away from buildings and power lines, which may distort the geomagnetic field. While it may be more convenient to calibrate an isolated magnetometer on a workbench, the calibration would likely become obsolete as soon as the magnetometer is mounted on the vehicle. 

It is worth emphasizing that artificial errors are not associated with the sensor itself.  Consequently, you cannot fix artificial errors by getting a better sensor. You fix artificial errors by (i) shielding/isolating the extraneous sources or (ii) removing the effects of the artificial errors from the data. In this work, we take the latter approach.

That said, the choice of magnetometer is still important. The full-scale range (FSR) of the sensor is particularly important. You don't want a sensor with a FSR that is orders-of-magnitude greater than the magnitude of the quantity of interest. This is because range and resolution are competing factors: what you gain in range you lose in resolution. For our application (vehicle state estimation), the quantity of interest is the geomagnetic field, the magnitude of which is about 0.5 Gauss. The AK8963 is a poor choice for our application because its FSR is 50 Gauss, which is 100x greater than the quantity of interest!

Autocalibration methods have a fundamental flaw

An autocalibration method determines the calibration parameters solely from magnetometer measurements. This feature makes it easy to collect the calibration data. Undoubtedly, the ease of data collection contributes to the popularity of a particular autocalibration method, the ellipsoid-fitting method. However, it can be shown that autocalibration methods are unable to correct for misalignment between the magnetometer and other inertial sensors [1]. Furthermore, it can be shown that misalignment is detrimental to attitude estimation [2]. In order to correct for magnetometer misalignment, additional sensors must be used. The theoretical flaw with autocalibration methods has real-world ramifications. In my experience, I have yet to see the ellipsoid-fitting method produce satisfactory estimates of the yaw attitude.

Keep it simple with the compass swinging method

Alternatives to the ellipsoid-fitting method include the dot-product invariance (DPI) method [3] and the compass swinging method. These alternative methods correct for misalignment by assimilating data from an additional sensor. The DPI method assimilates accelerometer data. The swinging method assimilates data from an "imaginary" magnetometer. We obtain data from the "imaginary" magnetometer by deducing the components of the geomagnetic field based on the orientation of the vehicle with respect to a compass rose. The mathematical details for all three calibration methods are included in the attached PDF.

The calibration procedure that I recommend applies the DPI method and the compass swinging method in succession. The DPI method is used to obtain a crude 3D calibration. The swinging method is used to enhance the measurement accuracy in the wings-level position. Of course, the calibration accuracy will decrease as the vehicle departs from the wings-level position. However, it is reasonable to assume the vehicle will remain close to the wings-level position during constant-altitude operations. Furthermore, deviations from the wings-level position are bounded due to roll and pitch constraints.

Ideally, the magnetometer would be well-calibrated after applying the DPI method. In practice, however, the estimated yaw angle can have up to 10 degrees of error. The error is linked to the off-diagonal elements of the matrix that appears in the inverse error model. The off-diagonal elements are difficult to observe using the DPI method. That is, the off-diagonal elements vary from run to run. For this reason, the swinging method is needed as an additional calibration step.

The throttle command can be related to a magnetometer bias

An electrical current will generate a magnetic field according to the Biot-Savart law (see this HyperPhysics article). A large current close to the magnetometer will bias the sensor and alter the estimated yaw attitude. A common source of such a current is the current drawn by the electric powertrain of the aircraft. The current-induced bias can be canceled by subtracted an estimated bias from the magnetometer readings. The estimated bias is proportional to the current. The proportionality constants can be estimated from system identification tests.

Of course, the previous solution requires a current sensor on the powertrain. The current sensor may be avoided by recognizing that the current is related to the throttle command. Using physical models of the UAV's powertrain (see the figure above), we can show that the current-induced bias is proportional to the square of the throttle command [4]. The figure below plots the magnetometer bias versus throttle command. The variable h3 denotes the component of the current-induced magnetometer bias along the z axis of the sensor. Overlaying the data is the quadratic model predicted by the powertrain analysis.8793495290?profile=RESIZE_400x

Conclusion

In conclusion, this article offers four insights on magnetometer calibration. First, we show that artificial errors impose special considerations on magnetometer calibration. Second, we caution the reader about autocalibration methods, such as the ellipsoid-fitting method. Third, we propose a calibration procedure that combines the DPI method and the swinging method. Finally, we propose a quadratic model for throttle-induced magnetometer biases.

magnetometer_calibration_procedure.pdf

References

[1] J. L. Crassidis, K.-L. Lai, and R. R. Harman, “Real-time attitude-independent three-axis magnetometer calibration,” J. Guid., Control Dyn., vol. 28, no. 1, pp. 115–120, 2005.

[2] D. Gebre-Egziabher, “Magnetometer autocalibration leveraging measurement locus constraints,” J. Aircr., vol. 44, no. 4, pp. 1361–1368, Jul. 2007.

[3] X. Li and Z. Li, “A new calibration method for tri-axial field sensors in strap-down navigation systems,” Meas. Sci. Technol., vol. 23, no. 10, pp. 105105-1–105105-6, 2012.

[4]  M. Silic and K. Mohseni, “Correcting current-induced magnetometer errors on UAVs: An online model-based approach,” IEEE Sens. J., vol. 20, no. 2, pp. 1067–1076, 2020.

Read more…

Simple Waypoint Navigation for Fixed-Wing UAVs

There is a simple way to implement waypoint navigation. The algorithm was introduced by Lawrence, Frew, and Pisano back in 2008. You can view the paper here: http://dx.doi.org/10.2514/1.34896.

I have flight tested this algorithm multiple times on a low-resource autopilot embarked on a fixed-wing UAV (see figure below). In this blog post, I want to share my approach to implementing this algorithm. I cannot claim any academic novelty. However, I hope to make this simple and effective algorithm more accessible to other researchers/hobbyists.

8598951697?profile=RESIZE_400x

In the remainder of this post, I will provide a high-level view of the algorithm. I will also show some flight test results. If the reader wants a more mathematical treatment of the implementation, the reader is referred to the attached PDF.

The algorithm is simple because it uses a single guidance vector field. Vector fields, in general, assign a vector to each point in space. Guidance vector fields, in particular, assign a desired velocity vector to each point in a 2D plane. The vector fields are designed such that they guide the vehicle to a particular path. In this case, the vector field brings the vehicle into a loiter circle. The following figure shows the vector field. The vector field also generates a desired acceleration vector. The acceleration vector is needed for accurate path following.

8598890294?profile=RESIZE_400xWe feed the guidance commands from the guidance vector field into the lateral control system. However, the input to the lateral control system is a bank angle (see figure below).  The block labeled “AC” represents the aircraft dynamics and the block labeled “Ail” represents the dynamics of the aileron actuator.
8598944085?profile=RESIZE_400x

Thus, it is necessary to convert the desired velocity and the desired acceleration into a desired bank angle. We use a two-step conversion.

First, we convert the guidance commands into a lateral acceleration command. The lateral acceleration command has two terms. The first term drives the angular misalignment between the vehicle velocity and the desired velocity to zero. The second term incorporates the desired acceleration vector; the second term functions as a feed-forward acceleration term needed for accurate path tracking.

Second, we convert the lateral acceleration command to a desired bank angle. The relationship between lateral acceleration and bank angle is illustrated in the figure below. By banking, the lift force attains a lateral component, which produces the desired lateral acceleration.

8598960700?profile=RESIZE_400x

Having described basic loiter circle tracking, we are ready to move on to waypoint navigation. The waypoint navigation routine is actually loitering in disguise: the routine positions loiter circles so that the vehicle smoothly intersects each waypoint in succession. The positioning algorithm is shown in the figure below.  The positions of the previous waypoint, current waypoint, and next waypoint are denoted by A, B, and C, respectively. The center point lies along the bisector of angle ABC. The loiter radius sets the distance between the center point and the current waypoint. Having determined the loiter center, the next step is to determine the sign of the circulation constant. If C is to the left of the line AB, then the circulation is counter-clockwise (<0). If C is to the right the line AB, then the circulation is clockwise (>0).

8599147484?profile=RESIZE_400x

A nice feature of the positioning routine is that it can work with only two waypoints. The waypoints are stored in a circularly linked list. Hence, the "next" waypoint and the "previous" waypoint can point to the same waypoint. 

Next, we describe the algorithm that governs how the aircraft switches from one waypoint to the next. 

The positions of the current waypoint and next waypoint are denoted by A and B, respectively. Let LA denote the loiter circle that brings the aircraft into A. Suppose the aircraft has just "hit" the current waypoint. The navigation routine sets the current waypoint to B and computes the parameters of LB, the loiter circle that brings the aircraft into B.

Now, the straightforward approach is to immediately switch from using LA to LB. However, this approach will change the guidance vector in an abrupt manner. To achieve a smooth transition between waypoints, the switch from LA to LB occurs when the velocity vectors from both loiter circles are pointing in roughly the same direction.  A smooth transition protects the low-level control system from large changes in the input command.

The figure below illustrates the switching algorithm. In the top plot, the aircraft is about to hit A. In the second plot, the aircraft has hit A and has set up the loiter circle of B. The aircraft, however, continues tracking the loiter circle of A. In the third plot, the guidance vectors from both loiter circles are aligned. The aircraft begins tracking the loiter circle of B.  In the fourth plot, the aircraft is en route to B.

8603314891?profile=RESIZE_400x

8603325682?profile=RESIZE_400x

8603334665?profile=RESIZE_400x8603342856?profile=RESIZE_400xI implemented the guidance system described herein using fixed-point arithmetic on the AMP autopilot, which is made in-house by our research group (see https://doi.org/10.2514/1.I010445). The microprocessor belongs to the DSPIC33 family of microprocessors made by Microchip.

Flight test results are shown in the figures below (map data ©2020 Google). The test took place at the Flying Gators RC Airport in Archer, FL. The first plot shows the flight path of the delta wing UAV performing waypoint navigation with four waypoints. The waypoints are positioned to create a figure-eight trajectory. The second plot shows the flight path of the delta wing UAV performing waypoint navigation with two waypoints. You can view a synthetic video of the flight test here: https://youtu.be/otRW2_80G0U.The video is reconstructed from downlinked telemetry data. You can view an actual video of a portion of the flight test here: https://youtu.be/jQyc3_tk7MA.

8603828281?profile=RESIZE_400x

8603768881?profile=RESIZE_400x

In the first plot, we note that there is a clear asymmetry in the flight pattern. This asymmetry was due to the aircraft being out of trim. When I examined the roll data after the flight test, I found that the aircraft was better at tracking negative roll commands as opposed to positive roll commands. Hence, the asymmetry has to do with the control system, not the guidance system.

In conclusion, this blog post provides an overview of a simple and effective waypoint navigation scheme. For a more mathematical treatment, the reader is referred to the attached PDF. I have also attached a MATLAB code that simulates loiter circle tracking. The vehicle dynamics are represented using a matrix state-space model.

simple_waypont_navigation.pdf

code.zip

Read more…

Sensors for Attitude Estimation

3689740489?profile=original

Hello UAV enthusiasts,

I recently created a slide deck on the topic of sensors for attitude estimation (i.e. gyroscopes, accelerometers and magnetometers). In these slides, I review

  1. Installation considerations,
  2. Stochastic models,
  3. Bias characterization,
  4. Sensor calibration, and
  5. Conceptual models.

The methods and concepts contained in these slides have been "battle tested''. That is, these are the methods and concepts I used while developing a lightweight autopilot system for UAVs. I hope you find some of this material useful. These slides were part of a graduate course titled "Control of Marine and Aerial Vehicles".

All the best,

Matthew

silic_uav_sensors_v2.pdf

silic_uav_sensors_v3.pdf

Read more…