✅作者简介:热爱科研的Matlab仿真开发者,擅长毕业设计辅导、数学建模、数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。
https://gitcode.com/qq_59747472/Matlab/blob/main/README.md
🍎 往期回顾关注个人主页:Matlab科研工作室
👇 关注我领取海量matlab电子书和数学建模资料
🍊个人信条:做科研,博学之、审问之、慎思之、明辨之、笃行之,是为:博学慎思,明辨笃行。
🔥 内容介绍
一、引言
无人机在现代社会的应用愈发广泛,涵盖了军事侦察、物流配送、地理测绘等众多领域。在无人机的运行过程中,精确的航路控制至关重要,它直接影响到无人机能否高效、安全地完成任务。传统的 PID 控制算法与先进的模糊 PID 控制算法是实现无人机航路控制的两种重要手段,本文将深入探讨这两种算法在无人机航路控制中的应用原理、特点及效果对比。
二、无人机航路控制概述
无人机航路控制旨在引导无人机按照预定的航线飞行,确保其在飞行过程中能够准确跟踪航路点,同时应对各种干扰因素,如气流变化、设备故障等,保持稳定的飞行姿态。无人机的飞行状态通常由多个参数描述,包括位置、速度、姿态角(俯仰角、偏航角、滚转角)等。航路控制算法需要根据这些参数的实时反馈,调整无人机的控制输入,如电机转速、舵面偏转角度等,以实现精确的航路跟踪。
三、PID 控制原理及在无人机航路控制中的应用
(一)PID 控制原理
PID 控制器是一种线性控制器,它根据给定值(期望的无人机位置、姿态等)与实际输出值(无人机当前的位置、姿态等)之间的偏差,通过比例(P)、积分(I)、微分(D)三个环节的线性组合来计算控制量。其控制规律的数学表达式为:
(二)在无人机航路控制中的应用
在无人机航路控制中,PID 控制器通常应用于多个控制回路,如位置控制回路和姿态控制回路。以位置控制为例,将无人机当前位置与预定航路点的位置偏差作为 PID 控制器的输入,通过计算得到的控制量来调整无人机的飞行速度和方向,使其逐渐靠近航路点。在姿态控制方面,根据无人机当前姿态角与期望姿态角的偏差,利用 PID 控制器调整舵面偏转角度,保持无人机的稳定飞行姿态。例如,当无人机的实际位置偏离预定航路点时,PID 控制器通过增大或减小推进电机的转速,改变无人机的飞行速度,同时调整方向舵的角度,使无人机转向,从而回到预定航路上。
四、模糊 PID 控制原理及在无人机航路控制中的应用
(一)模糊 PID 控制原理
五、PID 与模糊 PID 在无人机航路控制中的效果对比
(一)响应速度
在无人机起飞或遇到突发情况需要快速改变飞行方向时,模糊 PID 控制由于能够根据偏差和偏差变化率实时调整 PID 参数,对控制量的调整更加灵活和迅速,因此响应速度通常优于传统 PID 控制。例如,在执行紧急避障指令后,模糊 PID 控制下的无人机能够更快地调整飞行姿态和速度,重新回到预定航路上,其响应时间比传统 PID 控制缩短了 [X]%。
(二)稳定性
在无人机飞行过程中,不可避免地会受到各种干扰,如气流波动、电机噪声等。模糊 PID 控制能够根据干扰引起的偏差和偏差变化及时调整 PID 参数,使无人机在受到干扰后能够更快地恢复稳定飞行状态。相比之下,传统 PID 控制由于参数固定,在面对较大干扰时,可能会出现较长时间的波动,甚至导致飞行不稳定。例如,在遇到强气流干扰时,模糊 PID 控制下无人机的姿态波动范围比传统 PID 控制减小了 [X]%,能够更稳定地保持在预定航路上。
(三)准确性
模糊 PID 控制在跟踪航路点时,能够根据无人机与航路点的距离和接近速度,智能调整 PID 参数,有效减少超调和稳态误差,从而提高航路跟踪的准确性。传统 PID 控制由于参数不能实时自适应调整,在接近航路点时容易出现超调现象,导致跟踪误差增大。例如,在一系列航路点跟踪测试中,模糊 PID 控制的平均跟踪误差比传统 PID 控制降低了 [X]%,能够更精确地引导无人机沿着预定航路飞行。
六、结论
PID 控制和模糊 PID 控制在无人机航路控制中都具有重要作用。传统 PID 控制结构简单、易于实现,在一些相对稳定的飞行环境中能够满足基本的航路控制需求。而模糊 PID 控制凭借其自适应调整 PID 参数的能力,在响应速度、稳定性和准确性方面表现更优,尤其适用于复杂多变的飞行环境和对控制精度要求较高的任务。在实际应用中,应根据无人机的任务需求、飞行环境等因素,合理选择控制算法,以实现高效、安全、精确的航路控制。随着无人机技术的不断发展,模糊 PID 控制等先进控制算法有望在无人机领域得到更广泛的应用和进一步的优化。
⛳️ 运行结果
📣 部分代码
%This script is to run the simulation multiple times in order to gather
%mean results.
function meanrisetime = meanresult(controller,numsim)
%numsim is the number of times the simulation is to be run
%define arrays:
x=[];
y=[];
z=[];
xdot=[];
ydot=[];
zdot=[];
phi=[];
theta=[];
psi=[];
phidot=[];
thetadot=[];
psidot=[];
risetime=[];
%extract results from simulations:
for n=1:numsim;
if strcmpi(controller,'PID')==1;
result=nographsimulate(PID);
end
if strcmpi(controller,'PD')==1;
result=nographsimulate(PD);
end
x(n,:)= result.x(1,:);
y(n,:)= result.x(2,:);
z(n,:)= result.x(3,:);
xdot(n,:)=result.vel(1,:);
ydot(n,:)=result.vel(2,:);
zdot(n,:)=result.vel(3,:);
phi(n,:)=result.theta(1,:);
theta(n,:)=result.theta(2,:);
psi(n,:)=result.theta(3,:);
phidot(n,:)=result.angvel(1,:);
thetadot(n,:)=result.angvel(2,:);
psidot(n,:)=result.angvel(3,:);
risetime(n)=result.risetime;
end
times=result.t;
%take mean results:
meanx=mean(x);
meany=mean(y);
meanz=mean(z);
meanxdot=mean(xdot);
meanydot=mean(ydot);
meanzdot=mean(zdot);
meanphi=mean(phi);
meantheta=mean(theta);
meanpsi=mean(psi);
meanphidot=mean(phidot);
meanthetadot=mean(thetadot);
meanpsidot=mean(psidot);
risetime(risetime==0)=[];
meanrisetime=mean(risetime);
% %PLOT MEAN RESULTS:
% figure
% plots=[subplot(2,1,1), subplot(2,1,2)];
%
% %VELOCITIES
% subplot(plots(1));
% plot(times,meanxdot, '--b', 'Linewidth',1.2)
% titlestr1=strcat({'Mean velocities when simulated '},num2str(numsim),{' times'});
% title(titlestr1)
% xlabel('time (s)')
% ylabel('m/s')
% hold on
% plot(times,meanydot, 'r', 'Linewidth',1.2)
% hold on
% plot(times,meanzdot, ':g', 'Linewidth',1.2)
% legend('x','y','z')
%
% %DISPLACEMENTS
% subplot(plots(2));
% plot(times,meanx, '--b', 'Linewidth',1.2)
% titlestr2=strcat({'Mean displacements when simulated '},num2str(numsim),{' times'});
% title(titlestr2)
% xlabel('time (s)')
% ylabel('metres')
% hold on
% plot(times,meany, 'r', 'Linewidth',1.2)
% hold on
% plot(times,meanz, ':g', 'Linewidth',1.2)
%
% figure
% plots=[subplot(2,1,1), subplot(2,1,2)];
%
% %ANGULAR VELOCITIES
% subplot(plots(1));
% plot(times,meanphidot, 'r', 'Linewidth',1.2)
% titlestr3=strcat({'Mean angular velocities when simulated '},num2str(numsim),{' times'});
% title(titlestr3)
% xlabel('time (s)')
% ylabel('radians/s')
% hold on
% plot(times,meanthetadot, '--b', 'Linewidth',1.2)
% hold on
% plot(times,meanpsidot, ':g', 'Linewidth',1.2)
% legend('Roll','Pitch','Yaw')
%
% %ANGULAR DISPLACEMENTS
% subplot(plots(2));
% plot(times,meanphi, 'r', 'Linewidth',1.2)
% titlestr4=strcat({'Mean angular displacements when simulated '},num2str(numsim),{' times'});
% title(titlestr4)
% xlabel('time (s)')
% ylabel('radians')
% hold on
% plot(times,meantheta, '--b', 'Linewidth',1.2)
% hold on
% plot(times,meanpsi, ':g', 'Linewidth',1.2)
%PATH PLOT
xmax=max(meanx)+10;
xmin=min(meanx);
ymax=max(meany)+10;
ymin=min(meany);
zmax=max(meanz)+10;
zmin=min(meanz);
figure;
plot3(meanx,meany,meanz,'r','LineWidth',1.5)
axis([xmin,xmax,ymin,ymax,zmin,zmax])
xlabel('x')
ylabel('y')
zlabel('z')
grid on
posstr=strcat('x=',num2str(meanx(length(meanx)))...
,{', y='},num2str(meany(length(meany))),{', z='},num2str(meanz(length(meanz))));
text(meanx(length(meanx)),meany(length(meany)),meanz(length(meanz)),posstr);
trise=strcat({'mean rise time = '},num2str(meanrisetime),'s');
text(meanx(length(meanx)),meany(length(meany)),0.9*meanz(length(meanz)),trise);
titlestr5=strcat({'Mean path of quadcopter when simulated '},num2str(numsim),{' times'});
title(titlestr5)