drone ight with arti cial intelligence...of the drone. if the objective point is too far away from...

14
Drone flight with Artificial Intelligence Ana Adell Lamora Miguel Esp´ ıldora Sebastiano Chipoco aster en Ingenier´ ıa Matem´ atica Universidad Complutense de Madrid Junio 2018

Upload: others

Post on 22-Jan-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

Drone flight with Artificial

Intelligence

Ana Adell Lamora

Miguel Espıldora

Sebastiano Chipoco

Master en Ingenierıa Matematica

Universidad Complutense de Madrid

Junio 2018

Page 2: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

Contents

1 Abstract 3

2 Mathematical model of quadcopter 3

2.1 Euler-Lagrange equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Simulation 6

4 Inverse problem 7

4.1 Bezier curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

4.2 PID Controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

5 Neural Networks 10

5.1 Application of neural networks to drone flighting . . . . . . . . . . . . . . . . . . . 11

6 Results 12

6.1 Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

7 Future work 13

2

Page 3: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

1 Abstract

Our goal with this report is to show our study during the XII Modelling Week of the drone flightingwith Artificial Intelligence. We will limit our study to a particular type of drone called quadcopter.

We will first study the physics behind the flight of a drone modelling it as a rigid body withfour rotors. Then we will show how that model can be implemented on Simulink.

Once the model is implemented, the inverse problem will be studied, and last but not least, wewill show our approach to the neural networks used to fligth the drone.

2 Mathematical model of quadcopter

Before explaining the physical equations that govern the movement of a quadcopter, we must keepin mind how is its structure:

In the image, f1, . . . , f4 are the forces created by the four rotors, w1, . . . , w4 are the angularvelocities and τM1

, . . . , τM4are the torques.

In order to study the mathematical model, we will consider two reference frames:

- Inertial Frame: fixed to the ground.

- Body Frame: fixed to the center of mass of the quadcopter.

and we will have to find the six quantities needed to fix the state of the system: three coordinatesfor the position of the center of mass and three Euler angles.

Let’s consider the following vectors:

ξ =

xyz

, η =

φθψ

, q =

[ξη

]

where ξ corresponds to the absolute linear position of the quadcopter, defined in the inertial framex, y, z-axes and η corresponds to the Euler angles, where:

3

Page 4: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

• φ determines the rotation around the x-axis.

• θ: determines the rotation of the quadcopter around the y-axis.

• ψ determines the rotation around the z-axis.

The origin of the body frame is the center of mass of the quadcopter. Let’s consider one morevector that determine the angular velocities:

ν =

pqr

The rotation matrix from the body frame to the inertial frame is R and RT is the rotation matrixfrom the inertial frame to the body frame. R is given by:

R =

cosψcosθ cosψsenθsenφ− senψcosφ cosψsenθcosφ+ senψsenφsenψcosθ senψsenθsenφ+ cosψcosφ senψsenθcosφ− cosψsenφ−senθ cosθsenφ cosθcosφ

The transformation matrix for angular velocities from the inertial frame to the body frame is

Wη and from the body frame to the inertial frame is W−1η .

Wη is given by:

Wη =

1 0 −senθ0 cosφ cosθsenφ0 −senφ cosθcosφ

and we have the relation: ν = Wη η.

The quadcopter is assumed to have symmetric structure with the four arms aligned with thebody x and y-axes. Thus, the inertia matrix is a diagonal matrix I in which Ixx = Iyy and I isgiven by:

I =

Ixx 0 00 Iyy 00 0 Izz

On the other hand, the angular velocity of rotor i creates force in the direction of the rotor

axis, so we have the relation:fi = kw2

i

and the angular velocity and acceleration of the rotor also create torque around the rotor axis:

τMi = bw2i + IM wi

where k is the lift constant, b is the drag constant and IM is the inertia moment of the rotor.

Finally, if we consider the combined forces of the rotors, we have a thrust in the direction ofthe body z-axis, given by:

T =

4∑i=1

fi = k

4∑i=1

w2i , TB =

00T

4

Page 5: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

Torque τB consists of the torques τφ, τθ and τpsi in the direction of the corresponding body frameangles:

τB =

τφτθτψ

=

lk(−w22 + w2

4)lk(−w2

1 + w23)

τ2 + τ4 − τ3 − τ1

in which l is the distance between the rotor and the center of mass of the quadcopter.

Thus, the rotation around the x-axis is acquired by decreasing the 2nd rotor velocity andincreasing the 4th rotor velocity. Similarly, the rotation around the y-axis is acquired by decreasingthe 1st rotor velocity and increasing the 3th rotor velocity. The rotation around the z-axis isacquired by increasing the the angular velocities of two opposite rotors and decreasing the velocitiesof the other two.

2.1 Euler-Lagrange equations

The Lagrangian L is given by:

L(q, q) =m

2ξT ξ +

1

2νT Iν −mgz

where the first term corresponds to the translational energy, the second term to the rotationalenergy and the third term to the potential energy.

Applying the Euler-Lagrange Equations with external forces we have:

d

dt

(∂L

∂ξ

)− ∂L

∂ξ= RTB −Aξ

d

dt

(∂L

∂η

)− ∂L

∂η= τB

where R, TB and τB where defined before and Aξ corresponds to the friction force.

Finally, after some computation, we obtain the desired equations:

• Corresponding to the Euler angles:

η = J−1(τB − C(η, η)η) (1)

where C(η, η) is the Coriolis term and J is the Jacobian matrix, given by the expression:

J = WTη IWη

• Corresponding to the center of mass:

ξ =

xyz

= −g

001

+T

m

cosψsenθcosφ+ senψsenφsenψsenθcosφ− cosψsenφ

cosθcosφ

− 1

m

Ax 0 00 Ay 00 0 Az

xyz

(2)

where Ax, Ay and Az are the drag force coefficients for velocities in the corresponding direc-tions of the inertial frame.

5

Page 6: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

3 Simulation

Once we have studied the mathematical model, we are going to study the motion of the quadcopter.This process is known as the Direct Problem: given the angular velocity and the six quantitiesthat define the state of the drone, we want to see how it flies and where it goes.

In order to do that, we will use the graphical programming environment of Matlab calledSimulink. All the parameter values that we need are shown in the next table:

In our case, we will have the following inputs:

q =

[ξη

],

dq

dtand w

and the outputs will be ξ and η satisfying the equations (1) and (2). Therefore, the simulinkproject will have the following form:

We will test the mathematical model with the parameters considered above and some givenangular velocities of ω2

i = 390000 rad2/s2 for i = 1, 2, 3, 4. The quadcopter is initially in a stablestate in which the values of all positions and angles are zero, the body frame of the quadcopter iscongruent with the inertial frame. The total thrust is equal to the hover thrust, the thrust equalto gravity.

With the angular velocities considered, the quadcopter starts flying up by the z-axis, keeping

6

Page 7: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

x and y constant and equal to zero, and it starts spinning only around the z-axis, as we can see inthe next graphic:

Now we will do a simulation with different angular velocities values. In this case we will useω21 = ω2

3 = 390000 and ω22 = 390100 and ω2

4 = 389900. So we expect a rotation around the x-axis.The figure below will show us the six coordinates of the position of the drone:

Looking at the third coordinate, which is z, we can see that the drone crashes because z takesnegatives values after t = 6 approximately. Also the drone rotates around the x-axis as expected.

4 Inverse problem

Once we have studied the direct problem, we are going to focus on the Inverse Problem: weneed to calculate the angular velocity that the quadcopter needs to get to a specific point. In thispart, the so called Bezier curves will play an importante role, as we will see later in this report:

7

Page 8: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

4.1 Bezier curve

The Bezier curve is defined by a set of points b0, . . . , bn ∈ R3, called the control points, where n isthe degree of the curve. This points satisfy:

• The first and the last control points always correspond to the first point of the curve and thelast point of the curve, respectively.

• The intermediate points generally do not belong to the curve, but the curve always lies inthe convex hull of these points.

More specifically, the Bezier curve is a polynomial curve written in a Bernstein’s basis:

γ(t) =

n∑i=0

biBi,n(t) t ∈ [0, 1]

where bi are the control points and Bi,n are the Bernstein polynomials, given by:

Bi,n =

(n

i

)ti(1− t)n−1, i = 0, . . . , n

In our case, we will consider n = 2, the quadratic Bezier curve, which expression is given by:

γ(t) = (1− t)2b0 + 2(1− t)2tb1 + t2b2, 0 ≤ t ≤ 1

We will choose b0 as the origin, so the equation will be:

γ(t) = 2(1− t)2tb1 + t2b2, 0 ≤ t ≤ 1

The aim will be to consider some points of the curve and to try the quadcopter to follow thatpoints:

It is important to note that b1 is always the intersection of the two tangent lines to the curvethat pass through b0 and b2. This intersection exists because th quadratic Bezier curve is containedin a plane.

4.2 PID Controller

A Proportional-Integral-Derivative controller (PID) is a control loop feedbak mechanism used inapplications requiring continously modulated control. This is the method that we will use to solvethe inverse problem of the drone flighting.

8

Page 9: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

PID uses an error value:e(t) = xd(t)− x(t) (3)

In this equation, x(t) is the point where the drone is, and xd is the objective point where the droneaims to fly.

The control function that the PID to solve the inverse problem is:

uPID = KP e(t) +KI

∫ T

0

e(τ)dτ +KDde(t)

dt(4)

The aim is that with the control function uPID the error value will go to zero asimptoticallyas t goes to infinity:

limt→∞

|e(t)| = 0 (5)

This kind of controller is useful if the point that the drone needs to fly to is close to the positionof the drone. If the objective point is too far away from the drone, the PID will converge slowly,that is one of the reasons why we will use Bezier curves and neural networks.

Schematically, our implementation of the PID in the Simulink project can be seen in thefollowing picture:

9

Page 10: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

5 Neural Networks

A neural network is a computational model inspired in the natural neurons. Natural neuronsreceive signals trhough synapses located on de dendrites or membrane of the neuron. When thesignal received surpass a certain threshold, the neuron is activated and emits a signal trhough theaxon. This signal might be sent to another synapse, and might activate other neurons. Here wecan see an schematic picture of a real neuron.

An artificial neuron consist of inputs, that have the role of synapses in a real neuron. Thisinputs are multiplied by weights, and computed by a mathematical function which determines theactivation of the neuron. Usually a sigmoidal activation function is used.

Here the ωj are the weights to the input values xj and b is the bias, that is a numerical valueassociated with the neuron. The neuron computes f(b+

∑nj ωjxj) and provides an output.

A neural network is a set of interconnected neurons. We can see an example in the followingpicture:

The input data go into the input layer and then go through the hidden layers until an actualoutput is obtained via the output layer.

10

Page 11: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

In our image there is only one hidden layer, but there could be more of that kind of layers.

Neural networks will be used because with them we can approximate the value of a function.And due to the Universal approximation Theorem, the set of functions represented by a neuralnetwork is dense in L2(

∏ni [ai, bi];

∏mj [cj , dj ]) where n is the number of inputs and m is the number

of outputs.

5.1 Application of neural networks to drone flighting

Our objective is, given a target point qT , to calculate m points p1, .., pm that belong to the Beziercurve which starts at (0, 0, 0) and ends at qT . In our case m = 3.

We will train the neural network with a data set of randomly generated qT on a sphere ofradius r (in our case r=3, but any other radius could be chosen). The structure of the training setis the following:

Input OutputqT,1 = (q1T,1, q

2T,1, q

3T,1) p1 = (p11, p

21, p

31), ..., pm = (p1m, p

2m, p

3m)

qT,2 = (q1T,2, q2T,2, q

3T,2) p1 = (p11, p

21, p

31), ..., pm = (p1m, p

2m, p

3m)

... ...qT,N = (q1T,N , q

2T,N , q

3T,N ) p1 = (p11, p

21, p

31), ..., pm = (p1m, p

2m, p

3m)

We have used the Neural Network Toolbox with Matlab, that provides algorithms and apps tocreate, train, visualize and simulate neural networks. Our network has three neurons on the inputlayer, nine on the output layer and a hidden layer with six neurons. We have used an heuristicrule for the number of neurons in the hidden layer that recommends to put the following number:

N =inputs+ outputs

2(6)

Although there is no mathematical proof that is a good number, empirically has been proved thatis a good number to start with.

Once the neural network is trained, if we want the drone to flight to a certain point, we introducethe point to the neural network and we obtain intermediate points. Then the inverse problem issolved with the PID controller for each point sequentially until the drone flies to his objectivepoint.

This is of course just a first step to actually fly a drone using Artificial Intelligence. The ideawould be that the drone needs a method to obtain an image and then identify the obstacles. Once

11

Page 12: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

the obstacles are identified a set of points will be generated with a neural network to obtain a paththat avoid the obstacles. That’s why Bezier curves are useful, because a Bezier curve always liesinside the convex hull of the generating points.

Here we have done the training with just one point, it is the first step. With more time wecould have done it with more points and tested if it worked. That‘s a possible future task.

6 Results

To sum up, given a target point qT we will obtain 3 intermediate points p1, p2 and p3 that thedrone will consider as its current target points. Once the drone is reaching the first target pointp1, the current target point will be changed to the next one and so on, so that finally it can get toqT . The drone will fly from point to point by the use of the PID controller.

In this first example given the target point qT = (1.3621, 2.4302, 1.1132) we will see the distancefrom the center of mass to the current target point.

The three intermediate points calculated given qT are p1 = (0.0851, 0.1519, 0.4870), p2 =(0.3405, 0.6075, 0.8349) and p2 = (0.7662, 1.3670, 1.0436).

We can see in the figure above that there are three vertical leaps which indicate that once thedrone is approaching to its target, the target is suddenly changed to the next one, so the distancebetween the drone and the current target is now larger.

6.1 Linear Equations

The equations (1) and (2) can be linearized. We will approximate the sine and cosine functionsusing their Taylor series: for u ∈ R, sin(u) ∼ u and cos(u) ∼ 1.

We will try now to solve the inverse problem using the linearized direct problem. Given thesame target point that the one in the previous case, we will see in the next figure the variation ofthe norm distance:

12

Page 13: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

Considering the scale of the ordinates, we can see in this plot three target changes and that thedron doesn’t finally approach to the final target because the distance to the final target increasessignificantly.

When we change the targets the dron is asked to perform some suddenly turns that createssome unstabilites to its flight that the linearized problem finally can’t solve.

7 Future work

A way to continue with this work could be using Bezier curves of higher degree n. In order to doso, we would need the curve’s control points b1, ...bn (where the target point is bn) that would begenerated randomly and then use all these points in a machine method learning, such as the beforementioned neural networks.

We could use these higher degree Bezier curves that describe a more complex paths than theones used in this work, and we could use them to dodge some obstacles in the drone’s way to thetarget.

Also we could use some other machine learning method and compare and compare the resultswith our work done with neural networks.

13

Page 14: Drone ight with Arti cial Intelligence...of the drone. If the objective point is too far away from the drone, the PID will converge slowly, that is one of the reasons why we will use

References

[1] Luukkonen, T. (2011). Modelling and control of quadcopter. Independent research project inapplied mathematics, Espoo, 22.

[2] Vigoriti, F. and Siniscalco A. Tesina di Sistemi di Controllo Multivariabile. Stabilizzazioneassetto Quadricottero.

14