ANFIS Based Quadrotor Drone Altitude Control Implementation On Raspberry Pi Platform
ANFIS Based Quadrotor Drone Altitude Control Implementation On Raspberry Pi Platform
https://doi.org/10.1007/s10470-018-1159-8(0123456789().,-volV)(0123456789().,-volV)
Abstract
The unmanned aerial vehicles can have complicated dynamics and kinematics that governs the flight of such multirotor
devices. PID type controllers are one of the most popular approaches with Raspberry Pi 3 platform for stability of the flight.
However, in dynamic environment they are limited in performance and response times. The autonomous tuning of the
controller parameters according to the state of the environment with assistance of the adaptive neuro-fuzzy inference
system is a well known approach. This paper provides implementation details and feasibility of such a controller with
Raspberry Pi 3 platform for use in geological wireless sensing environments. The proposed neuro-fuzzy controller is
developed for a Raspberry Pi 3 platform and tested on a physical quadrotor drone and compared to the conventional PID
controller during flight.
123
Analog Integrated Circuits and Signal Processing
2.2 Learning
2.2.1 Back-propagation
0.2
123
Analog Integrated Circuits and Signal Processing
change in the parameter a by Jang [4]. Example of the ANFIS network of 2 inputs
# and 2 membership function per input is given in Fig. 2, and
related input space segmentation by 4 If-Then rules for this
change in the output of the node with a
network is presented on Fig. 3. Generally, it is recom-
# mended to use Sugeno-type inference system, where the
change in the overall output consequent parameters of the fuzzy rules are given as a
# polynomial function:
change in the error if X 2 A and Y 2 B; then Z ¼ f ðX; YÞ
It means that change in some parameter a produces where f ðX; YÞ ¼ pX þ qY þ r
change in the error, so the error can be propagated back in Layer 1 The function of each node of the first layer is to
the network to the node containing this parameter. Based produce the output based on the associated input and MF,
on the derivative error measure at this node, the parameter Eq. 4
a can be adjusted to minimize overall system error.
Back-propagation is core principle of training the pre- Out1;i ¼ lAi ðXÞ; where i is node with X input
ð4Þ
mise (membership function) parameters of the ANFIS Out1;i ¼ lBi ðYÞ; where i is node with Y input
architecture. For detailed explanation of integrating back-
Each membership function l can be given as appropriate
propagation, refer to the [4].
parameterized function, such triangular or trapezoidal.
However, due to the differential nature of the gradient
2.2.2 Least-square estimator
descent, it is recommended to use differentiable alterna-
tives, such as Gaussian, sigmoidal or generalized bell
The gradient descent based on a back-propagation of an
functions. Parameters that describe the shape of those
error is considered to be computationally slow learning
functions are called premise (or antecedent) parameters,
algorithm. However, as it will be presented later, the output
and updated during backpropagation error correction.
of the ANFIS is linearly dependent on the consequent
parameters, so the alternative fast linear learning algorithm Layer 2 The function of nodes in this layer is to calculate
is used for those parameters instead of gradient decent in the product of the all membership functions outputs asso-
order to accelerate the training of the network. This type of ciated with certain one certain rule, Eq. 5. Produced output
the linear training for ANFIS was originally proposed and can be considered as the firing strength or the weight of the
described in details in [4]. rule, associated with this node.
Out2;i ¼ lAi ðXÞ lBi ðYÞ ð5Þ
2.3 ANFIS architecture
Layer 3 The third layer nodes normalize the weight of
Combination of the fuzzy inference systems with learning each rule, Eq. 6
principles of the artificial neural networks resulted in wi
adaptive neuro-fuzzy inference system, originally proposed Out3;i ¼ wi ¼ P ð6Þ
i wi
П N CP
X
П N CP
Σ Out
П N CP
Y
П N CP
123
Analog Integrated Circuits and Signal Processing
X ð10Þ
1
Both types of learning are integrated into the ANFIS
A1 A2 network. Moreover, both learning types provides an
1 opportunity to integrate offline, online and batch learning
methods.
Fig. 3 Segmentation of input space for a network shown in Fig. 2 Fuzzy nature of the ANFIS allows operating both fuzzy
and crisp inputs and outputs with minimal adjustment of
the default network architecture. In addition, the ANFIS
Layer 4 Layer 4 is used for multiplication of normalized
poses as great nonlinear generalization property as machine
rule weight with corresponding consequent parameter f.
learning tool. Moreover, fewer adjustable parameters and
Typically, there is two popular forms of the consequent
applicability of linear learning techniques result in accel-
parameters: based on the first order or zero order Sugeno
erated learning, especially compared to the classical
fuzzy models 7.
ANN [5]. Finally, the If-Then rules can be extracted from
Out4;i ¼ wi fi ; where trained network, which will allow to the possible human
fi ¼ ðpi X þ qi Y þ ri Þ for first order model; or ð7Þ operator to interpret the ANFIS approximated system
fi ¼ ri ; for zero order model model, given the number and complexity of the rules are
not overwhelming for such human operator.
Layer 5 Typically, this layer is consist of single node, that
produces output as a summation of all output signals of the 2.5 ANFIS disadvantages
previous layer, Eq. 8
X The main disadvantage of the default ANFIS architecture is
Out5 ¼ wi fi ð8Þ
i
poor scalability with number of inputs and number of MFs.
For example, using the grid segmentation of input space
will require M N discrete rules to describe the system, where
As it can be seen from Eq. 8, the overall system output M is number of MFs per input and N is number of inputs.
is linearly dependent on the sum of the consequent This issue is also known as the ‘‘curse of dimensionality’’,
parameters of each rule, Eq. 9 so practical application of the ANFIS is limited to the
several discrete inputs. One way of addressing this problem
Out5 ¼ w1 fþ w2 f2 þ þ wn fn
can be to experiment with different segmentation
¼ ðw1 XÞp1 þ ðw1 YÞq1 þ ðw1 Þr1 þ ð9Þ methodologies, however, it will require more complex
þ ðwn XÞpn þ ðwn YÞqn þ ðwn Þrn algorithm to select the number and type of the MFs for
preliminary system description. In addition, there is still
Assuming fixed antecedent parameters, the input array
dependence on the external experts to setup initial ANFIS
and normalized rule weights wi will be constant, so overall
conditions and rules. Finally, the dependence on the com-
output is linearly dependent on consequent parameters
putationally heavy gradient decent to adjust part of the
p1 ; q1 ; r1 ; p2 ; q2 ; r2 ; . . .; pn ; qn ; and rn . Based on this
parameters is still limiting the speed of the adaptation,
assumption, the LSE method is viable option to adapt
especially if the online learning for the highly dynamic
consequent parameters.
123
Analog Integrated Circuits and Signal Processing
system is desired, so some faster alternative should be responsible for the variable thrust generation. Wires which
considered for a complex ANFIS architecture. correspond to three phases of the motors are connected to
the 30A Multirotor ESCs which are mounted on four arms
of the frame. Depending on a variation of connection of
3 ANFIS implementation these wires motors can rotate either clockwise or counter-
clockwise. Motors are connected to ESCs in a way such
ANFIS based flight control framework is computationally that the front left and rear right motors rotate in clockwise
demanding, especially comparing to the default controllers, direction, whereas front right and rear left motors rotate in
such as PID, so the hardware requirements are considerably counterclockwise direction. Each ESC uses its own fast
higher. As a result, the flight control is implemented on a frequency switching system based on MOSFET to control
Raspberry Pi 3 microcomputer. Compact size, low weight, the ratio of power ON/OFF, thus controlling the power
controllable power consumption and adequate computa- supply and consequently the speed of the motor. ESCs are
tional hardware and software make Raspberry Pi 3 a rea- connected to the output pins 1–4 of NAVIO2 in order to
sonable candidate for proposed application. acquire input signals obtained by RC receiver, which is
connected to the PPM/SB pin 0, and processed by rasp-
3.1 Raspberry Pi 3 and Navio2 berry pi. Power to the whole system is supplied by
Lithium–Polymer (LiPo) battery attached to the bottom of
Raspberry Pi is popular platform for implementation the lower plate. The four cells battery supplies 14.8 V and
robotic designs and projects (Fig. 4). Available hardware 5000 mAh with a discharge capacity of maximum 50 C.
allows to easily interface such small computer with wide The block diagram of electrical components of quad-
range of sensor and actuator. In addition, the computational copter provided below in Fig. 5 demonstrates connection
resources and software supports popular programming of microcontrollers and sensors, and how signal processing
languages and environments, such as Python, C/C??, Java is done. Target values of roll, pitch, yaw and thrust are
and many more. Moreover, the Unix based nature of the determined and transmitted by RC to the PWM/S Bus input
operational system allows high level of the software cus- pin of the Navio2 in a form of PPM signal. Further, this
tomization. Popularity of the Raspberry Pi microcomputers signal is calibrated regarding to the actual, measured values
as a compact platform for robotics projects lead to the obtained by sensors integrated to the Navio2. Two sensors,
development of specialized compatible hardware and specifically MPU9250 9DOF IMU and LSM9DS1 9DOF
software, designed to streamline the development process IMU, that contains 3-axis gyroscope, 3-axis accelerometer
of such projects. Navio2 by Emild is a great example of and 3-axis magnetometer are used for finding yaw, pitch
dedicated hardware/software package used for such appli- and roll characteristics of quadcopter. The reason behind
cation. It contains all required sensory hardware required using two sensors of the same functionality is to acquire
for optimal quadrotor drone flight control. Moreover, more accurate data for stability of the quadcopter. The
Navio2 software source files are made openly available by altitude of UAV is measured by built-in MS5611 Barom-
Emild, so there is an opportunity to customize it based on eter with accuracy of 10 cm, which in its turn affect the
the needs of the application. signal responsible for thrust generation in order to ensure
The UAV designed for this project is based on a classic steady ascending/descending. U-blox M8N Glonass/GPS/
x type model of quadrotor. Four brushless motors with Beidou with antenna attachable to the Navio2 is responsi-
fixed propellers are mounted on the ends of arms, and are ble to keep quadcopter within the set course. These mea-
sured and target signal values are collected by raspberry pi
3 and processed to compute the final signals that will be
sent to four ESCs of quadcopter from pins 1 to 4 of Navio
2.
123
Analog Integrated Circuits and Signal Processing
both offline and online. Finally, the comparison with offline manner to give a prediction of the chaotic time
commonly used PID controller should be made in terms of series, based on the number of past samples. In Eq. 11
the accuracy, response time and overall stability. there is a configuration of the inputs that have been used to
Primary way to compare both control techniques is to verify the ANFIS performance on Raspberry Pi.
analyze the stabilization parameters, such as settling time, ½xðt 18Þ; xðt 12Þ; xðt 6Þ; xðtÞ; xðt þ 6Þ ð11Þ
overshoot and amount of oscillation around the settling
point. It can be done by comparing the response to the The results of the offline learned ANFIS network pre-
change of the control signal. diction can be seen on a Fig. 6. It has been simulated for 4
inputs and 2 membership functions per input, resulting in
3.3 Performance of the offline and online 16 total rules with grid partitioning of the input space. It
learning produces RMS error of 0.065.
123
Analog Integrated Circuits and Signal Processing
123
Analog Integrated Circuits and Signal Processing
rate of change and comparing to the difference to the membership functions per each input. It has been trained
desired values, D, the controllers adjust the speed of the for 50 epochs and the results can be seen on a Fig. 9. The
motors to correct the pose of the UAV. performance of the proposed controller has been tested on
It has been proposed by numerous simulation to use PD the simulated response to the varying altitude change
controller instead of PID, due to the simplification of the command.
math and more robust stabilization [2, 6]. Based on this The same test has been done on the conventional PD
approach, only the the proportional and derivative coeffi- (Kp ¼ 15, Kd ¼ 8) controller (Fig. 10).
cients Kp and Kd for each rotational angles are used, so the
control equations are presented in the Eq. 16.
sx ¼ Kpr ðDhr Þ þ Kdr ðDh_r Þ
5 Discussion
sy ¼ Kp ðDhp Þ þ Kd ðDh_p Þ
p p As it can be seen from the obtained results, the conven-
ð16Þ
sz ¼ Kpy ðDhy Þ þ Kdy ðDh_y Þ tional PID-type controllers tend to be more reliable for a
_ smaller step change, or certain step change they were
T ¼ Kpz ðDZÞ þ Kdz ðDZÞ
preliminary tuned to maintain, while ANFIS network tends
The contribution of the each controller to speed of the to produce more desirable results for a sharper altitude
each motor is given in Eq. 17. change with minimal overshoot and small rise time.
However, noticeable altitude overshoot is produced for the
x 1 ¼ sy þ sz þ T
smaller change command. This issue could be caused by
x2 ¼ sy þ sz þ T the lack of the training data available specifically for a
ð17Þ
x 3 ¼ sx þ sz T smaller error scenarios, or under-training. However, it
x4 ¼ sx þ sz T should be noted that excessive amount of the training will
lead to the over-fitting, when the network will produce
excellent result during training, but fail to operate with the
4.3 ANFIS assisted control same performance for alternative dataset.
The performance of the ANFIS could be improved even
The purpose of the ANFIS in this setup is to design and further by increasing the diversity of the training data, for
implement the alternative for the PID/PD controller, which wider range of the experiments, and with more rigorous
would be able to optimally perform in dynamic environ- training, with taking over-fitting into account. As alterna-
ment. Firstly, the appropriate training data should be tive, the online learning method performance can be con-
obtained. The PID controlled quadcopter can be used to sidered, in order to be less dependent on dedicated training
obtain training input–output pairs, where inputs are error dataset.
and error rate, while the output is produced change in the It should be noted, that online training should be consid-
motor speed. The data can be obtained for different cases ered for the mobile platform, such as Raspberry Pi, so there
with different optimal PID parameters. For example, for a are some additional concerns that should be addressed in the
altitude controller the optimal PID response can be logged future work such as computational power and battery life.
for a command to increase the hovering altitude by 1 m, or
to decrease it by 0.5 m with different PID parameters. Computational power Raspberry Pi 3 is a microcomputer
Logging this data for multiple response experiments could with a limited capacity of the computational power. It is
produce an appropriate training data for a ANFIS con- vital to optimize the allocation of this resource. Firstly, the
troller. Similar to the altitude controller, the training data computational requirements to maintain all four ANFIS
can be produced for pitch, roll and yaw ANFIS controllers. based controllers (altitude, pitch, roll and yaw) operational
The proposed method of the training data acquisition has should be considered. Moreover, additional resources will
been done to collect the training data for a ANFIS altitude be required for onboard online learning and tuning of the
controller. It is based on the different experiments with PD control parameters. Lastly, additional drone functionality
controllers: to increase the flight altitude by 0.5, 1, 1.5 and should be taken into account. It could be desired for drone
2 m and the same values for a decreasing flight altitude, PD to be able to act as a remote sensor node or video signal
altitude controllers parameters presented in Table 1. transmitter, so amount of the available resources for a
Training data has been collected and ANFIS altitude con- controllers could be even more limited.
troller validation has been done in MATLAB and Simulink Battery Quadcopter drone is mobile platform, so the
environment. energy supply is limited. As a consequence of the addi-
The ANFIS network has been trained offline based on tional computational power of the ANFIS network
the generalized bell membership function, with 5
123
Analog Integrated Circuits and Signal Processing
1.5
data rate available for ZigBee based transmitter/receiver
1 protocols, it is desired to maximize the data exchange rate.
0.5
0
0 5 10 15 20 25 30 35 40 45 6 Conclusion
Time, s
Adaptive neuro-fuzzy network system is considered as
Fig. 10 The simulated PD (Kp ¼ 15, Kd ¼ 8) based altitude controller
alternative to the conventional PID controller for quadcopter
UAV flight control and stabilization. It has been shown, that
operation and maintenance the energy consumption tends
such architectures could be used as a generalized altitude
to be higher, which limits the aerial coverage.
controller, especially if the sharp altitude changes are
As it can be seen, one of the main issues related to the desired. Future work of this project could go into several
physical implementation of the ANFIS controllers is higher direction. Firstly, simulate and test the ANFIS performance
computational requirements compared to the conventional for other flight controllers (pitch, roll, yaw). Next, deploy
PID-type controllers, especially considering online learn- ANFIS based controllers on a physical Raspberry Pi drone,
ing. One way of the addressing this issue is to limit the and examine the limitations of both software and hardware.
amount and complexity of membership functions. Defi- Moreover, alternative types of the neuro-fuzzy architectures,
nitely, the accuracy could be compromised, but still such such as Cooperative-ANFIS or Evolving neuro-fuzzy net-
trade-off could be beneficial overall. Additionally, the works, could be tested for the same controller application and
alternatives for gradient descent learning could be consid- considering following properties: fast convergent learning,
ered, such as metaheuristic algorithms. online adaptation, small computational complexity. Finally,
Classic ANFIS architecture could be modified even development of the dedicated neuro-fuzzy analog hardware
more, by introduction of the evolutionary principles, so the planned for processing all ANFIS related data and algo-
whole structure of the network could be altered, not just rithms. The neuromorphic circuits, based on the CMOS
certain antecedent and consequent parameters. As a result, technology, memristors and crossbar arrays, are considered
the effects of the dynamic environment on a flight, such as for neuro-fuzzy circuit implementation. It is expected that
dynamically changing wind or weather conditions, could integration of such specialized hardware into quadrotor
be minimized. drone framework will reduce the processing load on the
Raspberry Pi and Navio2.
123
Analog Integrated Circuits and Signal Processing
123
Analog Integrated Circuits and Signal Processing
the Korea Agency for Infrastructure Technology Advancement, the Computing and Information Sciences, IEEE Transactions on Circuits
Korea Institute of Construction Technology, and the Korea Envi- and Systems 1, IEEE Access, IEEE Transactions on Emerging Topics
ronmental Industry and Technology Institute. He has also been acting in Computational Intelligence, and IET CPS (special issue) journals.
as an advisory member for the Ministry of Security and Public He is a Senior Member of IEEE, Life Member of ACM and Senior
Administration (South Korea), the Ministry of Land, Infrastructure Fellow of HEA. More see http://biomicrosystems.info/alex/.
and Transport (South Korea), the Ministry of Environment (South
Korea), and other government agencies. His research areas of interest
are primarily in geotechnical engineering, pavement engineering, and
construction materials. Prof. Kim has strong professional experience
in these areas and has participated actively in more than 100 projects
as a research assistant, research engineer, and principal/co-principal
investigator over the last 25 years.
123