当前位置: 首页 > 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.jsqmd.com/news/1389636/

相关文章:

  • MathorCup数学建模竞赛:从团队组建到实战策略的完整指南
  • 新电脑首次安装通讯软件前的安全核对清单
  • 驾驶事故处理策略
  • 大数据中的“数据倾斜“问题分析
  • 浏览器Agent的DOM处理管线:让LLM看懂网页的核心技术
  • 数学建模竞赛实战指南:从模型构建到论文写作的72小时攻关策略
  • 【C++ 面试真题】聊聊 C++ 的构造与析构
  • 智能体开发语言选型指南:Python、JS/TS、Go、Java对比与实战
  • 真空回流炉工艺方案定制:流程解析与参数优化实践
  • 【优化布局】基于模拟退火算法实现物流选址matlab代码
  • SQL进阶查询与网络安全实战:从多表关联到注入攻防
  • 中山大学智能工程学院考研专业课深度解析:控制、交通、电子信息专业选择与备考指南
  • 如何低成本快速建设一个微商的网站并实现销量爆发式增长全攻略
  • 强化学习入门:从马尔可夫决策过程到工程实践
  • 大兴网站开发网站建设报价背后的真相与选择指南
  • 基于OpenAPI规范驱动开发:从设计到代码的自动化实践
  • OpenSpec与TDD结合:用AI生成代码,以测试驱动确保质量
  • AI竞争进入硬件深水区:从算法到工程化的系统思维转变
  • 深耕辽宁大地:辽宁城乡建设网站如何以专业视角重塑城市美学与民生温度
  • LLM与Shader协同实战:构建语义驱动动态图形应用
  • 基于Deepseek与LangChain构建代码智能体:从概念到工程实践
  • 泉州最专业微信网站建设开发:为何企业在这个数字时代必须抓住这一核心流量入口
  • Java AI 应用接入大模型时,先把这四层工程边界划清楚
  • Android FFmpeg硬件加速集成:MediaCodec深度实践与性能优化
  • 从布莱克斯通比率到系统阈值:如何量化决策中的错误代价与容错率
  • 数学建模学习路径全解析:从思维培养到实战竞赛的完整指南
  • Docker Desktop下载最全保姆级教程!!!
  • Kali Linux新手入门:从环境搭建到实战靶场的网络安全学习路径
  • 材料力学基础:拉伸、压缩与剪切的工程应用与失效分析
  • 数学建模竞赛实战指南:从问题拆解到模型构建与论文写作