Velocity Sensor for Real-Time Backstepping Control of a Multirotor Considering Actuator Dynamics

A real-time implementation of a control scheme for a multirotor, based on angular velocity sensors for the actuators, is presented. The control scheme is composed of two loops: an inner loop for the actuators and an outer loop for the unmanned aerial vehicle (UAV). The UAV control algorithm is designed by means of the backstepping technique and a robust sliding mode differentiator, and the actuator control strategy is based on a standard proportional-integral-derivative (PID) controller. A robust exact differentiator, based on high order sliding modes, is used to estimate the complex derivatives present in the proposed control law. As the measurements of the propeller’s angular velocities are required for the control law, velocity sensors are mounted in the axles of the rotors to retrieve them and a signal conditioning stage is implemented. In addition, dynamical models for the actuators of the aircraft were calculated by means of transfer functions obtained via experimental measurements in a test bench developed for this purpose. This test bench permits to characterize the parameters of the transfer functions by comparing the forces computed using the nominal parameter to the measured forces. To this end, it is assumed that the loads in the actuators of the vehicle are insignificant during flight. The effectiveness of the proposed sensor, its signal conditioning, and the overall control scheme are validated by means of simulation results and real-time experiments.


Introduction
An unmanned aerial vehicle (UAV) is an aircraft with no aircrew, which is replaced by a control computer system and radio-link for remote controllability or autonomous flight. The applications of UAVs cover diverse technology areas from monitoring and surveillance to transportation, which influence research fields as computer vision, mechanical design and automatic control. Moreover, from a control point of view, a UAV is a complex, nonlinear, highly coupled dynamical system with multiple inputs and outputs that is usually disturbed by diverse environmental factors as wind, air density variations, and obstacles. Hence, in order to implement a UAV flight controller in real-time, it is important to first validate the designed control scheme using simulation results and, then, implement it in an electronic embedded system. In particular, multirotors are a type of UAV characterized by easy construction and control.
A great diversity of research works oriented to the control for multirotors can be found in the literature, as shown in [1,2]. The control scheme approaches include classic control schemes as PID system are shown. Afterwards, real-time experiments are developed, and their results are documented and discussed. Finally, the conclusions of the presented work are outlined.

UAV'S Dynamical Model
A graphical representation of the multirotor considered in this work is depicted in Figure 1. The position of the vehicle is defined by its Cartesian coordinates (x, y, z) which corresponds to the translation vector between the origins of and inertial reference system x E , y E , z E and a coordinated system x B , y B , z B fixed to the centre of gravity of the UAV. Therefore, the orientation of the vehicle is defined by the Euler angles between these two coordinate systems: roll (φ), pitch (θ) and yaw (ψ). Defining a state vector as X = [φ,φ, θ,θ, ψ,ψ, z,ż, x,ẋ, y,ẏ] T , the state space representation of the vehicle can be obtained as: where f 2 = −g, f 4 = x 4 x 6 I y −I z I x − J r I x x 4 Ω, f 6 = x 2 x 6 I z −I x I y + J r I y x 2 Ω, f 8 = x 2 x 4 with I x , I y , and I z as the moments of inertia of the multi-rotor frame body, J r the total inertia, g as the gravity acceleration, m as the total mass of the aircraft, Ω = ω 2 + ω 4 − ω 1 − ω 3 , ω i as the angular velocity of the ith rotor of the vehicle, c i = cos x i , s i = sin x i , and X = [x 1 , . . . , x 12 ] T . The variables U 1 , U 2 , U 3 , and U 4 are given by 4 as the thrust factor, p as the thrust factor seen from the x axis, q as the thrust factor seen from the y axis, and d = (C D ρA)/2 as the drag factor of the propellers, where C T is the thrust coefficient, ρ is the air density, D is the propeller diameter, C D is the drag coefficient, and A is the cross-section of movement.

Actuators Dynamical Model
The actuators of the vehicle correspond to brushless DC (BLDC) motors that are controlled in open loop by electronic speed controllers (ESC) by means of suitable pulse-width modulation (PWM) signals generated by the electronic control unit. The dynamical model of this type of motor consist of a set of 5 ordinary differential equations and diverse parameters as electrical resistance and inductance, inertia, friction and back EMF (electro-mechanical force). In order to avoid the cumbersome characterization of these parameters, we propose to obtain their approximated transfer functions in an experimental manner, defining the duty cycle of the PWM signal and the rotor's angular velocity as its input and output, respectively. The methodology consists of introducing a test input signal to the real motor and measuring the generated angular velocity. The test input signal was defined as a step signal of 100% of duty cycle at t 1 = 120 ms, and 50% of duty cycle at t 2 = 3950 ms. The experimental measurements are shown in Figure 2. Then, this data is used to obtain an estimated transfer function by means of the System Identification Toolbox from Matlab [32]. Several pole-zero configurations were tried and the best result, with 95.6% accuracy, corresponded to the estimated transfer function G m (s) defined as: G m (s) = 716.6s 2 + 1.377 × 10 5 s + 7066 s 2 + 11.16s + 0.4724 (3)

Dynamical Parameter Characterization
To determine completely the dynamic model of the quadrotor defined by Equations (1)-(3), the mechanical and electric parameters of the UAV must be characterized. The mechanical part of these parameters was obtained by means of a 3D model of the system designed in a computer-aided design (CAD) software [33], which is shown in Figure 3. From this model, nominal values for the inertia terms I x , I y , I z , the mass m, and length l were defined. On the other hand, the terms b and d are related to the drag and thrust forces generated by the propellers, these forces are depicted in Figure 4. In addition, these parameters are defined by the following formulas: where D is the propeller diameter in meters, n is the propeller/motor speed in rev/s, ρ is the air density in kg/m 3 , C T the thrust coefficient, A is the cross-section of the movement in m 2 , v is the drone velocity in m/s, and C D is the drag coefficient. The terms ρ, D, and A are assumed constant and approximated by nominal values. The terms n and v are measured by the UAV sensors and, in particular, the propeller velocity n sensor will be explained in detail in a following section. The remainder terms C D and C T are indicated as nominal values by some research works as in [9] where a thrust coefficient of 2.98 × 10 −3 and a drag coefficient of 1.14 × 10 −7 are presented, but there is no explanation or methodology to obtain these values, which is very important when it comes to motor control. Due to the fact that the cross-section area A facing the direction of movement of the drone is very difficult to calculate during flight, a fixed drag coefficient is proposed as 43 × 10 −3 . This value was adjusted experimentally during flight tests to obtain the best closed-loop performance. The thrust coefficient was obtained experimentally by means of a bench and a scale to create characteristic curves for the parameter. The overall test bench is shown in Figure 5. Its working principle is based on manually varying the propeller velocities and measuring the generated thrust by means of the scale. Figure 6 shows the obtained characteristic curve for n − C T . From this, a C T value is proposed based on a minimal root mean squared error (RMSE) of the obtained curve and its correspondent function. In order to validate the obtained parameter, a comparison between the behavior generated by the manufacturer value, the proposed value and the measurements is presented in Figure 7. With a proposed C T = 0.0817445, a minimal RMSE of 0.077301668 N (0.7882576369 g f ) is obtained. Compared to the measured values, this is relatively small with respect to the thrust force difference. Finally, this experimentally adjusted value for C T was used in this work, and the nominal value used in [9] for the drag coefficient C D was defined, as no experimental measurements related to this parameter were obtained.

Controller Design
The control proposal is composed of two controllers: the UAV controller and the actuator controller. The input for the UAV controller is a reference vector X r that includes the altitude (z) and the Euler's angles (φ, θ, ψ) of the multirotor, and its outputs are references values for the angular velocities of the actuators (or the propellers). The actuator controller is composed by four PID controllers, which receives the desired angular velocity and defines a correspondent PWM value as the input of the motor. This inner control loop is the same for all the four motors of the UAV. The overall control scheme is shown in Figure 8 and the UAV and actuator controller are defined in the following subsections.

UAV Controller
The control objective is the reference tracking for the orientation (x 1 = φ, x 3 = θ, x 5 = ψ) and the altitude (x 7 = z) of the UAV. Hence, it is assumed that the references variables x 1r , x 3r , x 5r and x 7r are known, as well as their derivatives. Then, in order to obtain a concise controller design procedure, four different sub-systems from Equation (1) are defined as: The error variables for these subsystems are given by z i = x ir − x i , and their dynamics yields: After that, a Lyapunov's function is designed as V i = 1 2 z 2 i and its derivative results of the form: Then, the term x i+1 is proposed as a virtual control term, which is designed as: which will allow us to define the error variable for the next block. The term x * i+1 is the desired value for x i+1 , so, the error variable z i+1 is defined as z i+1 = x * i+1 − x i+1 which can be used to re-shape the Equation (8) where the control term U (i+1)/2 will be designed for the convergence of Equation (10). To this end, the candidate Lyapunov's function V i+1 = V i + 1 2 z 2 i+1 is proposed, the derivative of which is given by: and the control term U (i+1)/2 is designed as: with k i+1 < 0. Using Equation (12), the termV i+1 yields: which fulfilsV i+1 ≤0 and the convergence of z i and z i+1 to zero is assured. Hence, the control objective is achieved.

Levant's Differentiator
The termsẋ ir andẍ ir of the control term Equation (12) are not defined. To avoid cumbersome computations for these expressions, a robust exact differentiator, proposed by Levant in [34,35], is used. The main problem with usual differentiator designs is the combination of exactness and robustness with respect to possible measurement errors and input noise. Moreover, if the input signal present disturbances, the differentiator's output will be also disturbed. To overcome this, Levant's differentiator provides the square of the maxima of the measured input signal from the base signal, reducing the rate error that can be present in the output [36], by means of a sliding mode control term. The Equations of the second order differentiator, used in this work, are given bẏ where f (t) is the input signal, z i is the estimation of the ith derivative of f (t), and λ 0 , λ 1 , λ 2 are differentiators parameters to be tuned. Hence, it can be used to obtainẋ ir andẍ ir with f (t) = x ir .

Actuator Controller
The UAV controller generates the desired values for U 1 , U 2 , U 3 , and U 4 . Afterwards, the desired values for the actuators' velocities ω 1r , ω 2r , ω 3r , and ω 4r can be obtained from Equation (2) as: From here, the error variables for the actuators' controllers are defined as: Finally, the equation of the PID controllers are defined as: where the control gains k Pi , k Ii , and k Di are tuned heuristically. The PW M i signals correspond to the duty cycles of the ESC for each motor. It is worth to note that, as the motors can only rotate in one direction, the PW M i values are bounded by the interval [0, 100]%.

Experimental Setup
The UAV used for the experiments is composed of a quadrotor QAV250 frame with MT2204-2300KV brushless motors and 6030 propellers. Each motor is driven by a 2-4S 12A electronic speed controller (ESC) with an 11.1 V 2200 mAh Lithium-Polymer battery as a power supply. The main control board of the vehice is a PIXHAWK PX4 2.4.6 which is an STM32F427 microcontroller based board that uses an STM32F100 as a failsafe system. It includes an L3GD20H 3-axis gyroscope sensor, an LSM303D 3-axis accelerometer, an MPU6000 inertial measurement unit (IMU), and an MS5611 barometer. The board provides 1 ADC channel, 1 CAN port, 1 I2C port, 5 UART ports, and supports up to 14 pulse protocol outputs. In order to implement the proposed controller for the real-time experiments, it is necessary to obtain measurements of the rotors angular velocities; nonetheless, there are no available ports in the main board. Hence, a daughter board that allows capturing of the rotors sensors signals was included. It is based on an ATMEGA328/P microcontroller, which is capable of running at a frequency of 16 MHz, has 8 ADC channels available with up to 10-bit precision, and a universal synchronous and asynchronous receiver-transmitter (USART). As a result, it can be used to sense up to 8 analog sensors and transmit the data through serial communication to the main board.

Angular Velocity Sensor for the UAV Rotors
As part of the inner loop controller for the motors, a sensor for the propeller's velocities must be designed. Since the motors used in this work do not have any type of encoder, an intermittent black and white band is attached to the motor case acting as encoder. Additionally, CNY70 reflective sensors are used for capturing the light intensity change in the band when the motor is rotating, generating a pulse frequency that feeds a pin voltage level change interrupt in a daughter board. The interconnection between the reflective sensor, the motor and the daughter board are presented in Figure 9. This daughter board is proposed to provide modularity to the firmware development and to implement the digital conditioning of the signals generated by the reflective sensors. The signal generated by the reflective sensors triggers an interruption in the daughter board. This interruption is time tracked with a timer and five different captures are obtained. The first capture takes a false pulse that was observed and is taken in the middle of a pulse generated (not at the rising or falling edge), and then the next four pulses are timer captured, having two complete periods observed, which are averaged to obtain better accuracy. The encoder black and white band attached has 40 alternating stripes within a motor revolution. To avoid overlap in the different interruption's tasks, an interrupt scheduler routine is designed to assign execution status to the different sensing tasks. In that way, only one interruption is running at a time, avoiding the interrupt miss for the speed period capturing, which is extremely time sensitive.

Velocity Sensor's Signal Conditioning
Due to the switching nature of the velocity sensor and the noisy characteristics of its optical transducer, the retrieved measurements presented undesired high frequency fluctuations. Hence, a digital filtering stage was designed in the daughter board. Two different proposals were implemented: a moving average (MA) filter and an exponentially weighted moving average (EWMA) filter. The first is a finite impulse response filter which consists in obtaining the average value of the last m samples of the measured signal according to the following Equation: where x k is the current sample of the measured signal and y k is the current output of the filter. The latter filter is a recursive or infinite impulse response filter which is implemented by the following Equation: where α is the constant weight assigned to the filter. The performance comparison between both filters provided a solid ground to choose the more promising filter. The EWMA exposes a smaller RMSE (root-mean-square error) and provides smoother output behaviour as the input data becomes gradually less influential as it ages. On the other hand, MA treats each of the samples equally during the output computing but these are regarded as soon as the samples fall off the end of the number of elements considered in the filter. Therefore, the EWMA filter was selected to be used in this work.

Overall Controller Implementation
The global designed embedded control scheme was implemented in the main board of the vehicle using the model based approach as in [37,38]. It is characterized as a closed-loop controller where the control laws are computed based on the measured states of the vehicle as depicted in Figure 8. The stages of the implemented control strategy are described in the Algorithm 1. All the simulation and real-time experiments were carried out using the controller implementation described in this method.

Results
The control proposal was implemented in simulation and real-time experiments considering the same control and system parameters aiming to analyse the results, which are presented in this section.

Simulation Results
The parameters used for the simulation experiments are listed in Table 1. These correspond to the parameters obtained by the methodology described in the previous sections. The control objective is to track the Euler angles (φ, θ, ψ) and the altitude (z) of the multirotor vehicle. The resulting trajectory of the UAV position describes a square path as depicted in Figure 10. It is worth to note that, as a stabilize flight mode is considered, the references received by the overall control scheme are for the attitude (φ r , θ r and ψ r ) and altitude (z r ) of the vehicle. Hence, the square shaped position depicted in Figure 10 is a direct result of the definition for φ r , θ r and ψ r . The labels t 1 , t 2 , t 3 and t 4 indicate the instants where the trajectory reaches the corners of the square. For easy correlation, these timestamps are also indicated in Figures 11-13 by means of vertical blue dashed lines. This is a direct result of the reference defined for the attitude of the UAV which is shown in Figure 11. Moreover, the references for the three angles are depicted as well. The tracking performance is satisfactory as the proposed control scheme obtains the convergence of the error variables to a small vicinity to zero.     Figure 12 depicts the generated Cartesian coordinates of the vehicle during the simulation, and for the case of the attitude signal the reference is also presented. The convergence of the altitude to its reference in a finite time can be noted. Furthermore, the angular velocities of the propellers, and their references, are shown in Figure 13. This behavior validates the effectiveness of the PID controllers for the actuators of the vehicle in the inner loop, as the tracking performance is satisfactory. Moreover, the references for the propeller's velocities are within the range of commercial motors for drones, which indicates the applicability of the proposed control scheme in a real vehicle.

Experimental Results
The results of the real-time experiments are depicted in the following figures. The roll, pitch, and yaw angles of the vehicle and their references are shown in Figures 14-16, respectively. It can be noted that the tracking performance is satisfactory as the convergence of the attitude of the vehicle follows the desired values. Also, a noise component is present in all the measured variables which is normal due to the normal behaviour of the vehicle in flight. On the other hand, the altitude of the vehicle and its desired value are depicted in Figure 17. Its convergence to the reference value can be appreciated as the tracking error variable converges to a small vicinity to zero in a finite time. Finally, a video recording of the real-time experiment can be found in [39] where the performance of the overall control scheme is presented. It is important to mention that the period corresponding to the Figures 14-17 corresponds to the period from 0:41 to 1:41 of the reported video.

Discussion
The proposed control scheme for a UAV based on rotor velocity sensors establishes a solid foundation for developing research related to robust control design, implementation and testing. Also, the developed instrumentation permits to approach real-time thrust computation and wind estimation. On the other hand, although the backstepping technique is widely used and applied in the automatic control field, this work allows to define a comparative reference for more robust and innovative control strategies such as sliding modes, neural networks and adaptive controllers. Moreover, the UAV can be easily adapted to function as a test bench for educational and research purposes related to the design and testing of new control algorithms for multirotors. Finally, the next steps for this research work are related to the design and implementation of robust control schemes based on sliding modes and adaptive control. Also, we are currently exploring fault tolerant controllers which will use the information from the actuators angular velocities and current consumption to detect a failure and reconfigure the controller according to the identified fault.

Materials and Methods
The manuscript describes the overall structure of the control scheme and the interconnection of the components of the UAV. The proposed angular velocity sensor for the rotors is graphically described in detail so any interested researcher can replicate its implementation. Regarding the software, all the code is available at the repository in [40].

Conclusions
A control scheme for the trajectory tracking of the attitude and altitude of a multirotor was presented and its effectiveness was demonstrated by means of simulation and real-time experiments. The control strategy is based on the measurements of the angular velocities of the actuators which are open-loop driven BLDC motors. The overall controller consists of two control loops: an outer control loop for the UAV and an inner control loop for the actuators. The UAV controller is designed using the backstepping methodology which assures the closed loop stability of the system. It receives the references for the attitude (Euler angles) and altitude (height) to generate the necessary angular velocities of the actuators to assure the tracking of these references by the vehicle. The actuator control loop receives these necessary angular velocities for the actuators and generates the necessary PWM signals for the BLDC motors to perform the tracking of these angular velocities. This controller is designed based on the PID scheme, which was heuristically tuned to obtain the desired performance.
The simulation results were obtained considering approximated transfer functions for the motors, which were calculated experimentally by means of a proposed test bench. For the real-time experiments, a simple and effective encoder design was implemented based on reflective sensors and a striped band. This is necessary as commercial UAVs do not usually include encoders in the actuator's axles. Moreover, a conditioning stage for the output of the reflective and the altitude sensors was implemented based on the exponentially weighted moving average (EWMA) filter. The simulation and real-time experiments were satisfactory as the control objectives were fulfilled.

Conflicts of Interest:
The authors declare no conflict of interest. The funders had no role in the design of the study; in the collection, analyses, or interpretation of data; in the writing of the manuscript, or in the decision to publish the results.

Abbreviations
The following abbreviations are used in this manuscript: