当前位置: 首页 > news >正文

【路径规划】基于RRT算法机器人最短路径规划matlab代码

​1 简介

移动机器人运动规划技术是自主移动机器人导航的核心技术之一,而路径规划技术是导航技术研究的一个关键课题.路径规划的任务是:依据一定的评价准则(如距离最短,时间最短,工作代价最小等等),在一个存在障碍物的工作环境内,寻求一条从初始点开始到目标点结束的较优的无碰撞路径.本文旨在结合实际环境基于快速扩展随机树(Rapidly-Exploring Random Tree, RRT)算法实现自主移动机器人的路径规划。​

2 部分代码

%*************************************** %% ????? clear all; close all; x_I=1; y_I=1; % ????? x_G=700; y_G=700; % ????? Thr=50; % ??????? Delta= 30; % ?????? NearDelta= 60; % ??near????? %% ????? T.v(1).x = x_I; % T????????v??????????????T??? T.v(1).y = y_I; T.v(1).xPrev = x_I; % ?????????????? T.v(1).yPrev = y_I; T.v(1).dist=0; % ???????????????????? T.v(1).rootDist=0; % ???????????????????? T.v(1).indPrev = 0; % T.v(1).p = []; % ????????????? %% ?????棗???? figure(1); ImpRgb=imread('newmap.png'); Imp=rgb2gray(ImpRgb); imshow(Imp) xL=size(Imp,1); yL=size(Imp,2); hold on plot(x_I, y_I, 'ro', 'MarkerSize',10, 'MarkerFaceColor','r'); plot(x_G, y_G, 'go', 'MarkerSize',10, 'MarkerFaceColor','g'); count=1; found = 0; updateFlag = 0; solutionEndIdx = -1; solutionIdxSet = []; solutionEllipse = inf; for iter = 1:4000 %Step 1: ???????????x_rand,????????????? x_rand=[xL, yL].*rand(1,2); if norm(x_rand - [x_I,y_I])+norm(x_rand - [x_G,y_G])> solutionEllipse continue; end %Step 2: ?????????????? x_phase1_near x_phase1_near=[]; min_dis_toT = inf; for i = 1:length(T.v) t_node = T.v(i); t_nodexy = [t_node.x, t_node.y]; dis_toT = norm(t_nodexy - x_rand); if dis_toT < min_dis_toT min_dis_toT = dis_toT; x_phase1_near = t_nodexy; end end %Step 3: ????x_new?? dxy = x_rand - x_phase1_near; dxynorm = dxy/norm(dxy); x_new = x_phase1_near + dxynorm*Delta; if ~collisionChecking(x_new,[],Imp) continue; end %Step 3: ??????x_new?????x_link,???near?? near_set = []; min_dis_toT = inf; x_link_idx = -1; for i = 1:length(T.v) t_node = T.v(i); t_nodexy = [t_node.x, t_node.y]; dis_toT = norm(t_nodexy - x_new); if dis_toT < NearDelta && collisionChecking(x_new,t_nodexy,Imp) near_set = [near_set;t_nodexy, i]; curDist = dis_toT + T.v(i).rootDist; if min_dis_toT > curDist min_dis_toT = curDist; x_link_idx = i; end end end if x_link_idx == -1 continue; end x_link = [T.v(x_link_idx).x,T.v(x_link_idx).y]; %Step 4: ?x_new???T %??????x_new?????x_link count=count+1; T.v(count).x = x_new(1); T.v(count).y = x_new(2); T.v(count).xPrev = x_link(1); T.v(count).yPrev = x_link(2); T.v(count).dist=norm(x_new - x_link); T.v(count).rootDist= T.v(x_link_idx).rootDist + norm(x_new - x_link); T.v(count).indPrev = x_link_idx; T.v(count).p = plot([x_link(1), x_new(1)],[x_link(2), x_new(2)], 'r', 'marker', '.'); drawnow; %Step 5:??rewire updateFlag = 0; x_new_idx = count; % disp(['cur is ', num2str(curNodeIdx), 'link to ', num2str(selected_nea_idx)]) for i = 1:size(near_set, 1) node_xy = near_set(i,1:2); node_idx = near_set(i,3); % ???x_new??? if node_idx == x_new_idx continue; end dist = norm(x_new - node_xy); if T.v(node_idx).rootDist > T.v(x_new_idx).rootDist + dist updateFlag = 1; T.v(node_idx).rootDist = T.v(x_new_idx).rootDist + dist; T.v(node_idx).xPrev = x_new(1); T.v(node_idx).yPrev = x_new(2); T.v(node_idx).dist = dist; T.v(node_idx).indPrev = x_new_idx; delete(T.v(node_idx).p) T.v(node_idx).p = plot([x_new(1), node_xy(1)],[x_new(2), node_xy(2)], 'r', 'marker', '.'); drawnow; end end %Step 6:????????????? if norm(x_new-[x_G,y_G]) < Thr && collisionChecking(x_new,[x_G,y_G],Imp) && found == 0 % ??[x_G y_G]?? count=count+1; solutionEndIdx = count; T.v(count).x = x_G; T.v(count).y = y_G; T.v(count).xPrev = x_new(1); T.v(count).yPrev = x_new(2); T.v(count).dist=norm(x_new - [x_G,y_G]); T.v(count).rootDist= T.v(x_new_idx).rootDist + norm(x_new - [x_G,y_G]); T.v(count).indPrev = x_new_idx; T.v(count).p = plot([x_new(1), x_G],[x_new(2), y_G], 'r', 'marker', '.'); found = 1; % ??[x_I x_I]?x_new ??????????? pathIndex = solutionEndIdx; solutionIdxSet = [pathIndex]; set(T.v(pathIndex).p, 'color', 'b','Linewidth', 3); for k = 1:1000 pathIndex = T.v(pathIndex).indPrev; if pathIndex == 1 break end solutionIdxSet = [solutionIdxSet, pathIndex]; set(T.v(pathIndex).p, 'color', 'b','Linewidth', 3); end % ???????? drawnow; end %Step 7: ???????????????????????????????????? if found == 1 && updateFlag == 1 % ?????? solutionEllipse = -inf; for i = 1:length(solutionIdxSet) set(T.v(solutionIdxSet(i)).p, 'color', 'r','Linewidth', 1); node_xy = [T.v(solutionIdxSet(i)).x,T.v(solutionIdxSet(i)).y]; if solutionEllipse < norm(node_xy - [x_I,y_I])+norm(node_xy - [x_G,y_G]) solutionEllipse = norm(node_xy - [x_I,y_I])+norm(node_xy - [x_G,y_G]); end end % ??????????? pathIndex = solutionEndIdx; solutionIdxSet = [pathIndex]; set(T.v(pathIndex).p, 'color', 'b','Linewidth', 3); for k = 1:1000 pathIndex = T.v(pathIndex).indPrev; if pathIndex == 1 break end solutionIdxSet = [solutionIdxSet, pathIndex]; set(T.v(pathIndex).p, 'color', 'b','Linewidth', 3); end % ???????? drawnow; end end

3 仿真结果

4 参考文献

[1]朱宏辉, 王嘉豪. 一种移动机器人路径规划新算法[J]. 计算机测量与控制, 2020, 28(11):6.

http://www.cnnetsun.cn/news/4014851.html

相关文章:

  • 厦门网站建设cnmxcm:为什么你的企业网站总是没人看?揭秘幕后真相与避坑指南
  • 谷歌 Pixel 11 Pro 推出 HiLight 指示灯,简约怀旧体验能否回归?
  • 揭秘叶县建设局网站背后的民生温度与工程品质
  • 如何低成本快速建设一个微商的网站并实现销量爆发式增长全攻略
  • 网站建设中页面下载的重要性及优化策略
  • 2024年光泽网站建设实战指南:中小企业如何用高性价比策略在搜索引擎突围并实现品牌数字化升级
  • 从零基础到行业标杆:为什么安康中小企业选择安康鼎盛网站建设能少走五年弯路?
  • 2026出海警示:这3个跨境平台“隐形收费”正吃掉你三成利润,老卖家亲历避坑指南
  • 个人网站建设优化:新手避坑指南与实战策略
  • 深耕辽宁大地:辽宁城乡建设网站如何以专业视角重塑城市美学与民生温度
  • 做网站不是搭积木而是做生意深度解析太原营销型网站建设制作的核心逻辑与避坑指南
  • 太原二级活性炭吸附箱
  • 小龙虾安装向导步步截图详解,TopClaw自动部署三分钟零编程体验
  • Linux-进程1
  • 10分钟搞定ESP32!从编译、烧写到运行全流程详解
  • 广东网站建设公司xywdl如何打造高转化率企业官网全解析与避坑指南
  • 大兴网站开发网站建设报价背后的真相与选择指南
  • 建站团队揭秘:专业网站建设所需人员配置及核心职责详解
  • 群晖与CentOS双实例部署网心云Docker:网络与存储隔离实战
  • Rsyslog配置深度解析:从核心概念到高可用日志处理架构实战
  • 当 AI 真正接入硬件:GaryCLI 如何用极低 API 成本,在 2 分钟内跑通 STM32 开发闭环
  • 从布莱克斯通比率到系统阈值:如何量化决策中的错误代价与容错率
  • 苗木企业网站建设源代码解析:如何让您的园林生意在线上“枝繁叶茂”并落地生根
  • 一天内用AI构建Netty MVC框架:探索AI编程的工程实践与边界
  • 从0到1打造高收益平台:深度解析投资理财网站建设的关键要素与实战策略
  • 专业级电子商务网站建设asp sql 源码下载指南:从零搭建高并发电商平台的实战干货
  • 南阳网站建设哪家好?老板避坑指南,揭秘正规靠谱团队那些事儿
  • 贵阳网站建设q479185700惠 揭秘中小企业如何用最低预算打造高转化官网并规避隐形陷阱
  • 道路建设去什么网站能看到最新进展和官方信息
  • 做cms网站建设方案选对工具比努力更重要,新手必看避坑指南