✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
移动机器人导航是移动机器人研究的关键技术,而路径规划是移动机器人导航的重要组成部分,也是机器人行进过程中运动控制的依据。路径规划的任务可以描述为:按照一定的评价标准,在含有障碍的环境中,搜索从起始点到终点的一条无碰路径。通过栅格法建立栅格地图作为机器人路径规划的工作环境,采用蜣螂算法作为机器人路径搜索的规则.将所有机器人放置于初始位置,经过NC次无碰撞迭代运动找到最优路径,到达目标位置.
⛄ 部分代码
col = G(:,j+1); % 地图的一列
id = find(col == 0); % 该列自由栅格的位置
X(i,j) = id(randi(length(id))); % 随机选择一个自由栅格
id = [];
end
fit( i ) = fitness(X( i, : ),G);
end
fpbest = fit; % 个体最优适应度
pX = X; % 个体最优位置
XX=pX;
[fgbest, bestIndex] = min( fit ); % 全局最优适应度
bestX = X(bestIndex, : ); % 全局最优位置
[fmax,B]=max(fit);
worse= X(B,:);
%%
for gen = 1 : maxgen
gen
[ ans, sortIndex ] = sort( fit );% Sort.
[fmax,B]=max( fit );
worse= X(B,:);
[~, Idx] = sort( fpbest );
r2=rand(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i = 1 : pNum
if(r2<0.9)
r1=rand(1);
a=rand(1,1);
if (a>0.1)
a=1;
else
a=-1;
end
X( i , : ) = pX( i , :)+0.3*abs(pX(i , : )-worse)+a*0.1*(XX( i , :)); % Equation (1)
else
aaa= randperm(180,1);
if ( aaa==0 ||aaa==90 ||aaa==180 )
X( i , : ) = pX( i , :);
end
theta= aaa*pi/180;
X( i , : ) = pX( i , :)+tan(theta).*abs(pX(i , : )-XX( i , :)); % Equation (2)
end
X( i , :) = Bounds(X(i , : ), Xmin, Xmax );
fit( i ) = fitness( X( i , : ),G );
end
[ fMMin, bestII ] = min( fit );
bestXX = X( bestII, : );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
R=1-gen/maxgen; %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xnew1 = bestXX.*(1-R);
Xnew2 =bestXX.*(1+R); %%% Equation (3)
Xnew1= Bounds(Xnew1, Xmin, Xmax );
Xnew2 = Bounds(Xnew2, Xmin, Xmax );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Xnew11 = bestX.*(1-R);
Xnew22 =bestX.*(1+R); %%% Equation (5)
Xnew11= Bounds(Xnew11, Xmin, Xmax );
Xnew22 = Bounds(Xnew22, Xmin, Xmax );
for i = ( pNum + 1 ) :12 % Equation (4)
X( i, : )=bestXX+((rand(1,dim)).*(pX( i , : )-Xnew1)+(rand(1,dim)).*(pX( i , : )-Xnew2));
X( i , :) = Bounds(X(i , : ), min(Xnew1), max(Xnew2) );
fit( i ) = fitness( X( i , : ),G );
end
for i = 13: 19 % Equation (6)
X( i, : )=pX( i , : )+((randn(1)).*(pX( i , : )-Xnew11)+((rand(1,dim)).*(pX( i , : )-Xnew22)));
X( i , :) = Bounds(X(i , : ), Xmin, Xmax );
fit( i ) = fitness( X( i , : ),G );
end
for j = 20 : NP % Equation (7)
X( j,: )=bestX+randn(1,dim).*((abs(( pX(j,: )-bestXX)))+(abs(( pX(j,: )-bestX))))./2;
X( j , :) = Bounds(X(j , : ), Xmin, Xmax );
fit( j ) = fitness( X( j , : ),G );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
XX=pX;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 更新个体最优值和全局最优值
for i = 1 : NP
if (fit(i) < fpbest(i))
fpbest(i) = fit(i);
pX(i, :) = X(i, :);
end
if(fpbest(i) < fgbest)
fgbest = fpbest(i);
bestX = pX(i, :);
end
end
bestX = LocalSearch(bestX,Xmax,G);
fgbest = fitness(bestX,G);
FG(gen,1)=fgbest;
⛄ 运行结果
⛄ 参考文献
[1] 周东健, 张兴国, 马海波,等. 基于栅格地图-蚁群算法的机器人最优路径规划[J]. 南通大学学报:自然科学版, 2013, 12(4):4.
[2] 刘琳琳. 基于栅格地图环境的机器人路径规划算法[J]. 机电信息, 2018(30):3.
[3] 陈晓娥, 苏理. 一种基于环境栅格地图的多机器人路径规划方法[J]. 机械科学与技术, 2009(10):5.
[4] 何佳泽, 张寿明. 基于优化算法的移动机器人全局路径规划[J]. 化工自动化及仪表, 2021, 48(4):5.
[5] 樊啸宇. 基于优化蚁群算法的智能机器人路径规划研究[J]. 中国科技纵横, 2018.
[6] 余翀, 邱其文. 基于栅格地图的分层式机器人路径规划算法[J]. 中国科学院研究生院学报, 2013.