基于matlab实现无人机自适应控制

该内容是关于Matlab环境下智能控制系统的仿真研究,包括参数估计、轨迹误差和输入信号的分析。作者探讨了多种控制算法,如PD控制、TEB、CG和BGF,并提供了代码示例。文章涉及无人机的轨迹规划和姿态控制,以及动态参数的自适应估计。
摘要由CSDN通过智能技术生成

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信       无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机 

⛄ 内容介绍

⛄ 部分代码

% /****************************************************************************%  * modification, are permitted provided that the following conditions%  * are met:%  *%  * 1. Redistributions of source code must retain the above copyright%  *    notice, this list of conditions and the following disclaimer.%  * 2. Redistributions in binary form must reproduce the above copyright%  *    notice, this list of conditions and the following disclaimer in%  *    the documentation and/or other materials provided with the%  *    distribution.%  * 3. Neither the name of this repo nor the names of its contributors may be%  *    used to endorse or promote products derived from this software%  *    without specific prior written permission.%  *%  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS%  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT%  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS%  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE%  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,%  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,%  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS%  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED%  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT%  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN%  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE%  * POSSIBILITY OF SUCH DAMAGE.%  *%  ****************************************************************************/clc;close all;clear all;set(0,'defaulttextInterpreter','latex');set(groot, 'defaultAxesTickLabelInterpreter','latex'); set(groot, 'defaultLegendInterpreter','latex');set(groot, 'DefaultAxesFontWeight', 'bold');%set(0,'DefaultFigureWindowStyle','docked')set(0,'DefaultFigureWindowStyle','normal')global my_sigmoid_ a a_orign label torque_vector amp1 amp2 tt input_pd input_teb input_cg input_bgf input_cf lambda0 lambdaf lambdac T get_qd1 get_qd2 get_qd3 get_qd4 k0 A Kd P0 K0; my_sigmoid_ = @my_sigmoid;label='1'; %1 or time_var. If time_var, the parameters will change as a sigmoidprint_plots=0;if strcmp(label,'time_var')    T=3;else    T=1.5;endm=0.5;Ixx=2*4.8e-02;Iyy=2*4.8e-02;Izz=2*8.8e-02;a=[m;Ixx;Iyy;Izz]; %Real parametersa_orign=[m;Ixx;Iyy;Izz]; %Real parameters%Parameters only of CF:K0=50*eye(4); %Parameters of CF and BGF:lambda0=4800; k0=200;   %%Parameters of CG and BGF and CF:lambdaf=10; %Parameters of TEB and CG:P0=5*eye(4); %Parameters of all the algorithms (used for the control law and the definition of s):lambdac=5; % A=20*eye(4);% Kd=50*eye(4);thrust.teb=[];     thrust.cg=[];   thrust.bgf=[];tau_yaw.teb=[];   tau_yaw.cg=[];  tau_yaw.bgf=[];tau_pitch.teb=[];  tau_pitch.cg=[];  tau_pitch.bgf=[];tau_roll.teb=[];   tau_roll.cg=[];  tau_roll.bgf=[];tau4_vector=[];syms tt%opts = odeset('RelTol',1e-2);   % [t,Y] = ode45(@(t,y) myfunc(t,y,....), tspan, ic, opts);[t_pd,y_pd] = adapt_control("PD"); %"TEB", "CG" or "BGF" [t_teb,y_teb] = adapt_control("TEB"); %"TEB", "CG" or "BGF"[t_cg,y_cg] = adapt_control("CG"); %"TEB", "CG" or "BGF"[t_bgf,y_bgf] = adapt_control("BGF"); %"TEB", "CG" or "BGF"[t_cf,y_cf] = adapt_control("CF"); %"TEB", "CG" or "BGF" %% Plotsclose allset(gcf,'renderer','Painters')close allwidth=1500; height=300;%%%%%% Estimated Parametersinit_par=13;figure; set(gcf, 'Position',  [100, 100, width, height])subplot(1,4,1); hold onplot(t_teb,y_teb(:,init_par))plot(t_cg,y_cg(:,init_par))plot(t_bgf,y_bgf(:,init_par))plot(t_cf,y_cf(:,init_par))if strcmp(label,'time_var')    plot(t_cf,my_sigmoid_(t_cf)*a_orign(1),'Color','blue','LineStyle','--')else    line([0 T],[a_orign(1) a_orign(1)],'Color','blue','LineStyle','--');end%yline(a(1),'-.b')title('$\hat{m}\;\;(kg)$'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','Real','Location','southeast')subplot(1,4,2); hold onplot(t_teb,y_teb(:,init_par+1))plot(t_cg,y_cg(:,init_par+1))plot(t_bgf,y_bgf(:,init_par+1))plot(t_cf,y_cf(:,init_par+1))if strcmp(label,'time_var')    plot(t_cf,my_sigmoid_(t_cf)*a_orign(2),'Color','blue','LineStyle','--')else    line([0 T],[a_orign(2) a_orign(2)],'Color','blue','LineStyle','--');endtitle('$\hat{I}_{xx}\;\;(kg \; m^2)$'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','Real','Location','southeast')subplot(1,4,3); hold onplot(t_teb,y_teb(:,init_par+2))plot(t_cg,y_cg(:,init_par+2))plot(t_bgf,y_bgf(:,init_par+2))plot(t_cf,y_cf(:,init_par+2))if strcmp(label,'time_var')    plot(t_cf,my_sigmoid_(t_cf)*a_orign(3),'Color','blue','LineStyle','--')else    line([0 T],[a_orign(3) a_orign(3)],'Color','blue','LineStyle','--');endtitle('$\hat{I}_{yy}\;\;(kg \; m^2)$'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','Real','Location','southeast')subplot(1,4,4); hold onplot(t_teb,y_teb(:,init_par+3))plot(t_cg,y_cg(:,init_par+3))plot(t_bgf,y_bgf(:,init_par+3))plot(t_cf,y_cf(:,init_par+3))if strcmp(label,'time_var')    plot(t_cf,my_sigmoid_(t_cf)*a_orign(4),'Color','blue','LineStyle','--')else    line([0 T],[a_orign(4) a_orign(4)],'Color','blue','LineStyle','--');endtitle('$\hat{I}_{zz}\;\;(kg \; m^2)$'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','Real','Location','southeast')set(gcf,'renderer','Painters')%suptitle('Estimated Parameters')if(print_plots==1) printeps(1,strcat('./figs/estimated_parameters',label))end%%%%%% Errors in qfigureinit_q=3;subplot(1,4,1); hold onplot(t_teb,y_teb(:,init_q)-get_qd1(t_teb))plot(t_cg,(y_cg(:,init_q)-get_qd1(t_cg)))plot(t_bgf,(y_bgf(:,init_q)-get_qd1(t_bgf)))plot(t_cf,(y_cf(:,init_q)-get_qd1(t_cf)))plot(t_pd,y_pd(:,init_q)-get_qd1(t_pd))title('$\tilde{z}$ (m)'); xlabel('$t(s)$')legend({'TEB','CG','BGF','CF','PD'},'Location','southeast')%ylim([-0.45 0.1])subplot(1,4,2); hold onplot(t_teb,(180/pi)*(y_teb(:,init_q+1)-get_qd2(t_teb)))plot(t_cg,(180/pi)*(y_cg(:,init_q+1)-get_qd2(t_cg)))plot(t_bgf,(180/pi)*(y_bgf(:,init_q+1)-get_qd2(t_bgf)))plot(t_cf,(180/pi)*(y_cf(:,init_q+1)-get_qd2(t_cf)))plot(t_pd,(180/pi)*(y_pd(:,init_q+1)-get_qd2(t_pd)))title('$\widetilde{roll}$ (deg)'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','PD','Location','southeast')%ylim([-2 1])subplot(1,4,3); hold onplot(t_teb,(180/pi)*(y_teb(:,init_q+2)-get_qd3(t_teb)))plot(t_cg,(180/pi)*(y_cg(:,init_q+2)-get_qd3(t_cg)))plot(t_bgf,(180/pi)*(y_bgf(:,init_q+2)-get_qd3(t_bgf)))plot(t_cf,(180/pi)*(y_cf(:,init_q+2)-get_qd3(t_cf)))plot(t_pd,(180/pi)*(y_pd(:,init_q+2)-get_qd3(t_pd)))title('$\widetilde{pitch}$ (deg)'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','PD','Location','southeast')%ylim([-2 1])subplot(1,4,4); hold onplot(t_teb,(180/pi)*(y_teb(:,init_q+3)-get_qd4(t_teb)))plot(t_cg,(180/pi)*(y_cg(:,init_q+3)-get_qd4(t_cg)))plot(t_bgf,(180/pi)*(y_bgf(:,init_q+3)-get_qd4(t_bgf)))plot(t_cf,(180/pi)*(y_cf(:,init_q+3)-get_qd4(t_cf)))plot(t_pd,(180/pi)*(y_pd(:,init_q+3)-get_qd4(t_pd)))title('$\widetilde{yaw} (deg)$'); xlabel('$t(s)$')legend('TEB','CG','BGF','CF','PD','Location','southeast')%ylim([-2 1])%suptitle('Position Errors')set(gcf, 'Position',  [100, 100, width, height])set(gcf,'renderer','Painters')if(print_plots==1) printeps(2,strcat('./figs/position_errors',label))end%%%%%%%%%%%%%%%%%   INPUTSfigure;  set(gcf, 'Position',  [100, 100, width, height])subplot(1,4,1); hold onplot(t_teb,input_teb(:,1))plot(t_cg,input_cg(:,1))plot(t_bgf,input_bgf(:,1))plot(t_cf,input_cf(:,1))plot(t_pd,input_pd(:,1))%yline(a(1),'-.b')title('$T\;\;(N)$'); xlabel('$t(s)$'); xlim([0 T])legend('TEB','CG','BGF','CF','PD','Location','southeast')subplot(1,4,2); hold onplot(t_teb,input_teb(:,2))plot(t_cg,input_cg(:,2))plot(t_bgf,input_bgf(:,2))plot(t_cf,input_cf(:,2))plot(t_pd,input_pd(:,2))%yline(a(1),'-.b')title('$\tau_{roll}\;\;(Nm)$'); xlabel('$t(s)$'); xlim([0 T])legend('TEB','CG','BGF','CF','PD','Location','southeast')subplot(1,4,3); hold onplot(t_teb,input_teb(:,3))plot(t_cg,input_cg(:,3))plot(t_bgf,input_bgf(:,3))plot(t_cf,input_cf(:,3))plot(t_pd,input_pd(:,3))%yline(a(1),'-.b')title('$\tau_{pitch}\;\;(Nm)$'); xlabel('$t(s)$'); xlim([0 T])legend('TEB','CG','BGF','CF','PD','Location','southeast')subplot(1,4,4); hold onplot(t_teb,input_teb(:,4))plot(t_cg,input_cg(:,4))plot(t_bgf,input_bgf(:,4))plot(t_cf,input_cf(:,4))plot(t_pd,input_pd(:,4))%yline(a(1),'-.b')title('$\tau_{yaw}\;\;(Nm)$'); xlabel('$t(s)$'); xlim([0 T])legend('TEB','CG','BGF','CF','PD','Location','southeast')%suptitle('Inputs')set(gcf,'renderer','Painters')if(print_plots==1) printeps(3,strcat('./figs/inputs',label))end%%%%%%%%%%%%%%%%%%% TRAJECTORIES% figure% subplot(3,1,1); hold on% plot(t_teb,get_qd1(t_teb));% plot(t_teb,y_teb(:,init_q));% legend('z_d (m)','z (m)')% % subplot(3,1,2)% hold on% plot(t_teb,(180/pi)*get_qd2(t_teb));% plot(t_teb,(180/pi)*get_qd3(t_teb));% plot(t_teb,(180/pi)*get_qd4(t_teb));% legend('roll_d (deg)','pitch_d (deg)','yaw_d(deg)')% % subplot(3,1,3); hold on% plot3(y_teb(:,1),y_teb(:,2),y_teb(:,3));% plot3(y_cg(:,1),y_cg(:,2),y_cg(:,3));% plot3(y_bgf(:,1),y_bgf(:,2),y_bgf(:,3));% title('3D trajectory'); xlabel('x'); ylabel('y'); zlabel('z'); grid on% legend('TEB','CG','BGF')%%function y=my_sigmoid(t)   global T   y=(1+0.5*sigmoid(t,T/2,80));endfunction [yaw pitch roll]=obtainEulerFromAccelAndYaw(accel,yaw)     %See Mellinger paper (Minimum Snap Trajectory Generation...)    tmp=[accel(1);accel(2);accel(3) + 9.81];    zb=tmp/norm(tmp);    xc=[cos(yaw);sin(yaw);0];    yb=cross(zb,xc)/norm(cross(zb,xc));    xb=cross(yb,zb);    rot_matrix = [xb,yb,zb];    [yaw pitch roll] = rotm2eul(rot_matrix,'ZYX');end

⛄ 运行结果

⛄ 参考文献

[1] Weiping Li and Jean-Jacques E Slotine. An indirect adaptive robot controller. Systems & control letters, 12(3):259–266,1989.

[2] Jean-Jacques E Slotine and Weiping Li. On the adaptive control of robot manipulators. The international journal of robotics research, 6(3):49–59, 1987.

[3] Zachary T Dydek, Anuradha M Annaswamy, and Eugene Lavretsky. Adaptive control of quadrotor uavs: A design trade study with flight evaluations. IEEE Transactions on control systems technology, 21(4):1400–1406, 2013.

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料

🍅 仿真咨询

1 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化
2 机器学习和深度学习方面
卷积神经网络(CNN)、LSTM、支持向量机(SVM)、最小二乘支持向量机(LSSVM)、极限学习机(ELM)、核极限学习机(KELM)、BP、RBF、宽度学习、DBN、RF、RBF、DELM、XGBOOST、TCN实现风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
2.图像处理方面
图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
3 路径规划方面
旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、车辆协同无人机路径规划、天线线性阵列分布优化、车间布局优化
4 无人机应用方面
无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配
5 无线传感器定位及布局方面
传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化
6 信号处理方面
信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化
7 电力系统方面
微电网优化、无功优化、配电网重构、储能配置
8 元胞自动机方面
交通流 人群疏散 病毒扩散 晶体生长
9 雷达方面
卡尔曼滤波跟踪、航迹关联、航迹融合

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值