Original link
Controller design
A linear mathematical model of the system based on roll, pitch, yaw transfer function expression
A closed-loop controller was designed using MATLAB simulation tools.
First, define the constants of the system model in the MATLAB script.
Percent ConstantsD =0.45;% diameter QuadrocopterL =sqrt(d^2/8);% distance between one rotor and center of massm =1.0024;% mass of quadrocopterg =9.81;% Gravitational AccelerationKPWM =7.8502;% proportional constant OMEGA/PWMJxx =0.01046412;% mass moment of inertia xbJyy =0.010746965;% mass moment of inertia YBJzz =0.020576095;% mass moment of inertia ZBBT =7.90261e-06;% proportional coefficient blade thrust/(omega^2)BH =1.66057e-7;% proportional coefficient blade torque/(omega^2)% System gainsK_phi = l*bt*kpwm*sqrt(M*G*BT)/jxx;k_theta = l*bt*kpwm*sqrt(M*G*BT)/jyy;k_psi = bh*kpwm*sqrt(M*G*BT)/jzz;
Z-Transform
Before designing the controller, consider that the system to be controlled is discrete, so it needs to be transformed to the z-domain. The sensor MPU-9150 is measured at a frequency of 50Hz and is the slowest part of the entire system, so it defines the sampling frequency of the control system.
%% Z-transform% sample time1/50;% LTI-System of quadcopters phi (roll)Gs_phi_s = tf(k_phi,[1 0 0]);% transfer function continuous to discreteGs_phi_z = c2d(Gs_phi_s, T_sample);
PD Pole Configuration
The first step is to design the roll change part of the four rotors in the controller by the pole assignment of the discrete z-domain. In the complex z-plane real axis, there are 3 stable poles at 0.83, which are used to design the closed-loop control system. The following MATLAB script also makes a calculation of the polynomial in the controller transfer function.
%% Pole-placement% desired poles[0.83 0.83 0.83];[Gs_phi_z_num, Gs_phi_z_den] = tfdata(Gs_phi_z,‘v‘);Gs_phi_z_num = Gs_phi_z_num(2:end);[Gc_phi_z_num, Gc_phi_z_den] = placepole(Gs_phi_z_num, Gs_phi_z_den, d_phi);% controllerGc_phi_z = tf(Gc_phi_z_num,Gc_phi_z_den,T_sample);
The complex pole-0 point map (Pole-zero map) of the closed-loop control system shows that the real part of all poles is the specified 0.83.
Such a closed-loop system, with MATLAB simulation results are as follows, is a settling time of about 1s step response.
Design of the Controller
is equivalent to a discrete PD controller with a general form of communication
The above formula can be written
In order to adjust the controller parameters in the flight test, the controller is designed to form PD parameter.
Compare the above formulas to find the transformation relationship
These parameters can be easily adjusted in the course of testing the aircraft.
%% PID controller % Controller coefficients a_phi = FLIPLR (gc_ Phi_z_den (2 : end )); B_phi = FLIPLR (Gc_phi_z_num); % pd-parameters P_phi = (B_phi (1 ) +b_phi (2 ))/(A_phi (1 ) +1 ); N_phi = (A_phi (1 ) +1 )/t_sample;d_phi = (B_phi ( Span class= "Hljs-number" >2 )-(B_phi (1 ) +b_phi (2 )/(A_phi (1 ) +1 )) *t_sample/(A_phi ( Span class= "Hljs-number" >1 ) +1 );
The same process is used for pitch and yaw. It is worth noting that for yaw, the angular velocity, not the angle, is to be controlled. Therefore, in the corresponding pole configuration, the final model is a simple P-controller.
Controller output
As the controller outputs for controlling the quadcopter ' s attitude is summarized by
The flight control output that controls the attitude of the aircraft can be summarized in the following form
Each PWM signal represents a motor, and when calculated, consider the portion of the PWM signal needed for hovering.
Simulation
The simulation model of the closed-loop control system in MATLAB simulator includes the Attitudecontrol description Controller and the nonlinear mathematical model of MM representing the four rotors. Considering the discrete form of the control system, the 0-order pole element is also input into the model.
The subsystem Attitudecontrol consists of 3 PID controllers that use the output to accurately calculate the input.
The step response for each angle in the closed-loop control system is shown below. The third figure looks less like a box because it controls angular velocity, not angle.
Expand into a PID controller
The first flight test found that the aircraft's centroid and geometric center were not coincident, causing the aircraft to turn sideways. Therefore, the controller needs an additional integral portion to be extended. The discrete PID controller model is represented as follows:
Convert fractional form to get
This gets the polynomial form of the numerator and denominator. The polynomial is sent to the control algorithm in the form of an array.
The integral gain I is determined by experiments.
Implementation
The digital controller is implemented on the Infineon XMC-4500, in attitudecontroller.c and AttitudeController.h two files.
The implementation details of the controller code can be in 5. Software found.
3 Controller Design