天天看点

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

一、四旋翼飞行器简介

0 引 言

四旋翼飞行器由于具有可垂直起降、机动性强、操作方便等诸多优点,在军事和民用场合得到广泛应用,从而成为众多学者的研究热点。四旋翼飞行器是具有四输入、六输出的欠驱动、非线性、强耦合系统。其姿态控制精度和抗干扰问题一直是研究重点。目前国内较普遍的飞行器控制算法主要包括:反步法、自适应控制、H控制、滑模控制、自抗扰控制等,对实现四旋翼飞行器的姿态控制具有重要的理论和实践意义。文献提出应用反步算法为飞行器上下、前后、左右、偏航4个子系统配置控制律,实现了四旋翼飞行器对设定轨迹的精确跟踪。该算法在构造Lyapunov函数的过程中,是以其导数小于零为前提,因此应用受到局限。文献针对传统的离散线性滑模应用于四旋翼飞行器控制具有跟踪误差大、响应速度慢、不能有限时间收敛等问题,提出了干扰观测器补偿的自适应离散终端滑模控制,使响应时间更快、跟踪效果更理想、鲁棒性更强。文献利用线性扩张状态观测器对四旋翼飞行器内部不确定干扰和外部干扰进行实时估计,进而采取线性状态反馈控制对扰动的估计值进行在线补偿,以实现四旋翼飞行器的姿态控制。

1 四旋翼飞行器动力学模型的建立

1. 1 四旋翼飞行器受力分析

对于飞行器的每个旋翼,剖面呈非对称,一旦旋翼旋转,由于上表面空气流速比下表面快,故上表面受到的空气压力小于下表面,上下表面受到的压差形成升力,如图1所示。旋翼1、3逆时针旋转,旋翼2、4顺时针旋转。由叶素动量理论可知,每个旋翼产生的升力Fi与电机转速ωi的平方成正比,即Fi=kFω2i(i=1,2,3,4),其中kF为升力系数。

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

图1 四旋翼飞行器受力分析图

当旋翼旋转时,空气阻力会阻碍其旋转。这种阻力形成施加在机体上的反扭转力矩,当4个旋翼转速相等时,旋翼产生的反扭矩作用相互抵消。四旋翼飞行器通过改变2对正反螺旋桨的转速实现对其运动控制。在4个旋翼转速相等的情况下,同时增加或者减少4个旋翼转速,可以实现飞行器上升或者下降。如果4个旋翼产生的升力之和等于机体重力,可以实现飞行器空中悬停。保持旋翼2、4的转速不变,改变旋翼1或者旋翼3的转速,飞行器在力矩l(F3-F1)或l(F1-F3)的作用下(其中l为电机轴线到飞行器中心距离),可实现俯仰运动。保持旋翼1和旋翼3的转速不变,改变旋翼2或者旋翼4的转速,飞行器在力矩l(F4-F2)或l(F2-F4)的作用下,可实现横滚运动。如果同时改变旋翼1和旋翼3的转速,或者同时改变旋翼2和旋翼4的转速,并保持飞行器总升力与机体重力相等,飞行器会在反扭矩的作用下实现偏航运动。由此可见,实现飞行器垂直运动的升力,以及实现俯仰、横滚、偏航运动的旋转力矩可以表示为

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

式中: F——飞行器垂直运动的升力;

Mx、My、Mz——四旋翼俯仰、横滚和偏航运动的旋转力矩;

kF——升力系数;

kM——旋转力矩系数。

1. 2 动力学模型建立

为了描述飞行器的姿态和运动状态,需要引入地理坐标系n(X,Y,Z)与载体坐标系b(x,y,z)。地理坐标系又称为东北天坐标系,载体坐标系与飞行器固连,原点为飞行器中心。将地理坐标系与载体坐标系原点重合,并将地理坐标系分别绕X、Y、Z轴旋转3次之后可得到载体坐标系,地理坐标系到载体坐标系的转换矩阵可表示为

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】
【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

由式(5)和式(2)可求得地理坐标系n中飞行器在X、Y、Z轴方向所受旋翼升力向量:

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】
【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

在低速飞行过程中,角速度矢量较小,式(8)中左边第二项可近似认为为零,则式(8)可化简为

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

将式(10)转换可得:

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

由式(7)和式(11)可得四旋翼飞行器在低速飞行情况下的非线性动力学模型:

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

由式(12)可知,四旋翼飞行器线运动不影响角运动,但是角运动会影响线运动。以u1、u2、u3、u4为系统输入,通过改变这4个输入变量的值,可以改变飞行器的3个线位移和3个角位移,从而实现对飞行器的运动控制。

2 四旋翼飞行器的控制系统构建与仿真

经典PID算法结构简单,基于偏差设计反馈律,不依赖受控对象的具体数学模型,在很多过程控制中均有良好表现。尽管各种新的控制算法不断涌现,但是并没有改变PID控制算法在工业控制中的主导地位。本文根据四旋翼在飞行过程中经常会遇到不确定外界干扰等情况,设计了基于小扰动的PID控制器,如图2所示。

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

图2 PID控制器结构图

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】

二、部分源代码及仿真图

【飞行器】基于matlab GUI四旋翼飞行器PID控制仿真【含Matlab源码 1279期】
function varargout = GUI_Config(varargin)
% GUI_CONFIG MATLAB code for GUI_Config.fig
%      GUI_CONFIG, by itself, creates a new GUI_CONFIG or raises the existing
%      singleton*.
%
%      H = GUI_CONFIG returns the handle to a new GUI_CONFIG or the handle to
%      the existing singleton*.
%
%      GUI_CONFIG('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in GUI_CONFIG.M_VALUE with the given input arguments.
%
%      GUI_CONFIG('Property','Value',...) creates a new GUI_CONFIG or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before GUI_Config_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to GUI_Config_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_Config

% Last Modified by GUIDE v2.5 18-Dec-2020 21:15:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_Config_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_Config_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
y_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function Izz_value_Callback(hObject, eventdata, handles)
% hObject    handle to Izz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Izz_value as text
%        str2double(get(hObject,'String')) returns contents of Izz_value as a double


% --- Executes during object creation, after setting all properties.
function Izz_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Izz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in structParamClear.
function structParamClear_Callback(hObject, eventdata, handles)
% hObject    handle to structParamClear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.m_value,'String','');
set(handles.g_value,'String','');
set(handles.L_value,'String','');
set(handles.Ixx_value,'String','');
set(handles.Iyy_value,'String','');
set(handles.Izz_value,'String','');

% --- Executes on button press in structParam_Default.
function structParam_Default_Callback(hObject, eventdata, handles)
% hObject    handle to structParam_Default (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.m_value,'String','0.5');
set(handles.g_value,'String','9.8');
set(handles.L_value,'String','0.2');
set(handles.Ixx_value,'String','0.114');
set(handles.Iyy_value,'String','0.114');
set(handles.Izz_value,'String','0.158');
set(handles.progresslabel,'String','结构参数使用默认参数');



function xt_value_Callback(hObject, eventdata, handles)
% hObject    handle to xt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of xt_value as text
%        str2double(get(hObject,'String')) returns contents of xt_value as a double


% --- Executes during object creation, after setting all properties.
function xt_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function yt_value_Callback(hObject, eventdata, handles)
% hObject    handle to yt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of yt_value as text
%        str2double(get(hObject,'String')) returns contents of yt_value as a double


% --- Executes during object creation, after setting all properties.
function yt_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to yt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function zt_value_Callback(hObject, eventdata, handles)
% hObject    handle to zt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of zt_value as text
%        str2double(get(hObject,'String')) returns contents of zt_value as a double


% --- Executes during object creation, after setting all properties.
function zt_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to zt_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in posParam_clear.
function posParam_clear_Callback(hObject, eventdata, handles)
% hObject    handle to posParam_clear (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.xt_value,'String','');
set(handles.yt_value,'String','');
set(handles.zt_value,'String','');


% --- Executes on button press in posParam_Default.
function posParam_Default_Callback(hObject, eventdata, handles)
% hObject    handle to posParam_Default (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
set(handles.xt_value,'String','30');
set(handles.yt_value,'String','50');
set(handles.zt_value,'String','-15');
set(handles.progresslabel,'String','位置参数使用默认参数');


function kpx_value_Callback(hObject, eventdata, handles)
% hObject    handle to kpx_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kpx_value as text
%        str2double(get(hObject,'String')) returns contents of kpx_value as a double


% --- Executes during object creation, after setting all properties.
function kpx_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kpx_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




% --- Executes during object creation, after setting all properties.
function kpy_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kpy_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function kiy_value_Callback(hObject, eventdata, handles)
% hObject    handle to kiy_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kiy_value as text
%        str2double(get(hObject,'String')) returns contents of kiy_value as a double


% --- Executes during object creation, after setting all properties.
function kiy_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kiy_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





function kpz_value_Callback(hObject, eventdata, handles)
% hObject    handle to kpz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kpz_value as text
%        str2double(get(hObject,'String')) returns contents of kpz_value as a double


% --- Executes during object creation, after setting all properties.
function kpz_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kpz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function kiz_value_Callback(hObject, eventdata, handles)
% hObject    handle to kiz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kiz_value as text
%        str2double(get(hObject,'String')) returns contents of kiz_value as a double


% --- Executes during object creation, after setting all properties.
function kiz_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kiz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function kdz_value_Callback(hObject, eventdata, handles)
% hObject    handle to kdz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kdz_value as text
%        str2double(get(hObject,'String')) returns contents of kdz_value as a double


% --- Executes during object creation, after setting all properties.
function kdz_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kdz_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function kpphi_value_Callback(hObject, eventdata, handles)
% hObject    handle to kpphi_value (see GCBO)




function kdtheta_value_Callback(hObject, eventdata, handles)
% hObject    handle to kdtheta_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kdtheta_value as text
%        str2double(get(hObject,'String')) returns contents of kdtheta_value as a double


% --- Executes during object creation, after setting all properties.
function kdtheta_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to kdtheta_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
set(hObject,'String','');
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function kppsi_value_Callback(hObject, eventdata, handles)
% hObject    handle to kppsi_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of kppsi_value as text
%        str2double(get(hObject,'String')) returns contents of kppsi_value as a double






           

三、运行结果

四、matlab版本及参考文献

下一篇: uniq命令