障碍物规避算法的MATLAB仿真
?
%------main主函數--------------------------------------------------
%------初始格式化--------------------------------------------------
clear all;
clc;
format bank;
%------定義全局變量----------------------------------------------
%-粒子群的-
global c1; ? ? ? ? ? ? %學習因子1
global c2; ? ? ? ? ? ? %學習因子2
global w; ? ? ? ? ? ? ?%慣性權重
global MaxDT; ? ? ? ? ? ?%最大迭代次數
global m; ? ? ? ? ? ? ? ? ?%搜索空間維數(未知數個數)
global N; ? ? ? ? ? ? ? ? ?%初始化群體個體數目
global eps; ? ? ? ? ? %設置精度(在已知最小值時候用)
global Kmax; ? ? ? ? ?%初始化x時用的最大迭代次數
global Qmax; ? ? ? ? ?%初始化x時粒子全部重新初始化用的最大迭代次數
global fitw1; ? ? ? ? %適應值函數中的兩個權重
global fitw2;
global pathta ; ? ? ? %移動的角度為60度
global psosued; ? ? ? ? %粒子群成功
global pathsued; ? ? ? ?%路徑可行
%-路徑規劃的-
global robotv; ? ? ? ? ?%機器人半徑
global s; ? ? ? ? ? ? ? %起始點
global g; ? ? ? ? ? ? ? %目標點
global obstaclesx; ? ? ? %障礙物點
global obstaclesy;
global Nsteps; ? ? ? ? ?%機器人最多能移動的步數
global ploR; ? ? ? ? ? ?%極坐標半徑
global segR; ? ? ? ? ? ?%極坐標的分段半徑
global mapmin; ? ? ? ? % 地圖大小
global mapmax;
global curpoint; ? ? ? ?%當前點的位置
global hadsteps; ? ? ? ?%只記錄curpoint的集:鏈表一樣
global curstep; ? ? ? ? %當前的步數
global rangOb; ? ? ? ? ?%在粒子范圍內的障礙物點
global obIndex; ? ? ? ? %記錄在粒子范圍內的障礙物點的索引
global goalLine; ? ? ? ?%記錄當前點和目標點之間連線的方程
global movelen; ? ? ? ? %機器人移動長度
global V; ? ? ? ? ? ? ? %機器人的速度(矢量)
global pointIndex; ? ? ?%記錄點的索引
global pathpoint; ? ? ? %記錄所有的點
global goalta ? ? ? ? ? ? ? %當前點到目標點的角度
global numta; ? ? ? ? ? %把圈分為幾個角
global pamoveta; ? ? ? ?%粒子的可行角度,維數由numta定
global searchsued; ? ? ?%是否搜索成功
%-------初始化矩陣----------------------------------------------
initial;
%pause;
%-------開始尋找路徑--------------------------------------------
result = pathplanning();?
if result == 1
? ? disp('找到路徑');
? ? hadsteps(curstep+1,1) = g(1);
? ? hadsteps(curstep+1,2) = g(2);
else
? ? disp('路徑找不到');
end
%-最后處理-----------------------------
pointIndex = pointIndex+1;
pathpoint(pointIndex,1) = g(1);
pathpoint(pointIndex,2) = g(2);
pathpoint
%-------畫---------------------------------------
figure(1)
hold on
%plot(pathpoint(:,1),pathpoint(:,2),'r-')
?plot(hadsteps(:,1),hadsteps(:,2),'b-')
hold off
%plot(pathpoint);
?
D-122
總結
以上是生活随笔為你收集整理的障碍物规避算法的MATLAB仿真的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 连续连通域检测算法的MATLAB仿真
- 下一篇: Monte Carlo仿真方法的基本思想