Description

Institutionen för systemteknik Department of Electrical Engineering Examensarbete Indoor Navigation Using Accelerometer and Magnetometer Examensarbete utfört i Reglerteknik vid Tekniska högskolan vid Linköpings

Information

Category:
## Travel & Places

Publish on:

Views: 59 | Pages: 60

Extension: PDF | Download: 0

Share

Transcript

Institutionen för systemteknik Department of Electrical Engineering Examensarbete Indoor Navigation Using Accelerometer and Magnetometer Examensarbete utfört i Reglerteknik vid Tekniska högskolan vid Linköpings universitet av Johnny Merkel, Joel Säll LiTH-ISY-EX-ET--11/0385--SE Linköping 2011 Department of Electrical Engineering Linköpings universitet SE Linköping, Sweden Linköpings tekniska högskola Linköpings universitet Linköping Indoor Navigation Using Accelerometer and Magnetometer Examensarbete utfört i Reglerteknik vid Tekniska högskolan i Linköping av Johnny Merkel, Joel Säll LiTH-ISY-EX-ET--11/0385--SE Handledare: Examinator: Jonas Callmer isy, Linköpings universitet Daniel Staf ENEA David Törnqvist isy, Linköpings universitet Linköping, 3 October, 2011 Avdelning, Institution Division, Department Division of Automatic Control Department of Electrical Engineering Linköpings universitet SE Linköping, Sweden Datum Date Sprk Language Svenska/Swedish Engelska/English Rapporttyp Report category Licentiatavhandling Examensarbete C-uppsats D-uppsats vrig rapport ISBN ISRN LiTH-ISY-EX-ET--11/0385--SE Serietitel och serienummer Title of series, numbering ISSN URL fr elektronisk version Titel Title Inomhusnavigering med hjälp av accelerometer och magnetometer Indoor Navigation Using Accelerometer and Magnetometer Frfattare Author Johnny Merkel, Joel Säll Sammanfattning Abstract This project will create a navigation system based on dead reckoning using an accelerometer and a magnetometer. There have previously been several studies made on navigation with accelerometers, magnetometers (electronic compass) and gyros. With these three components it is possible to do positioning and different kinds of movement analyses. There are several methods for detection of movement and calculation of position. To achieve greater accuracy in these applications, gyros are often used. Compared to magnetometers and accelerometer gyros consumes a lot of power. In an embedded system with limited power supplies from a battery this may be unacceptable. In this project a positioning system without a gyro have been developed and evaluated. Is this possible to do, and what accuracy is possible to achieve are questions asked. Algorithms have been developed and tested in MATLAB. The project is based on a device called a BeeBadge, part of the project will be to transfer the developed algorithms from MATLAB to C-code. Optimizations of the code will be performed due to the constraints in the memory and speed of the microcontroller on the BeeBadge. Nyckelord Keywords Kalman, Accelerometer, Magnetometer, Embedded System, Navigation, Hard Iron Compensation, Soft Iron Compensation Abstract This project will create a navigation system based on dead reckoning using an accelerometer and a magnetometer. There have previously been several studies made on navigation with accelerometers, magnetometers (electronic compass) and gyros. With these three components it is possible to do positioning and different kinds of movement analyses. There are several methods for detection of movement and calculation of position. To achieve greater accuracy in these applications, gyros are often used. Compared to magnetometers and accelerometer gyros consumes a lot of power. In an embedded system with limited power supplies from a battery this may be unacceptable. In this project a positioning system without a gyro have been developed and evaluated. Is this possible to do, and what accuracy is possible to achieve are questions asked. Algorithms have been developed and tested in MATLAB. The project is based on a device called a BeeBadge, part of the project will be to transfer the developed algorithms from MATLAB to C-code. Optimizations of the code will be performed due to the constraints in the memory and speed of the microcontroller on the BeeBadge. Sammanfattning I det här projektet så kommer ett navigeringssystem baserat på dödräkning med hjälp av en accelerometer och en magnetometer att skapas och utvärderas. Det har tidigare gjorts flertalet studier inom navigering med accelerometrar, elektroniska kompasser och gyroskop. Med dessa tre komponenter är det möjligt att utföra positioneringsberäkningar och olika rörelseanalyser. Det finns flertalet olika metoder för rörelseanalys och beräkning av position. För att uppnå högre noggrannhet vid dessa beräkningar så används ofta gyroskop. I förhållande till accelerometrar och elektroniska kompasser så drar gyroskop väldigt mycket ström och i ett inbyggt system där strömförsörjningen från ett batteri är begränsad, kan valet att använda ett gyroskop bli problematiskt. I projektet har ett navigeringssystem för positionsbestämning utan gyroskop utvecklats och utvärderats. Målen har varit att ta reda på om det är genomförbart och vilken nogrannhet man kan uppnå. Initialt har alla algoritmer utvecklats och testas i MATLAB. Projektet är baserat på en enhet som heter BeeBadge och utöver simmuleringarna i MATLAB har alla v vi algoritmer implementerats till hårdvaran i C-kod. Optimering av koden kommer att utföras på grund av hårdvarubegränsingar av BeeBadgens minne och processor. Acknowledgments We would like to thank: Enea, for making this project possible. Our supervisor Daniel Staf at Enea who have been a great aid with software and hardware related problems. Our supervisor Jonas Callmer who have aided us along the project and we would also like to thank our examiner David Törnqvist vii Contents 1 Introduction Method and Purpose Outline Hardware Components and Sensors Sensor Axes Step Detection Filtering Step Threshold Peak Average Max and Min Average Step Determination Heading Earth s Magnetic Field Rotation based tilt-compensation Projection based tilt-compensation Tilt-compensated Heading Magnetometer Calibration Hard Iron Offset Experimental Hard Iron Compensation Soft Iron Offset Magnetometer Offset Navigation Filter State Estimation and Measurement Models Non-linear Model Filter Model and Implementation ix x Contents 7 Implementation in C Approach Math Functions Optimization Experimental Results Problems and Verification Results Concluding Remarks Conclusions Future Work Bibliography 53 A Trigonometric Functions 55 Symbol β θ σ φ ψ a a x, a y, a z B B x, B y, B z d e 1, e 2, e 3 F k g G x, G y, G z m ˆm m R H k I Ox, I Oy, I Oz m x, m y, m z m h x, m h y, m h z K k n k N k O x, O y, O z Q k P k r k R 1, R 2 R k R x, R y v k w k x k X max Y max ˆx k ˆx k z k Explanation Smoothing constant used in filtration Pitch or soft iron ellipse angle Soft iron scaling factor Roll Yaw (heading) Accelerometer vector Accelerometer axes Used to derive Noise covariance Q k Magnetometer s output (before compensation) Projected vector, tilt compensation World axes Process model Gravity Global axes Magnetometer vector Tilt-compensated Magnetometer vector (Projection) Tilt-compensated Magnetometer vector (Rotation) Measurement model Magnetometers internal offset Magnetometer axes (all compensations done) Magnetometers axes (hard iron compensated) Kalman gain Accelerometer norm, unfiltered Accelerometer norm, filtered Hard iron offset on magnetometer axes Noise covariance of w k Estimated Error Covariance Norm of m x and m y Rotation matrices Noise covariance of v k Rotation matrices Measurement noise Process noise State Estimate m x when r k reaches its max value m y when r k reaches its max value a priori State Estimate a posteriori State Estimate Kalman measurement (ψ) Chapter 1 Introduction In this project a system for navigation has been developed using a magnetometer and a MEMS accelerometer. The navigation has been based on the detection of steps and calculation of heading. The project is based on a device called BeeBadge, distributed by Enea. The device is the size of a credit card and in the version used in this project it includes one magnetometer, one accelerometer and a microcontroller used for calculations and wireless communications. In Figure 1.1 the BeeBadge can be seen as it was used during the experiments. It is in the figure placed in a cardboard box and mounted on the hip. 1.1 Method and Purpose Using the accelerometer to detect steps and the magnetometer to calculate heading and position will only give a certain degree of accuracy. Partly due to errors in the step length and partly due to inaccuracies in the compass. The magnetometer is affected by ferrous metals and magnetized objects, which leads to results that sometimes are very erroneous. This is even more so indoors with electrical cabinets, beams or girders. The focus during development of the navigation system has therefore been to do measurements outdoor and from that construct a system that also could work indoors. Step detection is based on accelerometer data. This will together with the calculated heading from the magnetometer data be processed in a extended Kalman filter. Most of the measurements have been done with the BeeBadge strapped to the belt, but some initial test were done with the unit placed in the pocket and on the ankle as well as in the hand. A transition of the developed method for having the unit strapped in any of these locations is possible. 3 4 Introduction 1.2 Outline The contents of the chapters in this report will follow the same chronology as the calculations are performed. In the first chapter called Hardware there will be an introduction to the hardware and sensors used, followed by how measurements are performed and how the data is processed. The next step is described in Step Detection where the treatment of accelerometer data and step detection is described. After this the Heading chapter follows where the heading calculation is treated, using both magnetometer and accelerometer data. For the computation of heading to be performed correctly calibration of the magnetometer is necessary and a Chapter Calibration is therefore dedicated to this. To increase accuracy in positioning an extended Kalman filter is used, how this is structured can be read about in the Navigation Filter chapter. As all development was performed in MATLAB while the BeeBadge is programmed in C, the different functions developed for navigation have also been translated to C. The process behind this is described in Chapter Implementation in C. Figure 1.1. In the figure the BeeBadge can be seen mounted on the hip. Photo is taken during testing and the BeeBadge is for convenience mounted in a box. Chapter 2 Hardware This project is built on an early version of a device called BeeBadge and is the size of a credit card. The BeeBadge is designed to be power efficient and mobile. In the version used in this project an accelerometer, a magnetometer and a wireless microcontroller were included. The microcontroller is used for radio communication and calculations. Motion tracking and positioning is done in many similar devices, very often a gyro is used. The benefit of having a gyro is that angular velocities can be measured instead of only linear acceleration, allowing for calculations of speed and distance traveled more accurately. Gyros are compared to accelerometers very power consuming. Using only an accelerometer without a gyro to compensate it, acceleration will over time create very large errors. The BeeBadge has during this project been connected to a FTDI-chip allowing communication via USB. Wireless communication have not been used. The Bee- Badge have been printing data via UART to a terminal where it was captured as a txt-file. Simulations in MATLAB were later based on these files, allowing for repeated tests on a specific set of data samples. 2.1 Components and Sensors The accelerometer used is a three-axis and has the possibility to store up to 32 samples of X, Y & Z readings, this means that you need not read as often. The magnetometer also has three axes though no internal buffer except for the output registers. Worth to mention is that on the magnetometer the output registers are numbered from 0x03-0x08, two registers for each X, Y and Z output data. When read sequentially they contain the X, Z and Y-values and not X, Y and Z-values, this needs to be considered when retrieving data and doing calculations. 5 6 Hardware The calculations are done on a small microcontroller. It has a 32-bit CPU than can run up to 32 MHz with built in 2.4 GHz radio. The RAM and ROM are also built in and 128 kb each. The size of memory and speed of the CPU are the biggest restrictions. The BeeBadge has an API in Eclipse with a framework of functions, including communication with the sensors. Additional functions to support navigation were added and some minor modifications in the existing structure were done, such as sample rate of the sensors and the CPU-speed. For some timing purposes the microcontroller uses a 32 khz external crystal oscillator as clock reference. This crystal may be a bit off so there is a built-in possibility of calibrating it against the much more exact 32 MHz internal crystal oscillator. This calibration is basically a measurement of how many 32 khz ticks there are from the external crystal compared to how many there should be according to the more accurate 32 MHz clock. The calibrated interval is used as a reference for a wake timer. When the wake timer is called it returns the number of ticks that has passed since it was started and the time in seconds can be derived from that. This is amongst other things used as a time-stamp to see when data is read from the sensors. 2.2 Sensor Axes Both the accelerometer and the magnetometer have three axes, X, Y and Z. For the navigation to function as intended some parts of the algorithm requires that the X-axis points forwards, the Y-axis to the right and the Z-axis down. On the BeeBadge the sensors are not aligned with each other. The magnetometer s X and Y axes are turned 90 with respect to the accelerometer s X and Y axes. A global positioning of all axes is therefore necessary, the alignment can be seen in Figure 2.1. The new axes will in this document be referred to as G x, G y & G z respectively. 2.2 Sensor Axes 7 Figure 2.1. Alignment of magnetometer and accelerometer axes in global axes system. Chapter 3 Step Detection In this project the detection of movement is based on the detection of steps, which are derived from the accelerometer s output. When a step is detected the system will calculate the heading and the new position. In this chapter different methods for detecting steps are explained. When a step is taken the three axes on the accelerometer will be affected and the output will change. Depending on where the accelerometer is mounted on the person carrying it the output will look different, but there are similar patterns. The methods for step detection described in this chapter have only been thoroughly tested when the unit is carried on the hip, but with some modifications they can also be used when the unit is carried on the ankle, in a pocket or in a hand. When walking at a constant pace, the acceleration is always greatest at the beginning and at the end of a step [9]. This is due to the cyclic up and down motion the walker has. There will also be a small acceleration in the walking direction and a rotating movement around the center of the walking person. All these motions together affect the accelerometers X, Y and Z output. To simplify the detection of steps the norm of the accelerometer data is calculated. This eliminates the need for the accelerometer to be oriented in a specific way as there is only one instead of three samples of data to look at. The accelerometer is very sensitive to motions, the different axes have individual biases and the output is not 100% accurate. This makes low pass filtering of data necessary. 3.1 Filtering To be able to calculate accurate results low pass filtering is necessary. During the initial experiments in MATLAB a low pass third order Butterworth filter was used. This filter was later compared to a first order filter and the same accuracy in step detection could be achieved. The low pass Butterworth filter was therefore 9 10 Step Detection replaced by a simple first order low pass filter, see (3.1a). The new filter does not provide as smooth output because it is only a first order filter, but it proved to produce good results anyway. It is also slightly less computationally heavy than a third order filter. N k = βn k + (1 β)n k 1 N k = N k 1 + β(n k N k 1 ) (3.1a) (3.1b) Here n k is the unfiltered accelerometer norm and N k is the filtered norm. The subscript k is the index in a set of data. β is called the smoothing constant and is a number between 0 and 1. The closer to 1 that β is, the lower is the cut-off frequency. This is more clear in (3.1b). Filtering the accelerometer axes independently tends to give unreliable results. Filtering of both the accelerometer axes and the norm also gives results that are erroneous. It is therefore sufficient to filter only the calculated norm, saving time and power. In Figure 3.1 both filtered and unfiltered accelerometer norm can be seen when the simple filter is used. In the example used, the unit have been strapped to the belt when walking Accelerometer Norm Filtered Accelerometer Norm Unfiltered Accelerometer Norm 16 Magnitude Sample Figure 3.1. Filtered and unfiltered norm from accelerometer output. From a walking set when the unit is strapped to the belt. 3.2 Step Threshold In Figure 3.1 the filtered norm of accelerometer data can be seen. From the data norm a threshold is derived to help decide when a step occurs. A step can be said to occur when the data norm crosses this threshold. In this project two simple 3.2 Step Threshold 11 ways of calculating a threshold have been tested. Every person has its own style when walking, and the same person will produce different accelerometer norms if walking fast or slow, on grass or on asphalt. During measurements, the person wearing the BeeBadge may be changing speed. The threshold must therefore be dynamic, it must be able to adapt itself after the accelerometers output. To be derived they both require a number of data samples and the algorithms can therefore not be used in real time, but steps are detected immediately after a data set has been collected. The number of samples necessary to calculate a threshold can be chosen arbitrarily. When walking, a set of one second of samples gives a good result, in this project one second corresponds to 50 samples. Fewer samples can be used but gives a more unstable result. A peak in the data norm occurs before or after a foot is put down on the ground. A valley occurs when the foot is in contact with the ground and the leg is vertical above it. The peaks seen in the data norm have different amplitude depending on where the BeeBadge is carried. If it is placed on the right hip the right foot on the same side will give higher peaks in the accelerometer norm Peak Average This method for calculating a threshold uses the height of the peaks occurring in a set of samples. All the peaks are added together and then divided by the number of peaks that occurred. The result is the threshold for the set. When the different thresholds were tested a low pass Butterworth filter was used, this method then proved to give worse and more unstable result than the Max Min method described below. As the work progressed the Butterworth filter used for filtration was replaced by a much more efficient and simpler low-pass filter. A result of this new filter was that the peak average method gave more stable and reliable results than before. The reason for this might be that the third order Butterworth filter produces a too smooth result. When the new first order filter is used some small peaks between the higher peaks are left. These small peaks might help creating a better average. The peak average method is not implemented in the final version of the naviga

Related Search

Similar documents

We Need Your Support

Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks