数据来源
无人艇项目
算法数学模型
- 微分计算
2. USV在不同速度下,受到的阻力不一样。系统能够提供的推力,也不一样。
3. 由于空泡的影响,当速度不断增大时,推力会明显下降。因此,对于船体的稳定性,空泡有着明显的差别。因此,船体的设计,非常重要啊
4. 对于不同结构的船体,空泡有着不同程度的影响。
算法目标
基于USV在不同速度下的阻力、推力,计算USV从静止到加速至一定速度,所需要的时间,进行计算。
避障算法I/O:
Input:
Output:
仿真算法过程:
前提是梳理全国成果,建模、准备数据、理清思路。
第一步:数据插值
步长是定为0.05,即单个间隔是50毫秒。
x = 0:pi/4:2*pi;
v = sin(x);
xq = 0:pi/16:2*pi;
vq1 = interp1(x,v,xq);
vq2 = interp1(x,v,xq,'spline');
figure
vq1 = interp1(x,v,xq);
plot(x,v,'o',xq,vq1,':.');
xlim([0 2*pi]);
title('(Default) Linear Interpolation');
现在使用 'spline'
方法计算相同点处的 v
。
figure
vq2 = interp1(x,v,xq,'spline');
plot(x,v,'o',xq,vq2,':.');
xlim([0 2*pi]);
title('Spline Interpolation');
第二步:计算单步变量
第三步:循环结构
算法代码:
function Differential_calculation
% ruogu7(380545156@qq.com)
% Start: Am 10:14 Mar. 20th, 2020
% End: Pm 10:14 Mar. 20th, 2020
% Example:
clc; clear all;
% extract the data from excel file
[numdata,textdata,alldata] = xlsread('data.xls');
String_alldata = string(numdata);
Cleandata = String_alldata(3:end,1:end-1);
numdata = str2double(Cleandata);
%% ²åÖµ
k = 1:size(numdata,1)
kq = 1:0.05:size(numdata,1) % ²½³¤Îª0.05s
speed_Interpolation = interp1(k,numdata(:,1),kq) % ÏßÐÔ²åÖµ
resistance_Interpolation = interp1(k,numdata(:,7),kq,'nearest') % ÁÙ½ü²åÖµ
drivingforce_Interpolation = interp1(k,numdata(:,8),kq,'nearest') % ÁÙ½ü²åÖµ
kk = 1; % ËٶȵıêºÅ
real_speed = 22 + 0.0000000001;
for ii = 1:10000000
bb = find(speed_Interpolation < real_speed);
kk = size(bb,2) + 1
acce = ((drivingforce_Interpolation(kk)-resistance_Interpolation(kk))/9/1.15/1852)*3600;
Dotar_speed = acce*0.05;
real_speed = real_speed + Dotar_speed
if real_speed > 35
time_used = 0.05 * ii
break;
end
end
%%
% x = 0:pi/4:2*pi;
% v = sin(x);
% xq = 0:pi/16:2*pi;
% vq1 = interp1(x,v,xq);
% vq2 = interp1(x,v,xq,'spline');
代码优化,编程了函数,方便调用,同时也增加了一个统计结果,就是累计距离
function [time, distance] = timedistance4accelaration (usvweight, speed_start,speed_end)
% ruogu7(380545156@qq.com)
% Start: Am 10:14 Mar. 20th, 2020
% End: Pm 10:14 Mar. 20th, 2020
% Example:
% [time, distance] = timedistance4accelaration (8, 0, 12)
% [time, distance] = timedistance4accelaration (8, 12, 25)
% [time, distance] = timedistance4accelaration (8, 25, 35)
% [time, distance] = timedistance4accelaration (8, 35, 40)
%% clc; clear all;
% extract the data from excel file
[numdata,textdata,alldata] = xlsread('data_0321.xls');
String_alldata = string(numdata);
Cleandata = String_alldata(1:23,1:8);
numdata = str2double(Cleandata);
%% 插值
k = 1:size(numdata,1) ;
kq = 1:0.02:size(numdata,1) ; % 步长为0.05s
speed_Interpolation = interp1(k,numdata(:,1),kq); % 线性插值
if usvweight == 8
resistance_vector = numdata(:,3);
end
if usvweight == 8.5
resistance_vector = numdata(:,5);
end
if usvweight == 9
resistance_vector = numdata(:,7);
end
resistance_Interpolation = interp1(k,resistance_vector,kq,'nearest'); % 临近插值
drivingforce_Interpolation = interp1(k,numdata(:,8),kq,'nearest'); % 临近插值
kk = 1; % 速度的标号
real_speed = speed_start + 0.000000000001;
distance_period = 0;
distance =0;
for ii = 1:10000000
bb = find(speed_Interpolation < real_speed);
kk = size(bb,2) + 1
acce_weight = ((drivingforce_Interpolation(kk)-resistance_Interpolation(kk))/1.15/1852)*3600;
acce = acce_weight/usvweight
Dotar_speed = acce*0.02;
real_speed = real_speed + Dotar_speed;
Dotar_distance = (real_speed + Dotar_speed*0.5)*0.02; % 取阶段平均速度
distance = distance + Dotar_distance;
if real_speed > speed_end
time = 0.02 * ii;
break;
end
end