Abstract
This paper deals with the modelling, simulation-based controller design and path planning of a four rotor helicopter known as a quadrotor. All the drags, aerodynamic, coriolis and gyroscopic effect are neglected. A Newton-Euler formulation is used to derive the mathematical model. A smart self-tuning fuzzy PID controller based on an EKF algorithm is proposed for the attitude and position control of the quadrotor. The PID gains are tuned using a self-tuning fuzzy algorithm. The self-tuning of fuzzy parameters is achieved based on an EKF algorithm. A smart selection technique and exclusive tuning of active fuzzy parameters is proposed to reduce the computational time. Dijkstra's algorithm is used for path planning in a closed and known environment filled with obstacles and/or boundaries. The Dijkstra algorithm helps avoid obstacle and find the shortest route from a given initial position to the final position.
1. Introduction
A quadrotor is a cross-shaped aerial vehicle that is capable of vertical take-off and landing. It has four motors, each mounted per corner equidistant from the centre. The synchronized rotational speed (ω) of all the motors is key to the control of the quadrotor. Vertical motion results from the simultaneous increase or decrease of the rotational speeds of all the rotors. The motion along any direction on the lateral axis is obtained by decreasing the rotational speed of the rotors along the desired direction of motion, and increasing the rotational speed of the rotors opposite to the desired direction of motion. Moment produced by rotation of rotors is used to initiate yaw. For instance, clockwise yaw is initiated by simultaneously increasing the rotation speed of the rotors creating a clockwise moment, and decreasing the rotation speed of the rotors creating counterclockwise moment. The motion of the quadrotor is described schematically in figure 1. Control of a quadrotor is a challenging task for the following reasons: high manoeuvrability, high non-linearity, intensely coupled multivariable and under-actuated condition with six degrees of freedom and only four actuators.

Basic motion of a quadrotor.
A quadrotor is not a new concept. The first successful hovering of a quadrotor was achieved in October 1920 by Dr. George de Bothezat and Ivan Jerome [1]. Researchers have designed and implemented numerous quadrotor controllers such as PID/PD controllers, fuzzy controllers, sliding mode controllers, neuro-fuzzy controllers and vision-based controllers. M. Santos et al. [2] proposed an intelligent system based on fuzzy logic to control a quadrotor. C. Coza et al. [3] used an adaptive fuzzy control algorithm to control a quadrotor in the presence of sinusoidal wind disturbance. The author addressed a robust method to prevent drift in the fuzzy membership centres. Y. A. Younes et al. [4] introduced a backstepping fuzzy logic controller as a new approach to controlling the attitude stabilization of a quadrotor. The backstepping controller parameters were scheduled utilizing fuzzy logic. M. H. Amoozgar et al. [5] proposed an adaptive PID controller for fault-tolerant control of a quadrotor helicopter in the presence of actuator faults. The PID gains were tuned using a fuzzy interface scheme. A. Sharma et al. presented and compared PID and fuzzy PID controllers to stabilize a quadrotor. Other authors [6–8] also addressed the fuzzy PID control algorithm to control a quadrotor.
In this paper, modelling of a quadrotor, a control strategy using a self-tuning fuzzy PID algorithm and path planning using Dijkstra's algorithm are presented. A dynamic model is derived based on the Euler-Newton formulation. All the drags, aerodynamic, Coriolis and gyroscopic effects are neglected. The PID gain scheduling-based control algorithm is proposed for attitude stabilization and position control of the quadrotor. The tuning of PID gains is performed based on the self-tuning fuzzy controller. The tuning of the fuzzy parameters is performed using an EKF algorithm. Smart selection of the active fuzzy parameter followed by exclusive tuning of the active parameter is proposed to reduce the computational time. A path planning algorithm is proposed with two main objectives in mind: obstacle avoidance and shortest route calculation from any given initial position to the final position. Finally, a series of simulation results and conclusions are presented.
2. Mathematical Modelling
The mathematical model of the quadrotor is derived based on the Newton-Euler formulation. Let E = XE, YE, ZE denote an inertial frame and B = XB,YB,ZB denote a body fixed frame. The body frame is related to the inertial frame by a position vector (x, y, z) and three Euler angles, (φ, θ, ψ) representing roll, pitch and yaw respectively. All equations are expressed in the inertial frame. The vehicle is assumed to be rigid and symmetrical. The centre of mass, centre of gravity and origin of body axis are assumed to be coincident. Let cφ represent cos φ, and sφ represent sin φ. Similar notation is used for θ and ψ. The rotation matrix from the body frame to the inertial frame

Coordinate system.
The rotation of each rotor produces a vertical force towards the ZB direction and moment is produced opposite to the direction of rotation. Rotors are paired such that the total moment created is cancelled out. The rotor pair 2-4 produces clockwise moment, while the rotor pair 1-3 creates counterclockwise moment. Experimental observation at low speed showed that these moments are linearly dependent on the produced forces. The equation of motion can be written using force and moment balance as shown in equation 2 [9–11]
where Mi = C × Fi, Fi is the force from individual motors, Mi is the moment produced by rotation of the rotor for i = 1, …,4, C is the constant relating moment to force, m is the total mass of the UAV, g is the acceleration due to gravity, Ki is the coefficient of the drag opposing the motion of the quadrotor, for i = 1,2,…, 6. IX, IY, IZ are the moment of inertia of the UAV with respect to XB, YB, ZB axes respectively. As the drags are negligible at low speed, for convenience the drag coefficients are assumed to be zero [9]. Moreover, inputs are defined as:
Substituting equation 3 to equation 2, the simplified form of the quadrotor dynamics is obtained as presented in equation 4.
Likewise, the motor is modelled considering a small motor with very low inductance and no gearbox. The motor dynamics is given by equation 5 [10, 11]
where J is the propeller inertia, ω is the rotational speed, KE is the back EMF constant, KM is the torque constant, R is the internal resistance of the motor, d is the aerodynamic drag factor and V is the motor input voltage.
3. Control and Path Planning Algorithm
3.1. Self-Tuning Fuzzy PID
A PID (Proportional-Integral-Derivative) controller is a well-known feedback controller most widely used in various types of plants and industries utilizing robotics all over the world. A PID controller is simple and easy to design which often results in satisfactory performance. However, a PID controller has various limitations: the fixed gains of a PID controller limits the performance over a wider range of operating points. As a PID controller is based on the linear model, non-linearity in the system brings uncertainty and degraded performance. It lacks learning ability and the adaptability necessary to overcome nonlinearities and uncertainties. So, gain scheduling of a PID controller based on self-tuning of fuzzy parameters [12, 13] is proposed. The proposed algorithm can be described as presented in figure 3. The quadrotor is controlled using a PID algorithm. The proportional, derivative and integral gains of the PID controller are tuned using fuzzy logic. The fuzzy parameters of the fuzzy algorithm are further tuned using an EKF algorithm.
PID output is defined by,

Control algorithm structure.
where kp, ki, kd are PID gains, e (t) is error from reference to response signal at time t. The PID gains ka are tuned across range Δka based on the input variables error e (t) and its first derivative ė (t) as given by equation 7
where ka_0 is the base value of the gain. Usig ∈ [0,1] is the normalized output from the sigmoid function defined as:
where Uf is the output from fuzzy logic. Inputs to the fuzzy logic are normalized on range [-1 1]. For each input variables, five equal-sized isosceles triangular membership functions are considered NB, NS, ZE, PS, PB representing negative big, negative small, zero, positive small and positive big respectively. The membership function for each output is considered to be five singleton values. Details of membership functions are represented in figure 4.

a) Input membership functions b) Output singleton values.
Let, i and j represent the membership function index for the first and second input variables. Three vertices are used to define each of the triangular membership functions. (a1/2,i/j, 1) be the top vertices, (a1/2,i/j − b−1/2,i/j, 0) and (a1/2,i/j + b+1/2,i/j, 0) represent the base vertices. Each crisp input is fuzzified according to equation 9 to obtain the membership grade value f1/2,i/j for ith or jth membership function.
where Offseti/j = x1/2 − a1/2,i/j is defined as the distance vector from the tip vortex of the triangular membership function to the corresponding input x1 or x2 being error and error rate respectively.
Based on experience, 25 fuzzy rules are defined for all possible combinations of the inputs. These defined rules are used for initial calculation and are later tuned based on the system response. A minimum function is used to define the connectives. The output membership grade is obtained by equation 10.
Defuzzification to the crisp value is done using the centre of gravity method for singletons (COGS).
where wi,j is a weighted singleton value from rule table. The fuzzy rules and membership functions are tuned based on the EKF algorithm. The states in the EKF estimation are as presented in equation 12
Equation 13 describes the system model and the measurement model.
where xk represents the fuzzy states at sampling time k, and zk. is the measurement as obtained from the sensors. wk and vk are the process and measurement noise which are both assumed to be uncorrelated zero mean Gaussian noises with covariance Qk. and Rk respectively. Function f is the state transition model used to compute the predicted state from the current state estimate h represents the measurement model with respect to the estimated states which is as presented in equation 14.
where QQd is the quotient term to the inputs U1, U2, U3 and U4 as in the quadrotor dynamics equation 2. Similarly the term AQd is the additive term in the equation 2. For the extended Kalman filter, initial values of the states are supposed to be known precisely thus setting the initial error covariance (P−) to zero. The measurement model is linearized using the Jacobian as expressed in equation 15.
The term
where,
For
Similarly, the term
where the terms
And the term
where,
The Kalman Gain is computed as:
Measurement updates

Flow diagram: EKF-Fuzzy-PID algorithm.
Error covariance
Project Ahead
3.2. Smart Selection
Each of the p, i or d tuners has two inputs, five membership functions for each input and 25 sets of rules. Thus, in total 55 fuzzy parameters (i.e., 10 a1/2,i/j, 10 b+1/2,i/j, 10 b−1/2,i/j and 25 wi/j) are to be updated on every sampling time for a single tuner. So, in order to control six states using the PID controller, 990 fuzzy parameters are to be tuned in each sampling time. This accounts for excessive computational time and is a major problem when simulating and implementing a self-tuning fuzzy PID controller in a real system. However, only few of the parameters have an impact on the fuzzy output value - most of the parameters fall on the passive zone of the fuzzy and have no effect on the output from the fuzzy. Thus, smart selection and updating of the active fuzzy parameters is proposed. The overall smart selection and update process is as presented in figure 6.

Smart selection of active parameters and tuning.
The fuzzy parameter pool contains all the fuzzy parameter values. The active fuzzy parameters are picked from the fuzzy parameter pool, tuned using the EKF algorithm and then the tuned values are updated back to the pool. Initially, based on the crisp value of the inputs, the active membership function index is determined (i.e., i=1…5, j=1…5, b+=1…5 and b−=1…5). Cross-referencing the index value in the “Active Membership Function Index” block and “Fuzzy Parameter Pool” block, the active fuzzy parameters are picked. Thus, the picked active parameters are declared as states for the EKF update and thus proceeded to the tuning based on the EKF algorithm. Likewise, the active membership function index value is used to smartly pick the elements of the error covariance matrix from the “Error Covariance pool” block. Now the EKF update is performed as presented in equations 27, 28, 29 and 30.
The estimated states are then checked to see if they are in the logical range by applying the range constrains. Four different constraints are used to define the range constraints. Firstly, the membership functions are bounded within range of [-1 1]. Secondly, the order of the membership functions are not compromised. Thirdly, two and only two membership functions are overlapped in the region between the first and the last membership function. Finally, the region in the range [-1 1] and not in between the first and last membership function should still be defined. Applying these constrains helps maintain the functional integrity of the defined fuzzy logic and avoids the possibility of the occurrence of undefined zones in the input region.
Thus, estimated states and error covariance matrix are updated back to their corresponding pools and are made available to be picked for tuning in the next sampling time. The smart selection process reduced the fuzzy parameters to be tuned from 55 to only 12. So, in controlling the quadrotor position and orientation, the total fuzzy parameters to be tuned are reduced from 990 to less than 217. The smart selection and exclusive update of the active fuzzy parameters reduced the computational time significantly.
3.3. Path Planning and Obstacle Avoidance
The goal of the path planning algorithm here is to identify the shortest route from the quadrotor's initial position to any given final position while avoiding the obstacles. Dijkstra's algorithm [14] is adopted to perform the path planning. It solves the single-source shortest path problem in weighted graphs. The algorithm starts from a given initial node, assigns it as current node and starts the searches for the minimum weight node from the current node. After iteration completion, the current node is added to the explored node list. Again, assigning the node with the lowest total weight as the current node, it starts searching for the next minimum weight node for the next iteration. By minimizing the weighted value, the total distance of the route is minimized, thus the shortest route avoiding the obstacles is obtained.
Let current node (i.e., node 8) be denoted by R(xR,yR) and the current target node (i.e., node 5) be denoted by T(xT,yT). The line pointing from the current node (8) towards the current target node (5), generalized as node T(target) can be represented by the line vector.
where

Dijkstra's algorithm: visibility check.
where
Dissecting the above equation results in two linear simultaneous equations
Solving 34 to express q in terms of p:
Substituting 35 into 34 and rearranging we can obtain the p.
Substituting equation 36 into equation 35 will allow for q to be calculated. In the case of a vertical wall, i.e., xE − xA = 0 the first part of equation 34 should be used. Similarly in the case of a horizontal wall, i.e., yE − yA = 0, the second part of equation 35 should be used. In the case of non-vertical and non-horizontal walls, either the first part or the second part of equation 35 can be used. The boundary restriction from the quadrotor to the obstacle/wall is also taken into account. The restriction includes the quadrotor dimensional restriction that is from the centre of mass of the quadrotor to its arm end and additional restriction to allow the quadrotor enough space to fly safely in the case of some path deviation. Using a combination of the proposed controller scheme and Dijkstra's algorithm, the quadrotor can find its own optimal path from the given initial position to the final position in an environment with obstacles.
4. Simulation
The simulation of the proposed dynamics, control algorithm and path planning algorithm is performed using the Matlab/Simulink environment. The simulation block of the quadrotor system is as presented in figure 8.

Matlab/Simulink model of the system.
The task block contains the task or the command for the quadrotor to follow. The task is provided to the Dijkstra algorithm block to compute the optimal path. The optimal path is then provided to the controller block via the command feeder. A total of six controllers are used to fully control the quadrotor. Four of them, namely Z controller, Phi controller, Theta controller and Psi controller, together form the inner loop control and are the basic controllers used to stabilize the quadrotor. It steadies the attitude of the quadrotor while stabilizing the height [11, 15]. The remaining two controllers, the X controller and the Y controller, form the outer loop control. The outer loop control helps to navigate to desired position by providing the desired pitch and desired roll angle for the inner loop control to track down. The wind model available in Simulink library is used to model the wind blowing with a velocity of 1m/s opposite to the XE axis. The uncertainty on the other hand is imposed on the rotational speed of the motor as described in equation 37
5. Result
The simulation results of the quadrotor with integrated motor dynamics controlled using a self-tuning fuzzy PID controller, show it to be capable of performing path planning as presented in the figures and tables to follow. Figure 9, 10, 11 and 12 shows the waypoint following performance of the PID controller and the EKF fuzzy PID controller. The initial oscillation on the theta response in figure 11 is the result of the imposed wind model acting opposite to the x axis. Table 1 shows a comparison of performance between the two controllers, where the term “total error” is defined by the sum of the absolute positional error during the whole waypoint following mission. Figure 13 to figure 17 are used to show the performance of the EKF fuzzy PID controller while following the optimal path as calculated from Dijkstra's algorithm. The Matlab simulation (Figure 13), Virtual reality simulation (Figure 14), PID parameter tuning (Figure 15 and figure 16) and fuzzy parameter tuning (Figure 17) are displayed.

Waypoint following PID.

Waypoint following EKF fuzzy PID.

Attitude plot: Waypoint Following: EKF Fuzzy PID.

Voltage plot (Controlled Input): Waypoint Following: EKF Fuzzy PID.

Path Planning EKF Fuzzy PID.

Virtual reality simulation using Matlab/Simulink.

Tuning of PID gains: Y controller: Path Planning.

Tuning of PID gains: Phi Controller: Path Planning.

Fuzzy membership function tuning (at t=85 sec): Path Planning.
Performance comparison table: waypoint following.
6. Conclusion
The quadrotor was successfully controlled using PID gain scheduling based on an EKF algorithm. The stability control, waypoint following and path planning were successfully simulated. The self-tuning fuzzy PID controller showed good resistance to the induced disturbance and the uncertainty. It adapted to the wind and disturbance quickly and provided significantly better performance as compared to a simple PID controller. The obstacle avoidance and waypoint following performance was enhanced using the self-tuning fuzzy PID controller.
Footnotes
7. Acknowledgment
This work was supported by the 2013 Research Fund of University of Ulsan.
