失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 【无人船】基于模型预测控制(MPC)对USV进行自主控制(Matlab代码实现)

【无人船】基于模型预测控制(MPC)对USV进行自主控制(Matlab代码实现)

时间:2018-10-27 21:04:10

相关推荐

【无人船】基于模型预测控制(MPC)对USV进行自主控制(Matlab代码实现)

👨‍🎓个人主页:研学社的博客

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现

💥1 概述

无人船(unmanned surface vehicles,USV)是一种船端无人操控的水面船舶,近年来受到了广泛关注。如何实现自主航行是USV面临的核心问题,而设计一种具有精确航迹控制能力的运动控制器是解决该问题的基础。

本文介绍了一种模型预控制(MPC)算法,旨在自动驾驶无人水面车辆(USV)驶向一组航路点。该算法的设计被认为对海洋环境中遇到的环境扰动具有鲁棒性。USV和扰动的建模已经简化,因为这项工作旨在证明概念:对于现实世界的实施,应该考虑更准确的建模。

📚2 运行结果

主函数部分代码:

clearclose all​%Boat and simulation parametersm = 37; %Mass of the boatD = 0.7; %Distance between the motors and the center of massI = 0.1; %Moment of inertia(arbitrary value, should be identified)k = 0.1; %Viscosity coefficient (arbitrary value, should be identified)Tfinal = 150; %Total simulation timeTe = 0.1; %Sampling period​%Vectors used to hold simulation datax = zeros(7, ceil(Tfinal/Te));%State vectoru = zeros(2, ceil(Tfinal/Te));%Input vectordelta_u = zeros(2, ceil(Tfinal/Te)); %Input increment vectora = zeros(3, ceil(Tfinal/Te));%State vectori = 1; %Loop index​​​%Ordered list of waypointsx_list = [2 4 32 40 25 10 2]'; %X coordinates of the waypointsy_list = [2 15 17 7 0 -5 2]'; %Y coordinates of the waypointsa_list = zeros(7,1); %Angle of the boat between two successive waypointscurrent_obj = 2;%As the boat starts in the first waypoint, the current objective is the next%ie. the second waypoint​%Compute all the angles between two successive waypoints%The angles returned are between -pi and pifor j=1:7a_list(mod(j,7)+1,1) = angle(complex(x_list(mod(j,7)+1)-x_list(j), y_list(mod(j,7)+1)-y_list(j)));if a_list(j,1) < 0a_list(j,1) = a_list(j,1);endend​%Objectives list containing X,Y and Theta coordinatesr_list = [x_list y_list a_list];nb_obj = size(r_list,1);%Number of objectives​%MPC horizonsnu = 2; %Control horizon (dof of the optimization problem) ny = 30; %Prediction horizon​%State-space system used for the MPCa(:,i) = [0 0 1.4181]'; %Initial conditions : the boat is in the correct orientation%And has null angular speed and accelerationu(:,i) = [k/2 k/2]';%Initial condition on the command : to maintain a speed of 1m/sdelta_u(:,i) = [0 0]'; %Initial condition on the input increments​%System matricesA = [1 0 0;...%State matrixTe 1 0;...0 Te 1];B = [D/(2*I) -D/(2*I); 0 0; 0 0]; %Input matrix​%Augmented system matricesA_tilde = [A B; zeros(2,3), eye(2)]; %State matrixB_tilde = [zeros(3,2); eye(2)]; %Input matrixC_tilde = [0 0 1 0 0]; %Output matrixn_output = size(C_tilde,1);%Dimension of the outputn_input = size(B,2); %Number of inputsn_state = size(B,1); %Number of state variables​%State-space system used to provide an angle reference vectorx(:,i) = [2 2 1.4181 0 0 1 0]'; %State initial condition : the boat is in the first waypoint%and correctly orientedFx = [1 0 0 0 0 Te*cos(x(3,i)) 0;... %Linearized state matrix0 1 0 0 0 Te*sin(x(3,i)) 0;...0 0 1 Te 0 0 0;...0 0 0 1 Te 0 0;...0 0 0 0 1 0 0;...0 0 0 0 0 1 Te;...0 0 0 0 0 -k/m 1];Fu = [0 0; 0 0; 0 0; 0 0;... %Linearized input matrixD/(2*I) -D/(2*I); 0 0; 1/m 1/m];​r = zeros(n_output*ny,1); %Angle reference vector​%Matrices used for optimizationgainS = computeGainS(n_output, 1); %Steady-state gaingainQ = computeGainQ(n_output, 1); %Running cost gain on the outputgainR = computeGainR(2, 1); %Running cost gain on the inputQbar = computeQbar(C_tilde, gainQ, gainS, ny);Tbar = computeTbar(gainQ, C_tilde, gainS, ny);Rbar = computeRbar(gainR, nu);Cbar = computeCbar(A_tilde, B_tilde, ny, nu);Abar = computeAbar(A_tilde, ny);Hbar = computeHbar(Cbar, Qbar, Rbar);Fbar = computeFbar(Abar, Qbar, Cbar, Tbar);​%Quadprog solver options%Keep the solver quietoptions = optimoptions('quadprog');options = optimoptions(options, 'Display', 'off');​for t=0:Te:(Tfinal-1)a_tilde = [a(:,i); u(:,i)]; %Build the augmented state space vector for MPC%Compute the ny next angle objectivestmp = x(:,i); %Get the current stateobj = current_obj;%Get the current objective%Compute the angle of the line between the boat and the next waypointgoal_angle = angle(complex(r_list(obj,1)-tmp(1,1), r_list(obj,2)-tmp(2,1)));%If the distance between the goal angle and the current angle is%greater than pi, it means that there is a shorter path to this angle%than getting all the way around the unit circledist = abs(goal_angle - tmp(3,1));if dist > piif tmp(3,1) < 0goal_angle = tmp(3,1) - (2*pi - dist);elsegoal_angle = tmp(3,1) + (2*pi - dist);endend

🎉3 参考文献

[1]柳晨光. 基于预测控制的无人船运动控制方法研究[D]. 武汉理工大学.

部分理论引用网络文献,若有侵权联系博主删除。

🌈4 Matlab代码实现

如果觉得《【无人船】基于模型预测控制(MPC)对USV进行自主控制(Matlab代码实现)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。