首页 星云 工具 资源 星选 资讯 热门工具
:

PDF转图片 完全免费 小红书视频下载 无水印 抖音视频下载 无水印 数字星空

A算法路径规划博文附件1.zip

大数据 45MB 18 需要积分: 1
立即下载

资源介绍:

博文详细介绍用MATLAB实现基于A*算法的路径规划的附件1,里面包含了本系列第一和第二篇文章介绍内容的完整代码的matlab文件
%matlab初始化 clc; %清除命令窗口的内容 clear all; %清除工作空间的所有变量,函数,和MEX文件 close all; %关闭所有的figure窗口 %方格数及障碍物比例的设定 n = 20; % 产生一个n x n的方格,修改此值可以修改生成图片的方格数 wallpercent = 0.4; % 这个变量代表生成的障碍物占总方格数的比例 ,如0.5 表示障碍物占总格数的50% %方格以及障碍物的创建 [field, startposind, goalposind, costchart, fieldpointers] =initializeField(n,wallpercent); %随机生成包含障碍物,起始点,终止点等信息的矩阵 % 路径规划中用到的一些矩阵的初始化 setOpen = [startposind]; setOpenCosts = [0]; setOpenHeuristics = [Inf]; setClosed = []; setClosedCosts = []; movementdirections = {'R','L','D','U'}; %移动方向 % 这个函数用来随机生成环境,障碍物,起点,终点 axishandle = createFigure(field,costchart,startposind,goalposind); %将随机生成的方格及障碍物的数据生成图像 %% % 这个while循环是本程序的核心,利用循环进行迭代来寻找终止点 while ~max(ismember(setOpen,goalposind)) && ~isempty(setOpen) [temp, ii] = min(setOpenCosts + setOpenHeuristics); %寻找拓展出来的最小值 %这个函数的作用就是把输入的点作为父节点,然后进行拓展找到子节点,并且找到子节点的代价,并且把子节点距离终点的代价找到 [costs,heuristics,posinds] = findFValue(setOpen(ii),setOpenCosts(ii), field,goalposind,'euclidean'); setClosed = [setClosed; setOpen(ii)]; % 将找出来的拓展出来的点中代价最小的那个点串到矩阵setClosed 中 setClosedCosts = [setClosedCosts; setOpenCosts(ii)]; % 将拓展出来的点中代价最小的那个点的代价串到矩阵setClosedCosts 中 % 从setOpen中删除刚才放到矩阵setClosed中的那个点 %如果这个点位于矩阵的内部 if (ii > 1 && ii < length(setOpen)) setOpen = [setOpen(1:ii-1); setOpen(ii+1:end)]; setOpenCosts = [setOpenCosts(1:ii-1); setOpenCosts(ii+1:end)]; setOpenHeuristics = [setOpenHeuristics(1:ii-1); setOpenHeuristics(ii+1:end)]; %如果这个点位于矩阵第一行 elseif (ii == 1) setOpen = setOpen(2:end); setOpenCosts = setOpenCosts(2:end); setOpenHeuristics = setOpenHeuristics(2:end); %如果这个点位于矩阵的最后一行 else setOpen = setOpen(1:end-1); setOpenCosts = setOpenCosts(1:end-1); setOpenHeuristics = setOpenHeuristics(1:end-1); end %% % 把拓展出来的点中符合要求的点放到setOpen 矩阵中,作为待选点 for jj=1:length(posinds) if ~isinf(costs(jj)) % 判断该点(方格)处没有障碍物 % 判断一下该点是否 已经存在于setOpen 矩阵或者setClosed 矩阵中 % 如果我们要处理的拓展点既不在setOpen 矩阵,也不在setClosed 矩阵中 if ~max([setClosed; setOpen] == posinds(jj)) fieldpointers(posinds(jj)) = movementdirections(jj); costchart(posinds(jj)) = costs(jj); setOpen = [setOpen; posinds(jj)]; setOpenCosts = [setOpenCosts; costs(jj)]; setOpenHeuristics = [setOpenHeuristics; heuristics(jj)]; % 如果我们要处理的拓展点已经在setOpen 矩阵中 elseif max(setOpen == posinds(jj)) I = find(setOpen == posinds(jj)); % 如果通过目前的方法找到的这个点,比之前的方法好(代价小)就更新这个点 if setOpenCosts(I) > costs(jj) costchart(setOpen(I)) = costs(jj); setOpenCosts(I) = costs(jj); setOpenHeuristics(I) = heuristics(jj); fieldpointers(setOpen(I)) = movementdirections(jj); end % 如果我们要处理的拓展点已经在setClosed 矩阵中 else I = find(setClosed == posinds(jj)); % 如果通过目前的方法找到的这个点,比之前的方法好(代价小)就更新这个点 if setClosedCosts(I) > costs(jj) costchart(setClosed(I)) = costs(jj); setClosedCosts(I) = costs(jj); fieldpointers(setClosed(I)) = movementdirections(jj); end end end end %% if isempty(setOpen) break; end set(axishandle,'CData',[costchart costchart(:,end); costchart(end,:) costchart(end,end)]); set(gca,'CLim',[0 1.1*max(costchart(find(costchart < Inf)))]); drawnow; end %% %调用findWayBack函数进行路径回溯,并绘制出路径曲线 if max(ismember(setOpen,goalposind)) disp('Solution found!'); p = findWayBack(goalposind,fieldpointers); % 调用findWayBack函数进行路径回溯,将回溯结果放于矩阵P中 plot(p(:,2)+0.5,p(:,1)+0.5,'Color',0.2*ones(3,1),'LineWidth',4); %用 plot函数绘制路径曲线 drawnow; drawnow; [y,Fs] = audioread('000.wav'); sound(y,Fs); % 播放名为000的音乐,注意该文件需要跟matlab文件位于同一文件夹下, elseif isempty(setOpen) disp('No Solution!'); [y,Fs] = audioread('000.wav'); sound(y,Fs); end %% %findWayBack函数用来进行路径回溯,这个函数的输入参数是终止点goalposind和矩阵fieldpointers,输出参数是P function p = findWayBack(goalposind,fieldpointers) n = length(fieldpointers); % 获取环境的长度也就是n posind = goalposind; [py,px] = ind2sub([n,n],posind); % 将索引值posind转换为坐标值 [py,px] p = [py px]; %利用while循环进行回溯,当我们回溯到起始点的时候停止,也就是在矩阵fieldpointers中找到S时停止 while ~strcmp(fieldpointers{posind},'S') switch fieldpointers{posind} case 'L' % ’L’ 表示当前的点是由左边的点拓展出来的 px = px - 1; case 'R' % ’R’ 表示当前的点是由右边的点拓展出来的 px = px + 1; case 'U' % ’U’ 表示当前的点是由上面的点拓展出来的 py = py - 1; case 'D' % ’D’ 表示当前的点是由下边的点拓展出来的 py = py + 1; end p = [p; py px]; posind = sub2ind([n n],py,px);% 将坐标值转换为索引值 end end %% %这个函数的作用就是把输入的点作为父节点,然后进行拓展找到子节点,并且找到子节点的代价,并且把子节点距离终点的代价找到。 %函数的输出量中costs表示拓展的子节点到起始点的代价,heuristics表示拓展出来的点到终止点的距离大约是多少,posinds表示拓展出来的子节点 function [cost,heuristic,posinds] = findFValue(posind,costsofar,field,goalind,heuristicmethod) n = length(field); % 获取矩阵的长度 [currentpos(1) currentpos(2)] = ind2sub([n n],posind); %将要进行拓展的点(也就是父节点)的索引值拓展成坐标值 [goalpos(1) goalpos(2)] = ind2sub([n n],goalind); %将终止点的索引值拓展成坐标值 cost = Inf*ones(4,1); heuristic = Inf*ones(4,1); pos = ones(4,2); %将矩阵cost和heuristic初始化为4x1的无穷大值的矩阵,pos初始化为4x2的值为1的矩阵 % 拓展方向一 newx = currentpos(2) - 1; newy = currentpos(1); if newx > 0 pos(1,:) = [newy newx]; switch lower(heuristicmethod) case 'euclidean' heuristic(1) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); case 'taxicab' heuristic(1) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); end cost(1) = costsofar + field(newy,newx); end % 拓展方向二 newx = currentpos(2) + 1; newy = currentpos(1); if newx <= n pos(2,:) = [newy newx]; switch lower(heuristicmethod) case 'euclidean' heuristic(2) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); case 'taxicab' heuristic(2) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); end cost(2) = costsofar + field(newy,newx); end % 拓展方向三 newx = currentpos(2); newy = currentpos(1)-1; if newy > 0 pos(3,:) = [newy newx]; switch lower(heuristicmethod) case 'euclidean' heuristic(3) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); case 'taxicab' heuristic(3) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); end cost(3) = costsofar + field(newy,newx); end % 拓展方向四 newx = currentpos(2); newy = currentpos(1)+1; if newy <= n pos(4,:) = [newy newx]; switch lower(heuristicmethod) case 'euclidean' heuristic(4) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); case 'taxicab' heuristic(4) = abs(goalpos(2)-newx) + abs(goalpos(1)-newy); end cost(4) = costsofar + field(n

资源文件列表:

A算法路径规划博文附件1.zip 大约有3个文件
  1. A_ROAD_book1.m 3.34KB
  2. A_ROAD_book2.m 10.92KB
  3. 000.wav 49.25MB
0评论
提交 加载更多评论
其他资源 相关实用应用程序(Windows可用)
相关实用应用程序(Windows可用) 相关实用应用程序(Windows可用) 相关实用应用程序(Windows可用) 相关实用应用程序(Windows可用) 相关实用应用程序(Windows可用)
C#内存修改器(仿CE)
好吧 我承认这东西效率真不咋地 也别喷我的代码 我承认我的代码写的也不咋地 总之 有个思路就行了 是我仿照 CE 的界面做的 不得不说 CE 的搜索速度真的很快 还有就是 这程序 可能存在许多潜在的bug 比如内存溢出 不过我能知道的或者知道怎么解决的问题 我已近解决了 总之 这代码仅供参考
commons-net-1.4.1.zip
Jakarta Common net组件
时序图画图工具-TimeGen3.2安装包
免费下载,小巧好用的时序图画图工具TimeGen3.2安装包和安装使用教程,详细的安装和使用教程见博主《数字IC开发工具》栏目的博文。
最简单的基于FFMPEG的AVDevice的例子 1.2
FFMPEG工程浩大,可以参考的书籍又不是很多,因此很多刚学习FFMPEG的人常常感觉到无从下手。因此做了一个FFmpeg中的libavdevice类库的使用例子。 本工程包含两个基于FFmpeg的libavdevice的例子: simplest_ffmpeg_grabdesktop:屏幕录制。 simplest_ffmpeg_readcamera:读取摄像头。 1.2版本增加了多平台下编译的支持:Windows,MacOS,以及Linux。
C#水波程序(思路)
虽然说 网上已经有了 但是还是自己做了一个出来 其实这程序本从编程角度去说 没啥技术含量 关键是在于怎么操作像素去模拟水波 里面打包有当时写这程序时候的质料
nexus-maven-repository-index.zip
nexus-maven-repository-index.zip
oppo ozip格式转zip ozip2zip工具 ozip解密工具
将OPPO官网下载的ozip格式刷机包转成zip格式的刷机包,方便第三方rec刷入,亲测好用,严重鄙视某些论坛和厂商出的工具 这点东西还收费,目前已整理工具并打包,设置0积分下载,有用点个关注和支持,感谢!!