• No results found

Indoor Navigation Using an iPhone

N/A
N/A
Protected

Academic year: 2021

Share "Indoor Navigation Using an iPhone"

Copied!
49
0
0

Loading.... (view fulltext now)

Full text

(1)

Institutionen för systemteknik

Department of Electrical Engineering

Examensarbete

Indoor Navigation using an iPhone

Examensarbete utfört i Reglerteknik vid Tekniska högskolan i Linköping

av

André Emilsson

LiTH-ISY-EX--10/4375--SE

Linköping 2010

Department of Electrical Engineering Linköpings tekniska högskola

Linköpings universitet Linköpings universitet

(2)
(3)

Indoor Navigation using an iPhone

Examensarbete utfört i Reglerteknik

vid Tekniska högskolan i Linköping

av

André Emilsson

LiTH-ISY-EX--10/4375--SE

Handledare: Jonas Callmer

isy, Linköpings universitet

David Törnqvist

isy, Linköpings universitet

Examinator: Fredrik Gustafsson

isy, Linköpings universitet

(4)
(5)

Avdelning, Institution

Division, Department

Division of Automatic Control Department of Electrical Engineering Linköpings universitet

SE-581 83 Linköping, Sweden

Datum Date 2010-06-15 Språk Language  Svenska/Swedish  Engelska/English   Rapporttyp Report category  Licentiatavhandling  Examensarbete  C-uppsats  D-uppsats  Övrig rapport  

URL för elektronisk version

http://www.control.isy.liu.se http://www.ep.liu.se ISBNISRN LiTH-ISY-EX--10/4375--SE

Serietitel och serienummer

Title of series, numbering

ISSN

Titel

Title

Inomhusnavigering med iPhone Indoor Navigation using an iPhone

Författare

Author

André Emilsson

Sammanfattning

Abstract

Indoor navigation could be used in many applications to enhance performance in its specific area. Anything from serious life critical tasks like aiding firefighters or coordinating military attacks to more simple every day use like finding a desired shop in a large supermarket could be considered. Smartphones of today intro-duce an interesting platform with capabilities like existing, more clumsy, indoor navigation systems. The iPhone 3GS is a powerful smartphone that lets the pro-grammer use its hardware in an efficient and easy way. The iPhone 3GS has a 3-axis accelerometer, a 3-axis magnetometer and hardware accelerated image ren-dering which is used in this thesis to track the user on an indoor map. A particle filter is used to track the position of the user. The implementation shows how many particles the iPhone will be able to handle and update in real time without lag in the application.

Nyckelord

(6)
(7)

Abstract

Indoor navigation could be used in many applications to enhance performance in its specific area. Anything from serious life critical tasks like aiding firefighters or coordinating military attacks to more simple every day use like finding a desired shop in a large supermarket could be considered. Smartphones of today intro-duce an interesting platform with capabilities like existing, more clumsy, indoor navigation systems. The iPhone 3GS is a powerful smartphone that lets the pro-grammer use its hardware in an efficient and easy way. The iPhone 3GS has a 3-axis accelerometer, a 3-axis magnetometer and hardware accelerated image ren-dering which is used in this thesis to track the user on an indoor map. A particle filter is used to track the position of the user. The implementation shows how many particles the iPhone will be able to handle and update in real time without lag in the application.

Sammanfattning

Inomhusnavigering kan användas i många applikationer för att förbättra prestan-dan i de områden där de verkar. Allting från seriösa livshotande miljöer, som att hjälpa brandmän eller koordinera militära angrepp till mer vardagliga uppgifter som att hitta till en affär i ett köpcentrum kan dra nytta av inomhusnavigering. Dagens smartphones introducerar en intressant plattform med liknande egenska-per som hos mer otympliga inomhusnavigeringssystem. IPhone 3GS är en kraftfull smartphone som tillåter programmeraren att använda dess hårdvara på ett enkelt och effektivt sätt. IPhone 3GS har en 3-axlig accelerometer, en 3-axlig magneto-meter och hårdvaruaccelererad bildhantering, vilka används i detta examensarbete för att följa användaren på en inomhuskarta. Ett partikelfilter används för att föl-ja användarens position. Implementationen visar hur många partiklar som kan användas i iPhonen i realtid utan märkbar fördröjning.

(8)
(9)

Acknowledgments

I would like to thank my examiner Fredrik Gustafsson for giving me the opportu-nity to work on this thesis project and for the inspiration through projects with firefighters and shopping carts. I would also like to thank my supervisors Jonas Callmer and David Törnqvist for all the help and all the interesting discussions about technical issues regarding this project. They have also been giving helpful comments about this thesis and provided me with knowledge about the navigation filter used in this work. Former classmates, especially Jon Bjärkefur and Rickard Lindberg, deserve my gratitude for their help and support during this work.

(10)
(11)

Contents

1 Introduction 3

1.1 Background . . . 3

1.2 Thesis outline . . . 4

2 Hardware and Measurements 5 2.1 Accelerometer . . . 6 2.2 Magnetometer . . . 8 2.3 Sampling . . . 8 3 Step Detection 9 3.1 Detecting Steps . . . 9 3.2 Walking Styles . . . 11 3.2.1 In the Pocket . . . 11

3.2.2 Attached to the Ankle . . . 13

3.2.3 In the Hand . . . 14 3.3 Rotation . . . 14 3.3.1 Rotation matrix . . . 15 3.3.2 Projection . . . 16 3.3.3 Comparison . . . 16 4 Navigation Filter 21 4.1 General Particle Filter . . . 21

4.2 Particle Filter for Indoor Navigation . . . 22

4.3 PF Resampling . . . 25

5 Results 27 5.1 Simulation . . . 27

5.2 Demo Application . . . 27

6 Conclusions and Future Work 33 6.1 Discussion . . . 33

6.2 Future Work . . . 34

Bibliography 35

(12)
(13)

Symbols and Acronyms

Name Explanation

αH Magnetic heading calculated as atan2(mx, my), [−π, π] αP Corrected angle using projection

αR Corrected angle using rotation matrix ai Accelerometer data for index i = x, y, z

app(s) iPhone application(s)

atan2(x, y) Converts rectangular coordinates (x, y) to (r, θ), where θ = αH in this work

ftp File transfer protocol

FaceDown orientation iPhone with z-axis down and x-axis to the left FaceUp orientation iPhone with z-axis up and x-axis to the right LandscapeLeft orientation iPhone with x-axis up and y-axis to the left LandscapeRight orientation iPhone with x-axis down and y-axis to the right

mi Magnetometer data for index i = x, y, z

N (µ, σ2) Normal distribution with mean µ and variance σ2

OS Operating system

PF Particle filter

Portrait orientation iPhone with y-axis up and x-axis to the right PortraitUpsideDown orientation iPhone with y-axis down and x-axis to the left

std Standard deviation

WiFi Wireless network

ˆ

(14)
(15)

Chapter 1

Introduction

Indoor navigation has been an interesting problem for a long time and a lot of people are still doing research on the topic. The aim of this masters thesis is to implement a demo application on an iPhone 3GS using only its own hardware together with smart algorithms evaluated in MATLAB and an indoor map to navigate indoor. Figures 1.1 and 1.2 are snapshots from the resulting demo app where the indoor maps are pointed out and can be selected on an outdoor map.

Figure 1.1. Snapshot from demo app. An

indoor map is available and could be used.

Figure 1.2. Snapshot from demo app

after selecting the indoor map in fig-ure 1.1.

1.1

Background

The introduction of the Global Positioning System (GPS) made outdoor naviga-tion with high precision possible. Today it is widely used in automobiles, aircraft and watercraft. This precision decreases dramatically when the receiver is placed indoors or close to objects reflecting the GPS signal making indoor navigation difficult. Accurate positioning indoors could be used for anything from aiding firefighters or coordinating military attacks to finding a desired shop in a large supermarket.

(16)

4 Introduction

There are mainly two different approaches when talking about indoor naviga-tion. One when a map is available and one where there is no map to start with. The one without a map is called SLAM (Simultaneous Localization And Map-ping), where the map is created from scratch and the position is given in this new environment[6, 3]. A mono[16] or a stereo[19] camera is usually used today in order to navigate and present the new map. This work only covers the approach where a map is already presented. The challenge is to either find the location in the map or to start from a known location and keep track of the location as the object is moving around.

Since the GPS does not give an accurate enough signal indoor, other techniques like pseudolites (pseudo satellites), UWB, WiFi could be used to replace the GPS signal. When these signals are not available, step counting together with a compass and a map could be used to navigate in an indoor environment. This technique, when no outer signal is available, will be studied in this work.

Techniques that use GPS-like pseudolites[11] have centimeter precision but re-quire installation and calibration of antennas. Techniques that use UWB (Ultra Wide Band) are costly to implement but give a position within a few meters of the true location[24] which is enough for most applications. WiFi is available in most buildings which gives it a wider usage than the other two techniques. The accuracy is dependent on the number of stations available and multipath propa-gation of signals.

Many articles have been written about indoor navigation[12, 17, 9, 18] but also about implementations in an indoor environment[20]. Implementations that claim outdoor precision in an indoor environment[4] are usually large and clumsy to carry around. Something that is not clumsy and that a lot of people already have, are smartphones like the iPhone or htc phones[14, 13]. These phones have GPS receivers, accelerometers and magnetometers together with a relatively high processor capacity making them interesting platforms for indoor navigation.

1.2

Thesis outline

• Chapter 2 describes the sensors available on the iPhone.

• Chapter 3 introduces step detection and compensation for errors in the elec-tronic compass.

• Chapter 4 covers the navigation filter used to present the estimated position of the iPhone.

• Chapter 5 describes the resulting demo application from this work.

• Chapter 6 covers overall conclusion and possible future work that could be done.

(17)

Chapter 2

Hardware and

Measurements

To be able to do any kind of navigation, hardware is of course necessary. The iPhone 3GS was when introduced the most powerful phone available. It has a processor of 600 MHz, 256 MB RAM and a 3,5 inch multi-touch screen with a resolution of 480 x 320 pixels which makes it a really good platform. For nav-igation purposes there is a GPS, an accelerometer and a magnetometer. Both the accelerometer and the magnetometer are measuring in three dimensions x, y, z according to Figure 2.1. The coordinate system suggested by Apple and the one used in this work are shown in Figure 2.2 and values are corrected to work with the coordinate system suggested by Apple.

Figure 2.1. True coordinate system. Figure 2.2. Coordinate system from Apple

used in this thesis.

(18)

6 Hardware and Measurements

2.1

Accelerometer

The 3-axis accelerometer used on the iPhone 3GS to detect acceleration (m/s2), is the LIS331DL from STMicroelectronics. Apple uses the ±2g mode with an up-date rate at 100 MHz which means that the app could get new measurements at a maximum rate of 100 MHz with values between -2g and 2g.

Figures 2.3, 2.4, 2.5 and Table 2.1 show results from tests where the iPhone is static in different orientations. Approximately 10000 samples have been collected with a resolution of 3 decimals. There is a small bias in all measurements since the values should be 0 in two axis and 1 or -1 on the last axis, depending on the orientation.

Figure 2.3. Top row with accelerometer data where the iPhone is static in the

Por-traitUpsideDown orientation. Bottom row with accelerometer data where the iPhone is static in the Portrait orientation. Mean and standard deviation values are presented in Table 2.1.

The accelerometer could be used to calculate the distance traveled, by integrating the acceleration twice. It could also be used to get the orientation of the iPhone or as a step detector. To calculate distance by using only the accelerometer is not a good idea if some kind of precision is needed since the bias on all axes will cause a drift in the position. Even if the bias is known and compensated for, the average standard deviation for all orientations and axes are 0.0094g. This means that if the device is still it could drift as far as 15 meters in one minute or more than 400 meters in 5 minutes according to the formula for constant acceleration in Equation 2.1.

δ = v0t +1

20.0094t

2 (2.1)

v0 is the initial speed which is zero in this case, δ is the possible drift in meters and t is the time in seconds.

(19)

2.1 Accelerometer 7

Figure 2.4. Top row with accelerometer data where the iPhone is static in the

Land-scapeLeft orientation. Bottom row with accelerometer data where the iPhone is static in the LandscapeRight orientation. Mean and standard deviation values are presented in Table 2.1.

Figure 2.5. Top row with accelerometer data where the iPhone is static in the FaceDown

orientation. Bottom row with accelerometer data where the iPhone is static in the FaceUp orientation. Mean and standard deviation values are presented in Table 2.1.

orientation mean ax std ax mean ay std ay mean az std az

Portrait -0,0474 0,0087 -1,0227 0,009 -0,057 0,0082 PortraitUpsideDown -0,0484 0,0084 1,023 0,009 -0,0508 0,0084 LandscapeLeft -1,0646 0,008 -0,000014 0,011 -0,0676 0,0087 LandscapeRight 1,0647 0,008 0,00014 0,0107 -0,0681 0,0084 FaceUP -0,0466 0,0089 -0,0075 0,0098 -1,0005 0,0088 FaceDown -0,0605 0,0087 -0,0046 0,0099 0,9229 0,0079

Table 2.1. Mean and standard deviation of the accelerometer from different orientations

(20)

8 Hardware and Measurements

2.2

Magnetometer

The 3-axis electronic compass used in the iPhone 3GS to detect magnetic fields (µTesla), is the AK8973 from Asahi Asei Microsystems. The electronic compass or magnetometer is able to present the magnetic values in x-,y- and z-axis, the magnetic heading or the true heading to the user.

The magnetic heading points to the magnetic North Pole which is different from the geographic North Pole that the true heading is pointing towards. The differ-ence of magnetic and true heading is not expressed exactly by Apple, but since the heading object of the application needs the current location of the device from the Core Location Framework in order to calculate this value, it is most likely that the magnetic declination at the current location is added to the magnetic heading in order to get the true heading. In Linköping the value was exactly +3.8 degrees compared to the magnetic heading which correspond to the values of 3-4 degrees that SGU (Sveriges Geologiska Undersökning) presents. The magnetic and true values are not corrected for errors introduced when elevating and tilting the iPhone, which is discussed in Section 3.3.

2.3

Sampling

To be able to sample data and analyze it in MATLAB, a sampling app has been created. Two different techniques have been used. One where the iPhone directly sends the data in real time via WiFi to the iPhone Simulator and one that saves the data on the iPhone to send it later via ftp.

The first one works good in an area with high signal strength and low wireless data traffic. There is a small time delay when data is being sent between the iPhone and the simulator, but it is not noticeable to the human eye. This is a good way to demonstrate applications or discover situations when suspicious sen-sor data is generated. This application gives a really good idea about what is actually happening with the sensors when the iPhone is moving around.

The second app can be used in areas without WiFi or when no computer is avail-able. When WiFi connection is reestablished, the data can be sent to a server using ftp. Both apps that have been developed are in the pre-alpha stage and are only intended for analysis purposes in this project in order to build a demo application of indoor navigation on the iPhone 3GS.

(21)

Chapter 3

Step Detection

In order to navigate in an indoor environment, the distance traveled by the user must be calculated. In this work the accelerometer is the available resource for determining the distance traveled. The accelerometer data could be used in differ-ent ways to determine the distance traveled by the user, depending on the walking style which is described in Section 3.2. The demo app of this work uses step detection when the user is walking and a fix step length in order to present the estimated position of the user.

3.1

Detecting Steps

Figure 3.1 shows the accelerometer signal available for all 3 axis. The iPhone is elevated approximately 60◦at sample 200. Ten steps are taken in the figure, 5 steps before the elevation and 5 steps after. The z-axis in Figure 3.1 holds the most information about the steps when holding the iPhonen in the hand.

The 2-norm of the 3-axis accelerometer signal is used to detect steps in order to get an algorithm not effected by the orientation of the iPhone. Even if it is easy to see the steps when looking at the signal in Figure 3.2 and 3.3, it is a bit more difficult to detect it at run time without using too much computational resources and memory by saving old values. The difference of max and min values during a short period of time is used to detect a sudden change in the acceleration, pro-duced when taking a step, directly after the impact of the foot on the floor. If the difference is larger than a threshold and the derivative is positive, a step has been detected. The threshold does not vary too much in general, but walking on a carpet requires a lower threshold than hard indoor floors.

(22)

10 Step Detection

Figure 3.1. 3-axis accelerometer data. The iPhone is elevated approximately 60◦at sample 200. 10 steps are taken, 5 steps before the elevation at 75, 95, 115, 135, 155 and 5 steps after at sample 290, 310, 330, 350, 370.

Figure 3.2. Detection of step using sig-nalpa2

x+ a2y+ a2z, when the iPhone is hand

held. The spikes from above mark when the algorithm in Listings 3.1 detects a step.

Figure 3.3. A zoomed in version of Figure

3.2. Steps and impact of the foot on the floor are market out.

Figure 3.3, shows that the derivative is steeper directly after the impact and there-fore used in the algorithm to save computational resources and memory. This is described in MATLAB code in Listing 3.1, since MATLAB is a language known by most engineers. The disadvantage of using the 2-norm is that a quick turn would also result in a step which could be avoided by only looking at the accelerometer values in the y-axis. There is a trade-off between sensitivity when turning and rotation invariance here. Rotation invariance is prioritized in the demo app. To avoid double steps, the algorithm is turned off for a short period directly after each step and is turned back on shortly after to not miss a step.

(23)

3.2 Walking Styles 11

Listing 3.1. code: stepDetection.m Describing the step detecting progress when

sam-pling at 30 Hz

1 s_n = 8; % H i s t o r y l e n g t h 2 th = 0 . 2 5 ; % T h r e s h o l d

3 d e l a y = -15; % D e l a y b e f o r e a l g o r i t h m c a n d e t e c t s t e p 4 s t e p O K = - s_n ;

5 s ( t ) = s q r t( a_x . ^ 2 + a_y . ^ 2 + a_z . ^ 2 ) ; 6 if( s t e p O K >= 1) 7 s_h = s ( t - s_n : t ); 8 [ m a x V m a x I n d ] = m a x( s_h ); 9 [ m i n V m i n I n d ] = m i n( s_h ); 10 d i f f = a b s(m a x( s_h ) -m i n( s_h )); 11 if(d i f f >= th && m a x I n d < m i n I n d ) 12 n a v i g a t i o n F i l t e r(); 13 s t e p O K = d e l a y ; 14 e n d 15 e l s e 16 s t e p O K = s t e p O K +1; 17 e n d

3.2

Walking Styles

The whole idea of indoor navigation in this work, is to start from a known position and walk around in a known environment while keeping track of the position. In order to do so, the direction and distance of the movements must be calculated in real time to update the estimated position. There are three different settings that have been looked into:

1. Walking with the iPhone in the front pocket.

2. Walking with the iPhone attached to the ankle.

3. Walking with the iPhone in the hand in front of the user.

3.2.1

In the Pocket

The idea of having the iPhone in the pocket is that it can sense the angle it is tilted. If the device is placed in the pocket with the y-axis pointing down at the floor and the z-axis pointing in front of the user, the iPhone would follow the leg i.e the movement of a pendulum. Knowing the length of the leg makes the accuracy of a step ± a few centimeters when approximating the step as an isosceles triangle, illustrated in Figure 3.4. Equation 3.1 is used to calculate the distance of a step, when using the approximation of an isosceles triangle.

D = 2sin(αw

2 )L (3.1)

where D is the distance of one step, L is the length of the leg and αwis the angle

(24)

12 Step Detection Name αw (rad/s) L = 110 cm L = 115 cm A 0,78 83,9 87,4 B 0,74 79,6 83,2 C 0,77 82,6 86,4 Average 0,76 82,0 85,7

Table 3.1. Data from Figure 3.5.

Figure 3.4. Approximated distance D from αw and leg length (L) when walking.

Figure 3.5 shows four steps where the first three steps of the left leg are marked with the letters A, B and C. Table 3.1 shows data from Figure 3.5. The step length of the three steps are presented under L = 110 cm and L = 115 cm, where L is the length of the test subjects legs. The true length of L is approximately between 110 and 115 cm and the true step length of the three steps lies in the interval 80-85 cm. This shows that there is a possibility to measure the step length by approximating the step as a pendulum. This is an approximation for the sake of argument where the values have been extracted manually from the figures. More and longer tests have to be done in order to truly verify the precision of a step length.

(25)

3.2 Walking Styles 13

Figure 3.5. Angle from walking with the iPhone in the pocket. Angle A = 0.78 rad/s,

Angle B = 0.74 rad/s, Angle C = 0.77 rad/s.

3.2.2

Attached to the Ankle

This idea was taken from [23, 5] where different approaches to determine zero velocity was examined. The idea here is that the iPhone is attached to the ankle where steps are easy to detect using the accelerometer as a step detector. There is also a possibility to calculate the actual step length using accelerometer data and integrate the acceleration into distance, as described in Section 2.1. If the iPhone is placed on the ankle with its y-axis down and the x-axis in the forward direction of the leg, it is possible to calculate the distance using the accelerometer values of the x- and y-axis of the device. An accelerometer of the same sort drifts about 2 m in 20 seconds when stationary, which means that even if it is possible to calculate the distance, the precision is not good enough for indoor navigation alone. Since we have the possibility to detect when the foot is approximately still (i.e. when the other foot is taking a step) we can force reset the velocity to zero. In this way, instead of quadratic drift as in the case when distance is calculated from acceleration, we get linear drift in time. This is a fantastic improvement but not good enough for indoor navigation on the iPhone.

To calculate the distance using the accelerometer, a high update frequency is needed in order not to lose to much information. A frequency of 100 Hz is rec-ommended to get all updates from the accelerometer hardware. This is possible to get from the device but with a performance cost. Screen updates or calcula-tions are not recommended in order to get an update interval of 100 Hz. If the iPhone is experiencing overlay during its sampling, the frequency rate will not be constant. This fact introduces new problems with prefiltering of the signal, since new frequencies are introduced when samples are lost.

(26)

14 Step Detection

A large disadvantage of having the iPhone attached to the ankle is that the iPhone itself is not visible while walking. A way to work around this would be to have two devices communicating with each other via Bluetooth or WiFi. This could also solve the sampling problem since the workload could be distributed between both devices. Two devices have not been tested but sampling to a macbook via WiFi have been tested, showing that sampling from the iPhone with a rate of 100 Hz is possible in areas with a strong WiFi signal and low WiFi traffic.

What is really missing in the iPhone is a gyro. A gyro together with the ac-celerometer data would probably make distance calculations more accurate. With a gyro it would be possible to follow the path of the ankle in the air and thereby determining the length of each step.

3.2.3

In the Hand

The iPhone should be in front of the user with the screen facing up and the y-axis pointing forward. Holding the iPhone like this, there is no way to be sure that the iPhone is static. This means that distance calculations are not applicable if some kind of accuracy is needed in the application. The good thing is that the accelerometer is an excellent step detector even if the user is holding the phone in the hand. Also by holding the device fairly parallel to the ground, the magnetometer values in x- and y-axis are spared from lots of noise when the step is made. When the accelerometer is used for step detection, there is no use in having the update interval as high as 100 Hz. By looking at the step graph only a fourth of that should be necessary without losing valuable information. However since there is almost always good to have a safety margin, sampling at 30 Hz is a good idea. Walking with the iPhone in the hand, gets a lot of information from the hardware in a simple way while letting the user interact with the screen during a walk around. This walking style, is the style to be used with the demo app in this work.

3.3

Rotation

If the atan2 algorithm is used to calculate the magnetic heading and the iPhone is elevated or tilted from its correct position with both the x- and y-axis parallel to the ground, an error is introduced to that heading. This phenomena is introduced since the magnetic field is not parallel to the ground as shown in Figure 3.6. Even small rotations around the x- and the y-axis will result in large compass errors if no compensation is made. Two algorithms have been tested in order to eliminate such errors. One uses a rotation matrix with sine and cosine functions and one uses projection. Both get the same result when moving around one axis at the time, but the projection method requires less computation.

(27)

3.3 Rotation 15

3.3.1

Rotation matrix

The idea is to rotate the coordinate system of the iPhone back to its original horizontal position where the x-y plane is parallel to the ground. This requires the error angles θ and φ around the x- and y-axis respectively. The angle around the z-axis should not be used since that would make the iPhone point towards magnetic north all the time.

The uncompensated heading signal, αH, is the magnetic heading of the device. αH= atan2(mx, my) (3.2)

The αHsignal compensated for elevation and tilting of the iPhone using a rotation

matrix, is called αR and is calculated using Algorithm 1.

Algorithm 1 αR, Correction using rotation matrix.

1. Calculate elevation and tilt angles:

θ = atan2(ay, −az) (3.3a) φ = atan2(ax, −az) (3.3b)

where θ represents the angle around the iPhone x-axis and φ the angle around the iPhone y-axis.

2. Calculate rotation matrix to each angle:

=   1 0 0 0 cos(θ) sin(θ) 0 − sin(θ) cos(θ)   (3.3c) =   cos(φ) 0 sin(φ) 0 1 0 sin(φ) 0 cos(φ)   (3.3d)

3. Calculate the compensated rotation matrix mR:

mR= Rθ∗ Rφ∗   mx my mz   (3.3e) 4. Corrected heading αR: αR= atan2(mRx, m R y) (3.3f)

(28)

16 Step Detection

3.3.2

Projection

This method is based on the fixed system of the gravity vector and magnetic field vector. An orthogonal base[1] will be created out of these two vectors and the forward pointing vector of the iPhone will be projected on it to determine the magnetic heading parallel to the ground. The forward pointing vector of the iPhone may vary but is parallel to the y-axis when it is hand held. Algorithm 2 demonstrates how to calculate the corrected angle αP with the gravitation vector v3 and the magnetic vector v2 as input. Figure 3.6 demonstrates the projection

of y on R. To be more precise, y is projected on r1 and r2 which is described in

Algorithm 2.3. This part of the algorithm gives a component in the x- and y-axis of the two dimensional map coordinate system. Since the length of a vector always is positive, it is multiplied with 1 or -1 in the algorithm in order to give the correct result in the atan2() algorithm.

Figure 3.6. Projection of y-axis on r1-r2 plane.

3.3.3

Comparison

In Figure 3.7, a section of the two different algorithms are presented showing that there is a difference in the result under certain conditions. The true heading is not marked in the figure since it is actually not known. The experiment is done by hand and the small variations in true heading when the iPhone is tilted and elevated is not known. It does not matter in this case since the interesting part lies in the comparison of the signals when the heading is almost constant. The two algorithms perform exactly the same when the iPhone is rotated around one axis at the time. In Figure 3.7, the iPhone is rotated around both x- and y-axis at a given time and as seen in the figure, the rotation matrix does not perform well while the projection method does. One disadvantage of using the projection algorithm is that certain angles will make it unstable. This happens when the length of the ˆy vector in the r1-r2 plane is small, i.e. when the ˆy vector is close to

(29)

3.3 Rotation 17

Figure 3.7. αH, αR and αP compared. αP is considered to be the true value in this

figure.

The projection algorithm performs best when the iPhone is stationary and only turned or tilted, but performs badly if the iPhone is moving around. The gravita-tion vector could be seen as a plumb and is one of the base vectors in the R base. When the iPhone is moved around, the gravitation vector moves around as well which introduces errors in the magnetic heading. Figure 3.8 illustrates the errors introduced when steps are taken. At sample 50, the first step is started with an error caused by the plumb effect. At sample 200, the iPhone is elevated which introduces a large error in the atan2 algorithm. αP performs better but is also

affected by the quick change in orientation. At sample 270 another sequence of steps is started with the same error as sample 50.

In order to get the kind of accuracy as shown in Figure 3.8, the accelerometer and the magnetometer values must be prefiltered[8]. Figure 3.9 illustrates the effect of a low-pass butterworth filter, that has been used to filter out the high fre-quency noise together with frequencies for the steps. Even if the prefilter reduces many errors in the magnetic heading, it does not remove the plumb effect which makes the projection algorithm inefficient in cases where the elevation or tilt is not too high.

(30)

18 Step Detection

Figure 3.8. αP compared to αH and mean(αP) with prefiltered accelerometer and

magnetometer values.

(31)

3.3 Rotation 19

Algorithm 2 αP, Correction using projection.

1. Input to the algorithm:

v3=   ax ay az   (3.4a) v2=   mx my mz   (3.4b)

where v3 is the gravitation vector and v2 is the magnetic vector.

2. Construct new orthonormal basis R:

r3= v3 kv3k (3.4c) r2= r3Tv2r3 (3.4d) r2= r2 kr2k (3.4e) r1= r2× r3 (3.4f) R = [r1, r2, r3] (3.4g)

3. Project iPhone y-axis on r1-r2 plane to calculate αP:

ˆ y =   0 1 0   (3.4h) x = r T 1yˆ |rT 1y|ˆ kr1Tyrˆ 1k (3.4i) y = r T 2yˆ |rT 2y|ˆ krT 2yr2ˆ k (3.4j) αP = atan2(x, y) (3.4k)

(32)
(33)

Chapter 4

Navigation Filter

A navigation filter of some sort is needed in order to track the user and present the estimated position. A particle filter, where each particle represents a hypothesis of the true position, could be used to present such information without any complex model as would be needed by the more commonly used Kalman Filter[10] when it comes to tracking of objects.

4.1

General Particle Filter

The particle filter (PF) was originally introduced in [7]. Sequential Importance Sampling (SIS) is the most general of particle filters and described in detail in [2]. SIS suffers from degeneracy problem which means that all particles but one has a weight close to zero. According to [2], adding resampling to the SIS algorithm takes care of the degeneracy problem and makes the SIS algorithm the Sampling Importance Resampling algorithm (SIR). Even if SIR solves the degeneracy prob-lem, new problems arise. The first problem is that resampling limits the ability to parallelize the algorithm and the second is that particles with high weight are se-lected many times, which leads to many repeated particles. Algorithm 3 describes the general idea of the SIR PF.

(34)

22 Navigation Filter

Algorithm 3 Particle filter, SIR

1. Initialise:

– place Np particles at start point

2. Time update: – move all particles 3. Measurement update:

– weight particles according to probability – normalize weight

– resample all particles 4. Estimate update:

–update the estimated position 5. Iterate from step 2

4.2

Particle Filter for Indoor Navigation

The particle filter for indoor navigation is similar to the general SIR algorithm[22]. The basic idea is that Npparticles are placed out on the map normally distributed

around the starting position. Every time new information is available, i.e. when a step has been made, every particle is moved one step length in the direction of the device. The map puts restrictions on the movements and all particles that were moved through a wall are classified as false particles and resampled to a more probable position. As the device moves around, the particles will group together pointing out the most probable position of the device. A small randomness is introduced to every particle at every update in order to compensate for errors in the measurement data.

Algorithm 4 presents the outline of the algorithm used in this work. The initial-ization step is where all arrays of size Np are allocated. Position x, y, xn, yn, xe, ye

is expressed in the two dimensional standard coordinate system and the normal distributed noise is N (0, σ2) representing the noise around the new position. At time update (Algorithm 4.2) all particles are moved one step length in the new direction α which is calculated with the headingF unction(). The heading function could be the simple atan2 function or the more complex projection algo-rithm described in Algoalgo-rithm 2.

In measurement update (Algorithm 4.3) the weight q for all particles is calcu-lated in the weightF unction(). The weight function searches all points from the old position to the new position to find particles that have moved through a wall in the map. Particles walking through walls are given the weight zero. All particles that passes the test, i.e. does not walk through a wall, will be given a weight

(35)

4.2 Particle Filter for Indoor Navigation 23

corresponding to the distance from a probability line which is the center of corri-dors and is the path in the map where it is most likely for a person to walk. The closer a particle is to the probability line, the higher the weight. The weight is not linear but follows a curve of a normal distribution function. The curve of a normal distribution could be adopted to the disturbance in the magnetic field at a specific place. More disturbance calls for a steeper curve in order to keep the particles close to the estimated true path.

The demo application uses green lines to mark the probability path on the map. If there is an area with no disturbance and good signal strength, thicker lines or green areas could be used in order to let the estimated position wander around to places other than the center of the corridor. After the particles have been weighted, they are normalized so that the particle weights sums up to 1. This is done in order to make resampling in the resamplingF unction() easier. The re-sampling function uses the weights to sort out particles close or equal to zero and produce an index with new particles that are more probable. The index could and will probably contain the same numbers many times. The update of the estimated position (Algorithm 4.4) is simply the mean of all particles.

(36)

24 Navigation Filter

Algorithm 4 Particle filter, indoor navigation

1. Initialize:

Np− number of particles x[Np], y[Np] − x, y position

xn[Np], yn[Np] − new x, y position after time update q[Np] − weight of each particle

ind[NP] − index of more probable particles xe, ye− estimated x, y position

wl− N (0, σ2l) wα− N (0, σ2α)

l − step length

2. Time update: – move all particles

α = headingF unction(mx, my) (4.2a) xn[i] = x[i] + sin(α + wα) ∗ (l + wl), i = 1, . . . , Np (4.2b) yn[i] = y[i] + cos(α + wα) ∗ (l + wl), i = 1, . . . , Np (4.2c)

3. Measurement update:

– weight and resample all particles

q = weightF unction(x, y, xn, yn) (4.2d) q = q

P q (4.2e)

ind = resamplingF unction(q) (4.2f)

x = xn[ind] (4.2g)

y = yn[ind] (4.2h)

(4.2i) 4. Estimate update:

– updates the estimated position

xe= P x Np (4.2j) ye= P y Np (4.2k)

(37)

4.3 PF Resampling 25

4.3

PF Resampling

Resampling is the key of the particle filter. A good resampling algorithm could be the difference between a good or a useless PF. When false particles are resampled to valid particles, the particles describe a probability distribution of the estimated position as shown in Figure 4.1. With this approach, if the algorithm gets lost, it is very hard to refind the actual position. Since there could be a lot of temporary disturbances in the magnetic field when moving around indoors, the randomness introduced by the filter may be too small. This would result in particles getting behind the true position and possibly walking into a wall instead of making a 90 degree turn. If no particle makes the turn all particles will be resampled to a single point and will appear to stand in the same place while the device keeps moving. This means that the filter gets stuck. Figure 4.2 demonstrates this phenomena.

Figure 4.1. Particles describing the distribution and a resulting estimated position with

heading.

To work around the problem of getting stuck, some particles could be resampled to new places rather than to existing particles. When resampling to new places, the probability distribution function expressed by the particles will get lost and pos-sible locations are to be found where many particles are close to each other. The most general way of resampling in this way is to place some of the invalid particles at a totally random place on the map. In this way we do not get locked down on a specific place but allow the algorithm to find all possible places. However, in a large map there is a lot of possible places which decreases the performance of the filter and the probability of actually finding the true position.

Instead of only resampling to a totally random place in the map, some of the invalid particles could be resampled to a most likely position. Most likely posi-tions could be main corridors or areas near crossings of main corridors where it

(38)

26 Navigation Filter

Figure 4.2. Magnetic disturbance preventing the algorithm to make the turn and to

lose track of the real position.

is possible to get back on track if the position got stuck earlier. This method decreases the probability of getting stuck, compared to only resampling at valid particles, but only if we are close to and actually walk on the probability lines often. Large open areas and areas where the environment or map look the same in a lot of places are causing many problems. If a particle gets into an open area it is likely that it survives for a long time and a lot of other particles will be resampled to that specific place. Obviously if the environment looks the same in a lot of places there is no way of separating them from each other.

(39)

Chapter 5

Results

5.1

Simulation

MATLAB has been used in this work to evaluate the sampled data and test algo-rithms later to be implemented in the iPhone.

5.2

Demo Application

The demo app is implemented in Objective C and C which are the languages when programming apps to the iPhone. IPhone books [15, 21] have been most helpful. Together with internet and Apples webpage for developers (developer.apple.com) it was possible to implement an app as presented in this section. The demo app

Figure 5.1. Design diagram of demo app.

(40)

28 Results

is called IndoorNav and consists of two modes. The first is the outdoor mode in which a map of the world is available with pins representing an indoor map. The second mode is the indoor map where it is possible to view the estimated position of the user on the map. The outline of the application is described in Figure 5.1 and snapshots are shown in Figures 5.2, 5.3, 5.4 and 5.5. Each of the modes has a root view controller responsible of swapping sub views in and out to the screen according to the user interactions. The root view controller also handles messages and information between sub classes and therefore controls the flow of information in the application.

The particle filter with probability lines has been implemented in the indoor en-vironment of the app. 100-200 particles could be used and even plotted onto the indoor map without any lag in the application when moving around.

Since there were problems with implementing the projection algorithm that was intended to compensate for errors introduced when elevating or tilting the iPhone, the more simple atan2 algorithm is used. When walking around with the iPhone, problems with the heading in some areas with high magnetic disturbance could easily be detected by the user. The app itself or actually the particle filter com-pensates for some disturbance in the magnetic field in real time but the user could easily see if the heading does not point in the direction of the true path and turn the device itself in the opposite direction to compensate for this error.

The indoor part of the application uses about 60 MB of RAM memory which is quite a lot but it is kept almost constant during the operation in the indoor environment. The large indoor map of about 2000 x 1000 pixels is allocated twice and responsible for 90% of the total amount of data used in the program. It is allocated twice since it is allocated by the system and then again by the program to store pixel information, easily accessible by the app. The structure of the pixel information could be changed in order to decrease memory usage.

Figure 5.2. Snapshot demo app. The world

is available.

Figure 5.3. Snapshot demo app. List of

(41)

5.2 Demo Application 29

Figure 5.4. Snapshot demo app. Close to

position with available indoor map.

Figure 5.5. Snapshot demo app. Paused

and zoomed with red particles and blue esti-mated position pointing in the current head-ing.

Problems

A lot of operations that are trivial in MATLAB require some work in Objective C or C. Especially matrix operations that are not supported in iPhone OS 3 had to be written by hand. Matrix operations should be supported and hardware accelerated in iPhone OS 4.

Result

The result of the test walk is very accurate and follows the path of the test person as long as he walks in areas with probability lines. A simulation from prerecorded data with no compensation for magnetic disturbance and a walk around in real time has been made. Prerecorded data collections of the same route has been used in the simulations and are presented in Figure 5.6 and 5.7, where both figures show a simulation with 200 particles.

The true path is described by numbers from 1 to 8 in the figures and marked with a transparent blue line. Numbers 1, 2 and 3 are rooms entered in the tests. Numbers 4, 6 and 7 describes a left turn along the path. Number 5 is example of magnetic disturbance and number 8 is the end of the true path marked with a blue rectangle. The green dot is the end of the estimated path and is less than 6 meters from the true end in all simulations. The difference of the true and esti-mated end is caused by magnetic disturbance on all of the three corridors between number 4 and 8 where the more extensive disturbance is marked by the number 5. The doorways along these corridors are also causing the estimated position to fall behind the true path, since narrow paths kills a lot of particles that is most likely resampled to an existing position before the doorway. Even if the estimated position falls behind, it still follows the true path since some particles that are in front of the estimated position make the turn.

(42)

30 Results

In Figure 5.6, 3 out of 3 rooms are found and the estimated position stops less than 6 meters from the true position. In Figure 5.7, the compass can only have the four directions north, south, west or east, which is the directions of the major corridors in the map. The direction at each step is rounded to one of the four directions. 3 out of 3 rooms are found and the estimated position stops less than 3 meters from the true position. The fixed directions reduce the magnetic distur-bance which improves the accuracy with 3 meters in this case while the effect of the doorways still cause the filter to fall behind.

Figure 5.6. Result from simulation using 200 particles with all directions possible.

In the second kind of test, a walk with the iPhone and the demo app has been made in real time using 200 particles. After walking with the app for a short period of time, the estimated position is spot on or within 1 meter. This is the effect of the human brain compensating for magnetic disturbance by turning the iPhone in such a way that the estimated position heading is pointing in the same direction as the true path. Also, taking shorter or longer steps to compensate for small errors in the position while walking, actually makes the estimated position almost equal to the true path as long as it is close to the green probability lines on the map. Figures 5.8 and 5.9 show snapshots from the demo application at runtime where the estimated position is inside a room and exactly at the crossing of two corridors.

(43)

5.2 Demo Application 31

Figure 5.7. Result from simulation using 200 particles with only north, south, east or

west headings possible.

Figure 5.8. Real time walk into correct room from demo app. Estimated position with direction and red particles representing the probability distribution.

Figure 5.9. Real time walk on crossing from demo app. Estimated position with direction and red particles representing the probability distribution.

(44)
(45)

Chapter 6

Conclusions and Future

Work

6.1

Discussion

This thesis has shown that it is possible to implement a particle filter with 200 particles on an iPhone 3GS and that tracking a position on a indoor map is possi-ble with good precision in real time. The app can only keep track of the device as long as it is running. Even with iPhone OS 4 that supports multitasking, it would probably not be possible to keep track of the position in the background since the application requires all resources on the iPhone to function properly. Hard-ware accelerated matrix operations introduced in iPhone OS 4 as well as putting the navigation filter in its own thread, should improve the performance of the application by making it possible to increase the number of particles used in the navigation filter.

What is really missing in the iPhone is a gyro. A gyro would be most helpful to detect error readings in the magnetic field, making the compass more reliable and insensitive to magnetic disturbances during short periods of time.

(46)

34 Conclusions and Future Work

6.2

Future Work

There is almost always improvements to make in a project and this is no excep-tion. Below is a list of wishable features to be implemented in the app. All of these features are possible to implement with a small amount of work since the foundation of this app has been created in a way that makes changes like the ones listed below possible.

– Path finder from A to B on the indoor map. – Update/download indoor maps from internet. – Matrix operations (requires iPhone OS 4).

– Show indoor maps within a range from a location specified by the user. – Present map specific information on the map with a QR code.

– Interactive indoor maps with information about a specific place. – Navigation filter in its own thread.

(47)

Bibliography

[1] K.G. Andersson. Lineär algebra. Studentlitteratur, 2000. ISBN 91-44-01608-5.

[2] M.S. Arulampalam, S. Maskell, N. Gordon, T. Clapp, D. Sci, T. Organ, and S.A. Adelaide. A tutorial on particle filters for online nonlinear/non-GaussianBayesian tracking. IEEE Transactions on signal processing, 50(2):174–188, 2002.

[3] T. Bailey and H. Durrant-Whyte. Simultaneous localization and mapping (SLAM): Part II. IEEE Robotics & Automation Magazine, 13(3):108–117, 2006.

[4] A. Brown, Y. Lu, and NAVSYS CORP COLORADO SPRINGS CO. Indoor Navigation Test Results using an Integrated GPS/TOA/Inertial Navigation System. In Proceedings of ION GNSS 2006, Fort Worth,TX, 2006.

[5] J. Callmer, D. Törnqvist, and F. Gustafsson. Probabilistic stand still de-tection using foot mounted IMU. In Proceedings of the 13th International Conference on Information Fusion, Accepted for publication, 2010.

[6] H. Durrant-Whyte and T. Bailey. Simultaneous localisation and mapping (SLAM): Part I the essential algorithms. Robotics and Automation Magazine, 13(2):99–110, 2006.

[7] N.J. Gordon, D.J. Salmond, and A.F.M. Smith. Novel approach to nonlinear/non-Gaussian Bayesian state estimation. In IEE Proceedings, vol-ume 140, pages 107–113, 1993.

[8] F. Gustafsson, L. Ljung, and M. Millnert. Signalbehandling. Studentlitter-atur, 2001.

[9] A. Hub, J. Diepstraten, and T. Ertl. Design and development of an indoor navigation and object identification system for the blind. ACM SIGACCESS Accessibility and Computing, pages 147–152, 2003.

[10] R.E. Kalman. A new approach to linear filtering and prediction problems. Journal of basic Engineering, 82(1):35–45, 1960.

(48)

36 Bibliography

[11] C. Kee, D. Yun, H. Jun, B. Parkinson, S. Pullen, and T. Lagenstein. Centimeter-accuracy indoor navigation using GPS-like pseudolites. GPS WORLD, 12(11):14–23, 2001.

[12] H. Kuusniemi, R. Chen, J. Liu, Y. Chen, L. Pei, and W. Chen. An adaptive multi-sensor positioning system for personal navigation. Technical report, De-partment of Navigation and Positioning, Finnish Geodetic Institute, Finland, 2006.

[13] M.H.V. Le. Indoor Navigation System for Handheld Devices. PhD thesis, Worcester Polytechnic Institute, 2009.

[14] T. Lundberg and M.L. Korse. Indoor positioning on the android platform. Master’s thesis, LTH, Lund, 2010.

[15] D. Mark and J. LaMarche. Beginning iPhone development: exploring the iPhone SDK. Apress, 2009.

[16] M.J. Milford and G.F. Wyeth. Mapping a suburb with a single camera us-ing a biologically inspired SLAM system. IEEE Transactions on Robotics, 24(5):1038–1053, 2008.

[17] L.E. Miller. Indoor navigation for first responders: A feasibility study. Tech-nical report, Wireless Communication Technologies Group, 2006.

[18] G. Opshaug and P. Enge. GPS and UWB for Indoor Navigation. Department of Aeronautics and Astronautics, Stanford University, 2004.

[19] L.M. Paz, P. Pinies, J.D. Tardos, and J. Neira. Large-scale 6-dof slam with stereo-in-hand. Robotics, IEEE Transactions on, 24(5):946–957, 2008. [20] L. Ran, S. Helal, and S. Moore. Drishti: An integrated indoor/outdoor blind

navigation system and service. Technical report, Computer Information Sci-ence Engineering Department University of Florida, 2004.

[21] E. Sadun. The iPhone Developer’s Cookbook. Addison-Wesley, 2009. [22] T.B. Schön. Estimation of Nonlinear Dynamic Systems

Theory and Applications. Linköpings universitet, 2004. ISBN 91-85497-03-7. [23] I. Skog. Low-Cost Navigation Systems. PhD thesis, KTH, Stockholm, 2009. [24] A. Wernrud, A. Johansson, J. Rantakokko, P. Eliardsson, and U. Uppmanan. Soldier and first responder RF-positioning in indoor environments. Technical report, Division of Information Systems, Swedish Defence Research Agency, 2009.

(49)

Upphovsrätt

Detta dokument hålls tillgängligt på Internet — eller dess framtida ersättare — under 25 år från publiceringsdatum under förutsättning att inga extraordinära omständigheter uppstår.

Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för icke-kommersiell forskning och för undervisning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av doku-mentet kräver upphovsmannens medgivande. För att garantera äktheten, säkerhe-ten och tillgänglighesäkerhe-ten finns det lösningar av teknisk och administrativ art.

Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan be-skrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsmannens litterära eller konstnärliga anseende eller egenart.

För ytterligare information om Linköping University Electronic Press se förla-gets hemsida http://www.ep.liu.se/

Copyright

The publishers will keep this document online on the Internet — or its possi-ble replacement — for a period of 25 years from the date of publication barring exceptional circumstances.

The online availability of the document implies a permanent permission for anyone to read, to download, to print out single copies for his/her own use and to use it unchanged for any non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional on the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility.

According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement.

For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its www home page: http://www.ep.liu.se/

c

References

Related documents

På många små orter i gles- och landsbygder, där varken några nya apotek eller försälj- ningsställen för receptfria läkemedel har tillkommit, är nätet av

Detta projekt utvecklar policymixen för strategin Smart industri (Näringsdepartementet, 2016a). En av anledningarna till en stark avgränsning är att analysen bygger på djupa

Det verkar som om utländska uppköp leder till stora omstruktureringar i de förvärvade företagen som höjer produktiviteten i dessa: investeringarna i maskiner och utrustning ökar

DIN representerar Tyskland i ISO och CEN, och har en permanent plats i ISO:s råd. Det ger dem en bra position för att påverka strategiska frågor inom den internationella

Av 2012 års danska handlingsplan för Indien framgår att det finns en ambition att även ingå ett samförståndsavtal avseende högre utbildning vilket skulle främja utbildnings-,

Det är detta som Tyskland så effektivt lyckats med genom högnivåmöten där samarbeten inom forskning och innovation leder till förbättrade möjligheter för tyska företag i

Sedan dess har ett gradvis ökande intresse för området i båda länder lett till flera avtal om utbyte inom både utbildning och forskning mellan Nederländerna och Sydkorea..

Swissnex kontor i Shanghai är ett initiativ från statliga sekretariatet för utbildning forsk- ning och har till uppgift att främja Schweiz som en ledande aktör inom forskning