• No results found

Phase detection for attitude determination In quadrotors or 'drones'

N/A
N/A
Protected

Academic year: 2022

Share "Phase detection for attitude determination In quadrotors or 'drones'"

Copied!
44
0
0

Loading.... (view fulltext now)

Full text

(1)

Electronic Systems and Instrumentation

Phase detection for attitude determination In quadrotors or 'drones'

Mads Peter Hammer Strand

(2)

Examiner: Bengt Oelmann, bengt.oelmann@miun.se Supervisor: Dag Roar Hjelme, dag.hjelme@iet.ntnu.no Author: Mads Peter Hammer Strand,maphstra05@gmail.com Degree programme: Degree of Master of Arts/Science, 120 credits

(3)

a signal source. A correlation between orientation and phase-detector output is proved, and it is concluded that with further work on algorithms and signal filtering, an attitude determination system could be made.

As Quadrotors or ’drones’ are controlled by a system that could benefit by another reference system, accuracy of the phase-detector system is compared with the navigation systems currently used in drones.

(4)

stand how to write a thesis, my teacher Dominik Osinski, who is always eager to provide moral support and help, my co-student Runar Bruun Sivertsen for discussions and distractions, and finally my university and the other teachers there who where always ready to provide equipment and answers.

Abbreviations

• ADC - Analog to Digital Converter

• AHRS - Attitude and Heading Reference System

• d - distance between antennas

• d1 - Antenna one

• d2 - Antenna two

• DAC - Digital to Analog Converter

• DCM - Direction Cosine Matrix

• fq - RF frequency

• pd - Phase Difference

• pl - ’Phase Lag’

• R - Distance drone-source

• RSS - Received Signal Strength

• TDoA - Time difference of arrival

• UAV - Unmanned Aerial Vehicle

*If viewed in PDF-format, all figure numbers, chapter numbers and citations are click-able for easy navigation.

(5)

1.1 Background . . . 1

1.2 Overall aims, scope . . . 1

1.3 Verifiable goals . . . 2

1.4 Outline . . . 3

1.5 Related Work . . . 3

2 Other Considerations 4 3 Theory 5 3.1 Magnetometer based attitude determination . . . 6

3.2 Phase based attitude determination . . . 7

3.2.1 Phase lag . . . 8

3.2.2 Phase response to attitude change . . . 9

4 Method 11 4.1 Hardware and software . . . 11

4.1.1 Data acquisition . . . 11

4.2 Phase-detection . . . 12

4.2.1 Choice of physical parameters . . . 12

4.2.2 Simulation environment . . . 13

4.2.3 Algorithm test . . . 15

4.2.4 Phase detector test . . . 15

4.3 Magnetometer based attitude determination . . . 16

4.3.1 ’Competing’ orientation systems test . . . 16

5 Results 17 5.1 Orientation Comparison test . . . 17

5.2 Phase Detector . . . 19

5.2.1 Algorithm . . . 19

5.2.2 Voltage Response . . . 21

5.3 Prototype . . . 22

6 Discussion 25 7 Conclusion 26 8 Appendix 27 8.1 References . . . 27

8.2 Data Acquisition Schematic . . . 29

8.3 Matlab Source Code . . . 29

8.4 Arduino Source Code . . . 33

(6)

1 Introduction

The general idea of this thesis is that two antennas receiving the same signal, located separately on an object, will read the signal phase shifted in compar- ison to each other due to the signal having to travel a different distance/time to each antenna. Using a phase detector to measure this difference, it could be possible to determine the two antenna’s current angle in relation to the sig- nal source, and therefore the objects rotation or attitude also. The idea came from another project given by the company Haukr AS, who produce drones for commercial use. They had issues where the magnetometer on their drones was so much influenced by the engines that difficulties controlling the drone could arise. Originally their idea was some sort of shielding of either the magnetome- ter, power-cables or both. While working on how to shield these components the idea to approach the problem in another way entirely arose.

1.1 Background

Correct attitude determination is a necessity for most modern vehicles or air- craft. Traditionally this has been solved using Attitude and Heading Reference Systems (AHRS)[1][2], which uses mainly gyros that keep track of the vehicles motion. A gyro can sense when and how much an object is turning. I.e if you know you were pointing north, and the gyro says you have turned 180 degrees, now you know you are pointing south. However, gyros are prone to bias and

’drift’ errors, which means you cannot use them to ’remember’ your entire jour- ney from the starting point and at all times know your direction. Their position needs to be updated by some other reference. This has normally been solved by using gravity sensors(accelerometers) to update the directions pitch and roll, and a magnetometer to update yaw. All these parts constitute the AHRS.

Although AHRS technology is well tried and tested, there still exist some challenges. I.e Drones use magnetometers to correct for the ’drift’ that their gyroscopes suffer from, but because of magnetic influence from their engines, this is often not accurate enough. In this thesis, a method using phase difference detection to correct for drift is researched. If the phase-detection system turns out to be feasible, it will be less prone to influence from nearby magnetic fields and could be used in addition to or instead of the magnetometer to supply another reference value. A majority of vehicles today already use a Kalman-filter to evaluate their sensory input, so another input could easily be implemented into the AHRS.

1.2 Overall aims, scope

Although the system will provide continuous readings, it will very likely not be able to compete with a gyroscope in accuracy for instantaneous updates. A gyroscope does this very well. Instead, this system will try so substitute the function of the magnetometer, correcting for drift on the gyroscope. This thesis

(7)

will describe theoretical concepts and show simulations of how a system like this could be made to work. A working prototype would likely require an extensive analog circuit to filter and amplify the incoming signals, this will not be done in this project. However, a prototype without filtering and amplification will be made, to see if there still can be discovered a correlation between rotation and phase detector output.

It is realized that a system consisting of two antennas will not be enough on its own to create a complete attitude determination system, as phase detectors are unable to separate ’lagging’ and ’heading’ phase, and thus only can measure in the 0-180 degree range. Also a phase detector reading zero phase difference will not be able to tell which way a vehicle is pointing, only that the antennas are perpendicular to the source at that time. A solution to this could be a third antenna and a second detector, or incorporating measurements from a gyroscope or magnetometer, but this will not be in the scope of this project.

Proving that a system like this can work could be of considerable interest in several different applications, not just in drones, but ships, airplanes, cars.. All modern vehicles could use an autonomous navigation system, and an alternative that does not rely on magnetometers or suffer from the inaccuracies of them would be interesting in a lot of fields.

1.3 Verifiable goals

The ultimate aim of the task is to prove a correlation between vehicle orientation and phase detector output, while also researching, determining and developing the tools and processes that would be needed to create a complete attitude determination system.

In order to be a ’worthy’ addition to a drone’s (or other vehicle’s) already complex hardware, the system should at least be able to compete with the magnetometer mounted on the drone for accuracy. Therefore, a basic prototype of a magnetometer based navigation system similar to those used in drones will be made to have an attitude determination system to compare the phase- detection system with. A test that can be done on the different systems to determine how well they do in comparison in different circumstances will also be made.

As it can be hard to visualize and understand issues and problems in such a task, it was deemed useful to create a software simulation to help doing just this. It would also be useful to have an external-error free environment in which to test the concept. In this simulation, and also in general, an algorithm that can use phase-difference to calculate angle is needed. If the distance between source and antennas is known, this is straightforward, but this is rarely the case in practice.

It is also necessary to test the characteristics of the phase detector, and how its voltage output relates to differences in phase. Its useful to test that it actually works before hooking it up to antennas, and for accurate results one should be able to know precisely which phase the phase-detector is currently measuring.

To test the phase detector we need two signals which we can accurately shift

(8)

the phase of. It should be possible to generate these using a computer and the Labview-environment.

To summarize:

• Create a prototype that uses sensors to receive signals and data, and that can pass these to a computer for processing and testing. This data will hopefully prove a correlation between orientation and phase detector output.

• Create a test to compare ’competing’ attitude determination systems.

• Create a software simulation for visualisation purposes.

• Develop an algorithm that can use phase-difference to calculate angle.

• Create an experiment that can manipulate phase detector inputs and mea- sure outputs.

1.4 Outline

The first chapter, 3, will explain the theoretical concepts that are utilized in this task, and try to motivate my choice of methods that where used to achieve my results.

Then chapter 4 will describe the method in which experimental data was retrieved and processed. Chapter 5 will try to explain and visualize this data in a meaningful way.

Finally I will discuss my choice of method and what could have been done differently in chapter 6, and conclusions will be drawn in chapter 7.

The appendix, 8, will contain references, source code and schematics, so that my experiments and results can be reproduced.

1.5 Related Work

General problems with determining attitude of drones or UAV’s is discussed in [1] and [2], which utilize ’traditional’ sensors (magnetometer, accelerometer, gyro) and Euler angles to simplify describing both attitude and translational velocity in one ’quaternion’. Since this thesis only deals with attitude, not translation, Euler angles will not be necessary. While using phase-detection to determine attitude in UAV’s is a relatively unique proposition(as far as can be found), a similar method is studied in [3], where they propose to use phase detection to determine the attitude of a satellite in relation to a ground station.

They conclude that it is feasible to use this method in small satellites, where it fits a niche between coarse sun-based sensors and accurate image based sen- sors. [3] also delve deeper into the analog circuit needed to filter and amplify signals for such a system than this thesis will do. Where they make use of a grid of patch antennas (i.e in a 4x4 format) to determine horizontal and verti- cal attitude, this thesis will only consider horizontal attitude (vertical can be handled by an accelerometer) and initially just two antennas, with a larger sep- aration. In their paper they also operate with a fixed ground station, and the distance between signal source and receiver will be considerably lower in this thesis. Notably an approximation suggested in this paper will be made use of.

(9)

Another solution proposed by [4] is to utilize a drones inherent mobility to rotate a directional antenna mounted on the drone. Measurements of received signal strength (RSS) is stored for the period of rotation, and detecting the peaks in signal strength gives the orientation where the antenna faces the signal source. This method has the disadvantage that the drone has to stop mid-flight to perform its attitude-determination routine.

Figure 1.1: RSS when quadrotor is rotating in a fixed position, the peaks cor- respond to the attitude facing the signal source.[4]

2 Other Considerations

This thesis is proposing a new approach to solving a technological challenge, but a successful implementation will only provide an improvement on equipment that is already in day to day use in today’s society. Therefore there are no apparent ethical or social consequences to consider as a result of this thesis.

(10)

3 Theory

To understand the issue at hand in this thesis, it is necessary to get a basic under- standing of the points and challenges with vehicle attitude control. Determining attitude only makes sense if there is something to determine attitude in relation to. In this thesis attitude has been described as in relation to the signal source, but this information is not necessarily useful in itself. Say a drone needs to head north, if it only knows its attitude in relation to the signal source, this does not help it find which way to travel. Here it becomes useful to introduce the concepts of body referenced and global referenced coordinate systems, both with shared origo.

Figure 3.1: Local coordinate sys- tem(i,j,k) and global system(I,J,K).[5]

Imagine a global coordinate sys- tem common to everything on earth, where the x-axis can be defined to always point north, y-axis to always point west and z axis points up. It is possible for a vehicle to ’sense’ these axes using i.e a magnetometer to de- termine north and an accelerometer to determine up and down. If it also can sense its own rotation(its body referenced system), it can -in the case of drones- determine which engines to power up to achieve the desired direc- tion of travel, be it north, south, west or up. It can also translate its orien- tation and heading to the global ref- erence system, which can be accessed by another vehicle so they can both be aware of each others motion.

Imagine we implement the means so measure and place the axes of the global coordinate system on a vehicle. These measurements will always be made from the point of view of the vehicle, so if it rotates, the axes of the global system will seem to rotate. This is of course not true, north will always be north, what actually changes is the relation between the body and the globally referenced coordinate systems. This relation is usually expressed by the Direction Cosine Matrix (DCM) or the ’rotation matrix’. This is a 3x3 matrix defined so that if you multiply a vector or a point in one reference frame with the matrix(or its transpose), you will get the coordinates or vector in the other frame[5]. This is useful, i.e, a drone is ordered to head north, if it knows it’s DCM, it can translate ’north’ to its body-referenced frame, and now know what engines to turn on.

Using these new definitions, a rewording of the whole problem at hand could be ’find the current DCM’.

If we use the definitions from figure 3.1, i,j,k is the body referenced unit vectors, and I,J and K is the global unit vectors, it can be shown that the DCM

(11)

is defined as the dot product between these different vectors, like below.[5]

DCM =

I.i I.j I.k J.i J.j J.k K.i K.j K.k

As from the point of view of the vehicle, its own body referenced coordi- nate system will always be the same, we can define its unit vectors as i=[1,0,0], j=[0,1,0] and k=[0,0,1], and this will always be true. As the dot product of a vector A and the vector [1,0,0] equals A(1) and soforth, the matrix becomes:

DCM =

I(1) I(2) I(3) J (1) J (2) J (3) K(1) K(2) K(3)

This simplifies the process. Now the only values that are needed are I, J and K, or the direction of north, west and up. If those values could be accurately measured at all times, we could get the DCM, and thus know our vehicles orientation in relation to them, which makes sense.

3.1 Magnetometer based attitude determination

Since the aim of the phase detector is to substitute for the magnetometer when it does not provide sufficiently accurate readings, a system using the traditional magnetometer method for attitude determination was made, to make a com- parison. Also, if the goal is to determine magnetic north, the complete system would still require a magnetometer, only located at the source not at the vehi- cle.

As described previously, the required function of the magnetometer is to de- termine magnetic north, or the I vector in the DCM. A magnetometer reading provides us with the current strength of the magnetic field, represented as a 3-dimensional vector. Desirably, this vector is constituted only of the earths magnetic field at that location, but this is not always the case, which is the whole reason we need to supplement it. The magnetic vector is represented by the values x, y and z, where the x and y-axes are parallel to the magnetometers surface, and z-axis goes through it. This means a magnetometer will provide an accurate reading only as long as it oriented so that its surface is parallel to the earth’s surface, this is of course not guaranteed. A solution to this is to use a gravity sensor to determine the direction of ’down’, rotate the z axis to face opposite of this direction, then transpose the magnetometer reading to the plane perpendicular to the z-axis at origo. When this is done, the resulting transposed magnetic vector should point north. A demonstration is shown in figure 3.2. An accelerometer has read the current value of G, and a magnetome- ter has read the magnetic field vector. Both of these values are sent to matlab, where the calculations to transpose the vector are performed.

(12)

Figure 3.2: Body referenced coordinate system(black), transposed coordinate system(x=green,y=blue,z=teal). The actual magnetometer vector(purple) and the transposed magnetometer vector(red).

Using this method all three values of I,J and K can be determined, I is the transposed magnetometer vector, K is the opposite of the accelerometer vector, and J is perpendicular to both of these. Choosing the ’left’ option of y, we achieve that y will point west. Using these vectors as the DCM provides us with a way to continuously update the global reference frame from the drones point of view. This is the way that is commonly used today to correct for drift in drones, and therefore this is the system that will be used to compare the phase detector based system with.

3.2 Phase based attitude determination

The phase difference of a signal received at two different antennas is the same as using the ’time difference of arrival’(TDoA) at the two antennas, as the phase measured is purely a function of time. Measuring time difference directly accurately enough is difficult at such low distances, as it is in the order of nanoseconds. As an example, a rather large antenna separation of 50 cm will give a TDoA of 1.67 nanoseconds at maximum separation. Using the Nyquist

(13)

theorem, this would require a sampling frequency of ≈ 1.2 GHz just to tell if the signals did arrive at the same time or not, which is not even close to accurate enough.

Using a phase detector, we achieve a much more efficient method of doing this, as the ’phase speed’ can be increased or decreased by tuning the frequency of the signal. Using a common RF frequency of 433 MHz, equation 1 shows that the phase difference between the antennas is as much as 4.53 radians for an antenna seperation of 50 cm, even though the time difference is so short.

This is more difference than necessary for the detector(the distance between the antennas should be smaller). This is how a phase detector can detect time difference a lot more accurately than simply measuring the TDoA of the signals, assuming it is rated to the frequency. The phase difference and time delay is given by 1, where fq is the RF frequency.

pd = 1.67ns ∗ 2π ∗ f q (1)

3.2.1 Phase lag

The actual time difference is given by the distance between the signal source and each antenna. The closest antenna will receive the signal first, and there- fore get an ’earlier’ phase than the antenna further away. It is straightforward to calculate how this phase shift will change in response to different antenna orientations.

Figure 3.3: Drone and source, normal position.

Figure 3.3 shows how a drone might be positioned with the line be- tween its antennas placed normally to the signal source(red). If we imagine the drone to be positioned along d, with antenna one at the top left and antenna two at the bottom right, the distance between each antenna and the source is given by vectors d1 and d2. If we assume the source is trans- mitting, the phase at antenna one will be lagging behind the source because of the time needed for the signal to travel the distance d1. This ’phase lag’ is defined by equation 2. As

f q

c = 1λ this reduces to equation 3.

pl = d1

c ∗ 2π ∗ f q (2) pl = d1

λ ∗ 2π (3)

As an example, a wavelength of 69cm (433 MHz) and a distance of 10m will give us a lag of ca 90 radians or 5200 degrees.

(14)

However, the interesting thing is not how much antenna one lags behind the source, but the difference in lag between antenna one and two. This difference can be calculated directly by equation 4.

pd = |d1 − d2|

λ ∗ 2π (4)

In figure 3.3 the distances are the same, so the phase shift in the received signals will be exactly 0. In figure 3.4, we see that the drone now has rotated in comparison with the source. Lets assume that d1=10.25m and d2 = 9.75m.

Equation 4 gives us a total phase shift of 4.53 radians or 260 degrees.

3.2.2 Phase response to attitude change

Figure 3.4: Drone and source, rotated position(Simplified). The antenna posi- tions move in a circle with radius d/2 centered around the drone center when the drone rotates.

Thus far, calculating the phase differ- ence (and therefore calculating back- wards from reading the phase differ- ence) seems straightforward. How- ever, these equations all assume that the distance d1 and d2 are accurately known. This will never be the case in a real system. Therefore, an alterna- tive solution used in the thesis "Small Satellite Attitude Determination"[3]

is proposed instead. The method they use is to utilize the fact that normally R is much larger than d. If we look back to figure 3.3 and assume that this is the case, we can approximate that d1 and d2 ≈ R.

Looking at figure 3.4 and compar- ing with figure 3.3, as mentioned the difference between the two is that now the drone has rotated by the angle Θ, which we see three places in the fig-

ure. Also note that the vectors d1 and d2 has respectively increased and de- creased by the amount ∆d1 and ∆d2. We denote the new totals d1+∆d1 = d1t, and d2-∆d2 = d2t. Using basic trigonometry, we can now get expressions for the lengths of ∆d1 and ∆d2:

∆d = sin Θ ∗ d

2 (5)

Expressions for the total lengths then become:

d1t = d1 +sin Θ ∗ d 2 d2t = d2 −sin Θ ∗ d

2

(6)

(15)

Going back to equation 4, remember that the difference between d1 and d2 is what we need to solve the equation. Using our new totals we set the equation:

d1t − d2t = d1 +sin Θ ∗ d

2 − (d2 −sin Θ ∗ d

2 ) (7)

which factors down to:

d1t − d2t = d1 − d2 + d ∗ sin Θ (8) Here the assumption R » d comes in. The difference between d1, d2 and R is so small that we can approximate both to be equal to R, the equation then becomes:

d1t − d2t ≈ R − R + d ∗ sin Θ ≈ d ∗ sin Θ (9) Inserting this into equation 4, we get:

pd = 2π ∗ d sin Θ

λ (10)

or finally:

sin Θ =pd ∗ λ

2π ∗ d (11)

Which gives a function for the rotation angle Θ dependent on the phase differ- ence pd, which is what we are interested in. As this approximation was proposed to be used in satellites, where the distance R is always much greater than d, it was deemed necessary to test whether this could be used in smaller ranges too.

This test is shown in the Results section, chapter 5.2.1.

Another way to achieve a translation between pd and attitude, would be to map a reading of both of these using a gyroscope as reference for attitude. Then try to regress a function from this data that can translate between the two sets.

As more than one phase detector might be needed for a complete orientation system, some form of this procedure will probably be necessary. Using machine learning algorithms would probably be useful here.

(16)

4 Method

4.1 Hardware and software

Both software simulations and hardware experiments are utilized to complete project goals. The hardware used is mostly motivated by availability, price and ease of use. The components are as follows:

• Microcontroller, Arduino Uno. This controller was selected due to previ- ous experience working with it. Also, it was readily available, has all the capabilities needed to perform the project experiments and is cheap to get if someone else wants to reproduce this task[6]. In addition, drones often use a version of Arduino or a similar microcontroller.

• Magnetometer, Honeywell-HMC5983. Selected due to cheap price and availability as an integrated circuit. Easy i2c communication with the Arduino[7].

• Accelerometer, InvenSense MPU-6050. Also selected due to availability, also uses i2c communication and has an onboard gyroscope[8].

• Phase detector, Analog Devices AD8302. Selected due to being cheap, available as an integrated circuit, large operational range and linear response[9].

To program the Arduino, the Arduino IDE was used. Other software used is Matlab for receiving, processing and displaying data, as well as Labview to synthesize signals.

4.1.1 Data acquisition

The actual reception of data from the sensors is done using the Arduino. Its function is simple, it will start the sensors with the proper commands, gather data continuously, monitor serial input from the computer, and output the appropriate data.

Figure 4.1: Data flow.

The Arduino-computer com- munication is done using serial, where the computer(Matlab) sends a character to the Ar- duino, depending on the char- acter, the Arduino returns a specific value of data to Mat- lab. The Arduino also han- dles writing to the registers of the magnetometer and the accelerometer at initial setup.

Some registers need to be set for appropriate behaviour.

Since this will provide Matlab with all the data from the sensors real time, some in-

teresting experiments can now be made in an easier coding environment than

(17)

pure C++. Also now data can be displayed properly in figures real time.

The result is a sample rate of about 10 sets of data per second(on my system).

Higher baud rate on the serial communication might increase this, also other optimizations could probably be made. Right now all digital filters is done while reading data, which is not strictly necessary. The code running on the Arduino is based on the projects in [10] and [11]. The code was modified to run simultaneously and to provide the data requested by matlab over serial. Matlab and Arduino source code can be found in appendix 8.3 and 8.4

4.2 Phase-detection

4.2.1 Choice of physical parameters

Rewriting equation 11, we see that the physical parameters that needs to be decided are frequency(wavelength(λ)) and distance between antennas(d).

sin Θ =pd ∗ λ

2π ∗ d (12)

The goal here is to make a choice that gives us a plausible d while maxi- mizing the phase difference between the two signals. The system should also not reach saturation to early, that is, if to high a frequency is chosen, the phase difference will reach maximum and ’start over’ long before we reach 2π radi- ans. As well, the phase detector alone cannot distinguish between ’lagging’ and

’heading’ phase, so the maximum phase difference it can detect is 180 degrees.

Beginning with an arbitrary but plausible antenna separation of 40 centime- ters, we can calculate the frequency needed to get 180 degrees phase shift at maximum antenna separation by using equation 13.

pd = d

c ∗ f q ∗ 360 f q = 180 ∗ c

360 ∗ 0.4 = 374M Hz

(13)

374 MHz seems as good a frequency as any, however frequencies are legally restricted, and this frequency falls in to the category of military and air-traffic control[12]. To be safe another choice should be made. There is a commonly used amateur-available frequency quite close, 433 MHz, for which there also exists lots of cheaply made RF components. Deciding to use 433 MHz, equation 13 gives an ideal antenna separation of 34.62 cm. Both of these parameters are acceptable, so these values will be used in further simulations and experiments.

(18)

4.2.2 Simulation environment

In order to test whether a phase-detection based orientation system could work theoretically, it was decided to create a matlab simulation/visualization of such a system. An interactive script was created where the user can move the drone around, rotate it, and actual rotation and approximated information from the- oretical phase-shift measurements are plotted and stored for processing. This could be a useful tool for developing algorithms that produce actual orientation data from phase-measurements.

Figure 4.2: Simulation environment. The user is able to select drone position and orientation(source is fixed), and results are shown in figure 4.3. In this simulation antenna separation is 34.6 cm and frequency is 433 MHz(chapter 4.2.1), but other parameters can be selected.

(19)

Figure 4.3: Simulation environment. Phase-difference and calculated theta is shown live. Currently the drone has not translated but has completed two complete revolutions. Note, the gyro(global orientation) does not start at the same zero as the phase detector in this example, due to the simulated drone not being directly north or south of the source.

Theta is the variable that can be calculated from phase shift using the method described in chapter 3.2.2. As seen in figure 4.3, it only varies between 0-90 degrees. This is because a rotation from no time difference to maximum time difference is only 90 degrees, as illustrated in figure 4.4. This setup can not calculate whether the drone rotates in one or the other direction due to the phase detectors inability to separate ’lagging’ or ’heading’ phase.

Figure 4.4: Theta response to attitude change.

An algorithm would need to incorporate measurements from the magne- tometer or gyro in addition to the phase detector, or alternatively use three phase-detectors, to separate between one direction or the other. This would still simplify the task of the magnetometer, as it now only needs to determine if

(20)

the drone is heading north or south, then the phase detector can calculate the specific orientation.

Note, this is a two-dimensional simulation. Other issues will also arise in a three-dimensional environment, specifically if the drone is at a higher altitude than the signal source, which is likely to happen. Assuming the drone keeps a level orientation compared to ground, which it in most cases do, the effect on phase-difference will still be small. Further work would be to expand the simulation to include all three axes, to measure the effect different altitudes would have.

4.2.3 Algorithm test

As mentioned in chapter 3.2.2, it was necessary to test whether the approxima- tion suggested by [3] would be accurate enough. The approximation required that the distance between source and antenna where larger than the distance between antennas, but didn’t specify by how much. A script was created in Matlab that utilizes the software simulation and gradually reduces the distance between drone and signal source while calculating actual and approximate phase shift for each step. The approximate phase shift is calculated in accordance with equation 10, while the actual phase shift is calculated using the time difference for a simulated signal to reach each antenna. The process is repeated for differ- ent values of d(distance between antennas). The result is discussed in chapter 5.2.1.

4.2.4 Phase detector test

One of the project goals is to develop a robust system for testing phase-detector response. This will be necessary for both testing and development, where it would be useful to at all times know exactly the phase the detector is currently experiencing, and what voltage it outputs. For this to be accomplished, it is necessary to have complete control of the phase difference between to signals to the detector, and at the same time measure its response. Due to having no signal generators which are able to output two signals and accurately shift the phase between them(there is probably not often much need for such functional- ity) a program utilizing National Instruments Labview and its myDAQ where created. The program was based on an example found at National Instruments forums[13], and modified accordingly to provide the functions needed. Com- puter generated signals go through a DAC, and are therefore severely limited in their output frequency. Every single point in the sine function is actually a constant voltage that needs to be reset to a new value for the sine function to progress. For an accurate sine, around two hundred such points need to be made for each period. That means that if you were to generate a signal of 433MHz, you would need a clock frequency two hundred times higher. Ex- periments showed that the program was able to generate up to 10KHz signals accurately.

The program outputs two signals, allowing the user to select phase difference

(21)

between them, and uses the myDAQ analog input port to read the phase re- sponse from the detector. The results are stored in a text file for processing.

These results are discussed in chapter 5.2.2

4.3 Magnetometer based attitude determination

4.3.1 ’Competing’ orientation systems test

As specified in chapter 3.1, an experiment to test the accuracy of two ’competing’

orientation systems is needed. The goal of this script is to calculate the accuracy of one method of determining orientation in reference to another. For reference, a gyroscope will be used, as this is the most accurate sensor that is available.

Since the test lasts about a minute, errors due to gyroscope drift are negligible.

Using the Arduino to gather data from our magnetometer and accelerometer, the method of obtaining magnetometer heading explained in 3.1 is implemented.

The results are saved continuously while the Arduino board and the sensors are manually rotated. After the test is done, the data from the magnetometer and gyroscope are stored in Matlab. Three experiments where performed, one

’normal’, one trying to do faster rotation, and one where the magnetometer where subjected to induced noise in the form of an electrical current running close to it. This is the situation the magnetometer will experience if it where to be used on a drone.

The stored data from the magnetometer and the gyroscope is then post- processed in matlab. Due to observed inconsistencies in the results, a spike filter is run on both sensor values, removing any data that differentiates largely from previous measured values. The results are then shifted to have the same mean value, then plotted on the same axes. Output of a successful test is shown and discussed in chapter 5.1

(22)

5 Results

This chapter will show the result of the experiments that was done during this task. First the ’Orientation Comparison test’ then the tests on the phase detector, and finally the implementation of the orientation comparison on the prototype drone, to compare all three orientation sensors.

5.1 Orientation Comparison test

As is seen in figure 5.1, at first view, the accuracy of the magnetometer seems quite good in this experiment. The orange line of the magnetometer seems to follow the reference(blue) well. The mean difference is still 8 degrees, which is higher than what the magnetometer is rated at[7], but as is evident from the curve, both signals are still subject to a bit of noise. Better software filters(like the Kalman filter), could probably get better accuracy. Figure 5.2 shows a test done using faster rotation, and the magnetometer is still able to keep up.

Figure 5.1: Plot of magnetometer determined rotation angle vs gyroscope deter- mined. Slow rotation(100 samples ≈ 10 seconds). Standard deviation is given in degrees.

Using fast rotation, the mean difference between the magnetometer and the gyroscope reached 14.9 degrees, however, it might be that the projection of the axes used(chapter 3.1) deteriorates the accuracy of the magnetometer.

To illustrate the problem with using a magnetometer as a reference in drones, an electric field where introduced near the magnetometer while running the test.

(23)

This gives us a quite a different result, as shown in figure 5.3.

Figure 5.2: Same as figure 5.1, using faster rotation.

Figure 5.3: Orientation test while turning on/off an electric field close to the magnetometer. Red=on, Blue = off.

In figure 5.3, a live wire running 3 amps where kept close to the magnetome-

(24)

ter during testing. The current was switched on and off, as denoted by the red and blue dots on the figure. Red representing power on and blue representing power off. As seen, the magnetometer readings become completely untrustwor- thy with this variable introduced, although some of the deviation is caused by the mean-shift operation on the data. Even while not being an accurate repre- sentation of the conditions a magnetometer on a drone experiences, this result illustrates the problem with using magnetometers to determine attitude when close to a current source.

5.2 Phase Detector

5.2.1 Algorithm

A simulation was made where the accuracy of the approximated function de- scribed in 4.2.3 was calculated. The angle Θ was held constant at 30 degrees and frequency at 433 MHz. The results where plotted, and the test was repeated for different separations of antennas. As seen on figure 5.4, the approximation only fails at very low distances to the source, less than two meters. The approx- imation phase shift gives us the same result no matter how we vary the distance, while the actual shift is reduced when we get close to the signal source. Also increasing the distance between the antennas increases the ’minimum distance’

of the algorithm. We can conclude that the approximation is reasonable as long as the distance is larger than a few times the antenna separation. As the drone will almost never operate within two meters of the source, the approximation seems to work sufficiently, but for testing purposes the minimum distance will need to be kept in mind.

(25)

Figure 5.4: Accuracy of approximation at different antenna separations.

(26)

5.2.2 Voltage Response

In chapter 4.2.4 the process of creating a test for voltage response to different phase differences was discussed. The resulting Labview interface is shown in figure 5.5. The labview MyDAQ is outputting two signals that are connected to the phase detector, and the interface allows for dynamically changing the parameters of the two signals. The signals has been run for some time, and the phase difference has been changed up and down. The voltage response is evident, shown in the right graph.

Figure 5.5: Labview interface. Left waveform shows current output signals, right shows phase detector voltage history. The dial allows the user to select current phase difference ouput.

Figure 5.6 shows post processing done on the data of the test using matlab.

Every voltage point read has been added and averaged by the number of samples at that frequency. As seen, the response is linear. A linear regression was done on the data, and for 1KHz and 2 volts input, the response follows the function:

u = −0.01116 ∗ pd + 1.96240 (14) With an R value above 0.99, which is very high. However this is a the average of many datapoints, the actual output of the detector is not this consistent. As seen on figure 5.5 the raw signal is quite noisy. It is expected that the constants of the equation will change during exposure to an actual signal, which will be much higher frequency and not necessarily 2 volts.

(27)

Figure 5.6: Voltage Response to phase difference.This is symmetrical around 180 degrees, that is if the graph showed up to 360 points, the voltage would rise at the same rate again.

The results in figure 5.6 matches what we would expect from the data- sheet(page 10)[9], even at this low a frequency. The voltage at 0 degrees shift is expected to change as the frequency and voltage of the input signals change, but as long as we do not reach maximum or minimum input voltage on the ADC, an algorithm should be able to scale the data properly no matter the voltage.

Parts of this tool should be useful in developing such an algoritm.

5.3 Prototype

A prototype drone was made according to the specifications in chapter 4.2.1.

Using a signal generator hooked up to an antenna, we create a 433 MHz signal that two antennas placed ≈ 17 cm apart will receive and transmit to the phase detector. One antenna is hooked directly to the detector, while the other goes through an isolated cable to prevent the cable acting as an antenna. The reason for using half the antenna distance calculated to be ideal is that the signal reaching the furthest antenna also must pass back through the cable back to the detector. In a proper system this would need to be accurately accounted for, but in this prototype the only goal is to see if there is some correlation, so halving the distance should be sufficient.

(28)

Using the same script as in the previous chapter, incorporating phase detec- tor voltage output as well, will provide data to see if there is correlation between orientation and PD-output.

Figure 5.7 shows an image of the ’drone’. The phase detector is beneath the tape on the left side and can be found localizing the blue led light. The antennas are at each end of the ’drone’, the Arduino, Accelerometer and Magnetometer is on the proto board in the middle. An external power supply is required for the phase detector at this point. A simple schematic of this setup is shown in Appendix 8.1

Figure 5.7: Prototype ’drone’, antennas can be seen on the left and right, other sensors in the center.

Figure 5.8 shows a result of the comparison test running on all three sensors, after post-processing. The goal of this experiment was to show correlation between phase detector voltage and gyro orientation, therefore the output of the phase detector where scaled to have the same range as the output of the gyro and the magnetometer(by simply multiplying the output of the detector with the number which will give it the same max and min as the gyro). In addition data from the magnetometer and detector has been shifted to have the same mean as that from the gyroscope. Although this is not the proper method of converting phase detector voltage to orientation, it will provide us with an easy method of seeing correlation.

(29)

Figure 5.8: Result of comparison test, Gyro, Magnetometer and Phase Detector.

Evident from the figure is that the range of the experiment is low, the drone was only rotated about 45 degrees in this test. This was because rotating it further did not provide good results. The cause of this is mainly that a rotation from maximum to minimum phase difference is only 90 degrees(as illustrated in figure 4.4. It is also a likely cause that the input signals to the phase detector where not in any way filtered or amplified. Also the test was done in an in- door environment, and the effect of reflection and interference on the signal was probably very high. Experiments showed that simply waving your hand in the vicinity of the antennas influenced the phase detector, making its output values vary and become irregular. Something that hopefully can be remedied by using filters and a smarter algorithm. The mean deviation is of the detector is as seen much larger than the one from the magnetometer, but with proper filtering and amplification the phase detector output should be less influenced by magnetic fields than the magnetometer.

Even though the experiment had to be severely limited in it’s scope, and even though the signals to the phase detector where open to interference, the test shows a correlation between rotating the drone and phase detector output.

This is promising, and we now have a system is in place which easily can be modified to accommodate more detectors later.

(30)

6 Discussion

This thesis gave me an opportunity to spend a lot of time reading and learning about a subject which I did not know much about before I began. As it proba- bly is with all theses, first now I feel I know enough about the subject to do it

’properly’, and if I did it again many things would have been done differently.

I would have been able to progress further in the project, but as it is, some things have been left for later. There are two further points which I mainly would have liked to have completed, which is to implement a proper analog circuit to filter and amplify antenna signals, as well as run a machine learn- ing algorithm on data from two detectors in reference to the gyroscope. From working with the data, I feel that it should be possible to make the complete orientation determination-method using this approach, even though I have not been able to prove this in this thesis. It might turn out to not be as accurate as the magnetometer, but it would still provide an alternative.

Looking back at the results and the project goals, all goals where completed to a degree. Mainly the prototype was created, and some correlation between orientation and phase detector output was proved. Considering all error sources, the indoor environment, the lack of analog filtering/amplification of the anten- nas, and the difficulty of reading/transmitting many sets of data via serial at once, this seems promising. A better experiment where some or all of these are eliminated will probably give a much better result.

Many tools where also developed, the prototype, the simulation environment, the Labview signal generator, the code for running the Arduino and its Matlab counterpart. I have tried to document these as well as I can, so hopefully I, or someone else will consider to continue the project at some point. There is still a lot of work to be done, the prototype should get its filter, the simulation environment should be in 3D, and further test could have been done on the Labview program(i.e inducing noise and seeing the detector response). The Arduino code could probably be optimized a lot, the method for retrieving gyroscope data was directly copied and modified quickly to get the necessary readings, which means some of the code might be unnecessary, some might interfere with other functions.

Also, considering the attitude algorithm, a note on chapter 3.2.2, in which I explained the method of determining attitude from phase difference proposed in [3]. Working with the data, I have since come to the conclusion that regressing a function using either machine learning or some other method would probably be the best approach instead. I have been able to map the correlation manually simply using matlab, and an automated algorithm should be able to do this even better.

(31)

7 Conclusion

As a conclusion, a correlation between attitude and phase detector output in a limited test has been proved. A full attitude-determination system based on phase detector(s) is not proven possible, but it seems likely that one can be made due to the promising correlation. Whether it will have better accuracy than a magnetometer based system remains to be seen, but tests and experiments to determine this -once filtering is in place- has been developed. Several issues has been overcome during the course of this project, and hopefully someone can use the tools and experience made in this thesis to continue the work at some point.

As for the validity of the results, the data was retrieved over a length of time, and the chance that the correlation is a fluke over so many samples seem very low. The processing of data was done with the purpose of showing a visual correlation in mind, and as such the data values where modified. However, the same operations where performed on all the data, merely a scaling and mean- shifting process, so the integrity of the result was kept.

In my opinion, the priority for further work should first be an analog filter and amplification circuit, the same experiments with this in place would imme- diately show if further work is worthwhile. Assuming it is, an implementation of three antennas and two phase detectors will provide enough data for imple- menting a suitable machine learning algorithm to regress the output of these into attitude information.

(32)

8 Appendix

8.1 References

[1] D. Gebre-Egziabhe, R. C. Hayward, and J.D. Powell. Design of Multi- sensor Attitude Determination Systems. IEEE Transactions on Aerospace and Electronic Systems, 40(2):1–2, 2004. URL http://ieeexplore.ieee.

org/xpl/articleDetails.jsp?arnumber=1310010&tag=1. Retrieved at 01.06.2016.

[2] Emil Fresk and George Nikolakopoulos. Full Quaternion Based Attitude Control for a Quadrotor . Control Conference (ECC), 2013 European, pages 1–2, 2013. URL http://ieeexplore.ieee.org/stamp/stamp.jsp?

arnumber=6669617. Retrieved at 01.06.2016.

[3] Danilo Roascio, Leonardo M. Reyneri, Claudio Sansoe, and Mau- rizio Bruno. Small Satellite Attitude Determination With RF Carrier Phase Measurement. pages 1–3, 2006. URL https:

//www.researchgate.net/publication/268302908_SMALL_SATELLITE_

ATTITUDE_DETERMINATION_WITH_RF_CARRIER_PHASE_MEASUREMENT. Re- trieved at 01.06.2016.

[4] Jason T. Isaacs, Francois Quitin, Luis R. Garcia Carrillo, Upamanyu Madhow, and Joao P. Hespana. Quadrotor Control for RF Source Lo- calization and Tracking. Conference: 2014 International Conference on Unmanned Aircraft Systems (ICUAS), At Orlando, FL, pages 5–8, 2014. URL http://www.researchgate.net/publication/270453843_

Quadrotor_Control_for_RF_Source_Localization_and_Tracking. Re- trieved at 01.06.2016.

[5] Dcm tutorial, an introduction to orientation kinematics, 2011. URL http:

//www.starlino.com/dcm_tutorial.html. Retrieved at 01.06.2016.

[6] Arduino 2016. Arduino Documentation, 2016. URL https://www.

arduino.cc/en/Main/ArduinoBoardUno#documentation. Retrieved at 01.06.2016.

[7] Honeywell International Inc 2011. Magnetometer Documentation, 2016. URL http://www51.honeywell.com/aero/common/documents/

myaerospacecatalog-documents/Defense_Brochures-documents/

HMC5983_3_Axis_Compass_IC.pdf. Retrieved at 01.06.2016.

[8] InvenSense Inc. Accelerometer Documentation, 2016. URL https://www.cdiweb.com/datasheets/invensense/MPU-6050_

DataSheet_V3%204.pdf. Retrieved at 01.06.2016.

[9] Analog Devices. Phase Detector Documentation, 2016. URL http://www.analog.com/media/en/technical-documentation/

data-sheets/AD8302.pdf. Retrieved at 01.06.2016.

(33)

[10] David Cuartielles. Proof of concept of an Arduino library for Honey- well’s HMC5983 magnetic sensor., 2014. URL https://github.com/

arduinoverkstad/HMC5983. Retrieved at 01.06.2016.

[11] Jeff Rowberg. Demonstration Arduino sketch for MPU6050 class using DMP (MotionApps v2.0)., 2012. URL https://github.com/jrowberg/

i2cdevlib. Retrieved at 01.06.2016.

[12] The European Table of Frequency Allocation and Applications. pages 89–

91, 2015. URL http://www.erodocdb.dk/docs/doc98/official/pdf/

ERCRep025.pdf. Retrieved at 01.06.2016.

[13] National Instruments. Multiple channel analog output with dynamically updated waveform attributes, 2011. URL https://decibel.ni.com/

content/docs/DOC-10821. Retrieved at 01.06.2016.

(34)

8.2 Data Acquisition Schematic

Figure 8.1: Schematic of Microcontroller and Sensors.

8.3 Matlab Source Code

(35)
(36)
(37)
(38)

8.4 Arduino Source Code

(39)
(40)
(41)
(42)
(43)
(44)

References

Related documents

In this thesis we investigated the Internet and social media usage for the truck drivers and owners in Bulgaria, Romania, Turkey and Ukraine, with a special focus on

The EU exports of waste abroad have negative environmental and public health consequences in the countries of destination, while resources for the circular economy.. domestically

Thirdly, two companies were present: Vattenfall (at the time the company used the name ‘Nuon’) and Alliander. Vattenfall is the owner of the heat network that was already in place

46 Konkreta exempel skulle kunna vara främjandeinsatser för affärsänglar/affärsängelnätverk, skapa arenor där aktörer från utbuds- och efterfrågesidan kan mötas eller

The increasing availability of data and attention to services has increased the understanding of the contribution of services to innovation and productivity in

Av tabellen framgår att det behövs utförlig information om de projekt som genomförs vid instituten. Då Tillväxtanalys ska föreslå en metod som kan visa hur institutens verksamhet

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar

Den förbättrade tillgängligheten berör framför allt boende i områden med en mycket hög eller hög tillgänglighet till tätorter, men även antalet personer med längre än