使用模型预测控制对USV进行自主控制(Matlab代码实现)

    目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码

💥1 概述

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

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

📚2 运行结果

主函数部分代码:

clear
close all
​
%Boat and simulation parameters
m = 37;         %Mass of the boat
D = 0.7;        %Distance between the motors and the center of mass
I = 0.1;        %Moment of inertia      (arbitrary value, should be identified)
k = 0.1;        %Viscosity coefficient  (arbitrary value, should be identified)
Tfinal = 150;   %Total simulation time
Te = 0.1;       %Sampling period
​
%Vectors used to hold simulation data
x = zeros(7, ceil(Tfinal/Te));          %State vector
u = zeros(2, ceil(Tfinal/Te));          %Input vector
delta_u = zeros(2, ceil(Tfinal/Te));    %Input increment vector
a = zeros(3, ceil(Tfinal/Te));          %State vector
i = 1;                                  %Loop index
​
​
​
%Ordered list of waypoints
x_list = [2 4 32 40 25 10 2]';  %X coordinates of the waypoints
y_list = [2 15 17 7 0 -5 2]';   %Y coordinates of the waypoints
a_list = zeros(7,1);            %Angle of the boat between two successive waypoints
current_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 pi
for j=1:7
   a_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) < 0
      a_list(j,1) = a_list(j,1);
   end
end
​
%Objectives list containing X,Y and Theta coordinates
r_list = [x_list y_list a_list];
nb_obj = size(r_list,1);                %Number of objectives
​
%MPC horizons
nu = 2;         %Control horizon (dof of the optimization problem)  
ny = 30;        %Prediction horizon
​
%State-space system used for the MPC
a(:,i) = [0 0 1.4181]';                 %Initial conditions : the boat is in the correct orientation
                                        %And has null angular speed and acceleration
u(:,i) = [k/2 k/2]';                    %Initial condition on the command : to maintain a speed of 1m/s
delta_u(:,i) = [0 0]';                  %Initial condition on the input increments
​
%System matrices
A = [1  0 0;...                         %State matrix
     Te 1 0;...
     0 Te 1];
B = [D/(2*I) -D/(2*I); 0 0; 0 0];       %Input matrix
​
%Augmented system matrices
A_tilde = [A B; zeros(2,3), eye(2)];    %State matrix
B_tilde = [zeros(3,2); eye(2)];         %Input matrix
C_tilde = [0 0 1 0 0];                  %Output matrix
n_output = size(C_tilde,1);                    %Dimension of the output
n_input = size(B,2);            %Number of inputs
n_state = size(B,1);            %Number of state variables
​
%State-space system used to provide an angle reference vector
x(:,i) = [2 2 1.4181 0 0 1 0]';         %State initial condition : the boat is in the first waypoint
                                        %and correctly oriented
Fx = [1 0 0 0 0 Te*cos(x(3,i)) 0;...    %Linearized state matrix
      0 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 matrix               
      D/(2*I) -D/(2*I); 0 0; 1/m 1/m];
​
r = zeros(n_output*ny,1);                      %Angle reference vector
​
%Matrices used for optimization
gainS = computeGainS(n_output, 1);             %Steady-state gain
gainQ = computeGainQ(n_output, 1);             %Running cost gain on the output
gainR = computeGainR(2, 1);             %Running cost gain on the input
Qbar = 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 quiet
options = 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 objectives
    tmp = x(:,i);           %Get the current state
    obj = current_obj;      %Get the current objective
    
    %Compute the angle of the line between the boat and the next waypoint
    goal_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 circle
    dist = abs(goal_angle - tmp(3,1));
    if dist > pi
        if tmp(3,1) < 0
            goal_angle = tmp(3,1) - (2*pi - dist);
        else
            goal_angle = tmp(3,1) + (2*pi - dist);
        end
    end
 

🎉3 参考文献

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

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

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 无人是一种没有人工驾驶员的水上只,它通过自动化技术和无线通信技术实现自主航行。在无人的研发过程中,使用数学模型有助于对其进行建模和仿真分析。 Matlab是一种常用的科学计算软件,可以用于数学建模和仿真。通过Matlab,可以基于无人的物理性质和条件,建立相应的数学模型,对其运行和稳定性进行研究。 在构建无人Matlab数学模型时,需要考虑体的运动学和动力学性质。通过定义体的姿态角、位置和速度等参数,可以建立体的运动方程和力学模型。同时,还需要考虑到环境因素对体的影响,如水流和风力等因素,这些因素可以添加到数学模型中。 除了体的运动,还可以在数学模型中考虑无人的导航和路径规划。通过定义目标点和障碍物,可以使用数学算法和优化方法,制定出最佳的航线和跟踪控制策略,从而实现无人自主航行和避障。 此外,通过在Matlab中建立数学模型,还可以对无人的传感器和通信系统进行仿真分析。例如,通过定义传感器的参数和性能指标,可以模拟传感器的工作原理,并对传感器数据进行处理和融合,实现对环境的感知和识别。同时,可以使用Matlab中的通信工具箱,模拟无人与地面站之间的无线通信,验证通信的可靠性和稳定性。 总之,无人Matlab数学模型可以帮助研究人员理解体的运动和控制特性,优化航线规划和避障算法,同时也可以用于系统设计和性能评估。通过Matlab的强大计算和仿真功能,无人的研发和应用将更加高效和可靠。 ### 回答2: 无人是一种自主导航、自主控制只,通过使用传感器和控制算法,能够自主航行和执行任务。在设计和开发无人时,数学模型是非常重要的工具之一,而MATLAB是一个强大的数学建模和仿真平台,可以用于构建无人数学模型无人数学模型可以包括以下几个方面: 1. 运动学模型:包括位置、速度和加速度等相关参数,用于描述无人的运动特性。可以使用方程组来表示无人的运动学模型,通过MATLAB进行建模和仿真,可以更好地理解和预测无人的行为。 2. 动力学模型:用于描述无人的动力学特性,包括推进力、阻力和转向特性等。可以建立基于物理定律的动力学方程,通过MATLAB进行数值模拟和优化,可以辅助无人控制算法设计。 3. 控制系统模型:用于描述无人控制系统,包括传感器、执行器和控制算法等。可以使用MATLAB进行系统建模、设计和仿真,可以验证控制算法的性能,并进行性能调整和改进。 通过MATLAB构建无人数学模型,可以对无人的运动特性、动力学特性和控制系统进行详细的分析和仿真。这样可以更好地理解无人的行为和性能,并进行优化和改进,从而更好地满足无人任务的要求。同时,MATLAB还提供了丰富的工具箱和函数库,可以方便地进行数据处理、算法设计和性能评估,为无人的设计和开发提供强大的支持。 ### 回答3: 无人Matlab数学模型是指在Matlab软件环境中使用数学模型来描述和预测无人的运动特性和行为。无人是一种自动驾驶的只,通过集成的传感器和控制系统来实现自主航行和任务执行。 在建立无人Matlab数学模型时,需要考虑以下几个方面: 1. 基本参数和环境因素:包括无人的尺寸、质量、水动力系数以及环境中的风力、水流等因素。 2. 运动方程:根据牛顿力学定律和体运动特性,建立无人的运动方程,其中包括体的速度、加速度和转角等参数。 3. 控制系统:设计无人控制系统,包括姿态控制、轨迹规划和路径跟踪等模块,以保持体的稳定和精确导航。 4. 传感器模型:考虑无人的传感器,如GPS、惯性测量单元(IMU)、雷达等,建立相应的测量模型,用于实时获取环境信息。 5. 任务模型:根据无人的具体任务需求,设计相应的任务模型,例如搜索、救援、海洋测绘等。 通过将以上几个方面的数学模型集成在一起,并在Matlab进行编程和仿真,我们可以对无人的运动和行为进行模拟和预测。这样的模型可以帮助我们评估无人的性能、优化控制算法,并指导无人的实际应用。此外,还可以通过模型进行虚拟仿真,提前解决一些潜在问题,提高无人的安全性和可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值