"""
《基于智能优化与RRT算法的无人机任务规划方法研究》博士论文
《基于改进人工势场法的路径规划算法研究》硕士论文"""import matplotlib.pyplot as plt
import random
import math
import copyshow_animation = Trueclass Node(object):"""RRT Node"""def __init__(self, x, y):self.x = xself.y = yself.parent = Noneclass RRT(object):"""Class for RRT Planning"""def __init__(self, start, goal, obstacle_list, rand_area):"""Setting Parameterstart:Start Position [x,y]goal:Goal Position [x,y]obstacleList:obstacle Positions [[x,y,size],...]randArea:random sampling Area [min,max]"""self.start = Node(start[0], start[1])self.end = Node(goal[0], goal[1])self.min_rand = rand_area[0]self.max_rand = rand_area[1]self.expandDis = 1.0self.goalSampleRate = 0.05  # 选择终点的概率是0.05self.maxIter = 500self.obstacleList = obstacle_listself.nodeList = [self.start]def random_node(self):"""产生随机节点:return:"""node_x = random.uniform(self.min_rand, self.max_rand)node_y = random.uniform(self.min_rand, self.max_rand)node = [node_x, node_y]return node@staticmethoddef get_nearest_list_index(node_list, rnd):""":param node_list::param rnd::return:"""d_list = [(node.x - rnd[0]) ** 2 + (node.y - rnd[1]) ** 2 for node in node_list]min_index = d_list.index(min(d_list))return min_index@staticmethoddef collision_check(new_node, obstacle_list):a = 1for (ox, oy, size) in obstacle_list:dx = ox - new_node.xdy = oy - new_node.yd = math.sqrt(dx * dx + dy * dy)if d <= size:a = 0  # collisionreturn a  # safedef planning(self):"""Path planninganimation: flag for animation on or off"""while True:# Random Samplingif random.random() > self.goalSampleRate:rnd = self.random_node()else:rnd = [self.end.x, self.end.y]# Find nearest nodemin_index = self.get_nearest_list_index(self.nodeList, rnd)# print(min_index)# expand treenearest_node = self.nodeList[min_index]# 返回弧度制theta = math.atan2(rnd[1] - nearest_node.y, rnd[0] - nearest_node.x)new_node = copy.deepcopy(nearest_node)new_node.x += self.expandDis * math.cos(theta)new_node.y += self.expandDis * math.sin(theta)new_node.parent = min_indexif not self.collision_check(new_node, self.obstacleList):continueself.nodeList.append(new_node)# check goaldx = new_node.x - self.end.xdy = new_node.y - self.end.yd = math.sqrt(dx * dx + dy * dy)if d <= self.expandDis:print("Goal!!")breakif True:self.draw_graph(rnd)path = [[self.end.x, self.end.y]]last_index = len(self.nodeList) - 1while self.nodeList[last_index].parent is not None:node = self.nodeList[last_index]path.append([node.x, node.y])last_index = node.parentpath.append([self.start.x, self.start.y])return pathdef draw_graph(self, rnd=None):"""Draw Graph"""print('aaa')plt.clf()  # 清除上次画的图if rnd is not None:plt.plot(rnd[0], rnd[1], "^g")for node in self.nodeList:if node.parent is not None:plt.plot([node.x, self.nodeList[node.parent].x], [node.y, self.nodeList[node.parent].y], "-g")for (ox, oy, size) in self.obstacleList:plt.plot(ox, oy, "sk", ms=10*size)plt.plot(self.start.x, self.start.y, "^r")plt.plot(self.end.x, self.end.y, "^b")plt.axis([self.min_rand, self.max_rand, self.min_rand, self.max_rand])plt.grid(True)plt.pause(0.01)def draw_static(self, path):"""画出静态图像:return:"""plt.clf()  # 清除上次画的图for node in self.nodeList:if node.parent is not None:plt.plot([node.x, self.nodeList[node.parent].x], [node.y, self.nodeList[node.parent].y], "-g")for (ox, oy, size) in self.obstacleList:plt.plot(ox, oy, "sk", ms=10*size)plt.plot(self.start.x, self.start.y, "^r")plt.plot(self.end.x, self.end.y, "^b")plt.axis([self.min_rand, self.max_rand, self.min_rand, self.max_rand])plt.plot([data[0] for data in path], [data[1] for data in path], '-r')plt.grid(True)plt.show()def main():print("start RRT path planning")obstacle_list = [(5, 1, 1),(3, 6, 2),(3, 8, 2),(1, 1, 2),(3, 5, 2),(9, 5, 2)]# Set Initial parametersrrt = RRT(start=[0, 0], goal=[8, 9], rand_area=[-2, 10], obstacle_list=obstacle_list)path = rrt.planning()print(path)# Draw final pathif show_animation:plt.close()rrt.draw_static(path)if __name__ == '__main__':main()

参考

https://www.cnblogs.com/yangmingustb/p/9013534.html

RRT算法(快速拓展随机树)的Python实现相关推荐

  1. python无人机路径规划算法_快速拓展随机树(RRT)路径规划,python

    1 """2 version1.1,2018-05-09 3 <基于智能优化与RRT算法的无人机任务规划方法研究>博士论文4 <基于改进人工势场法的路径 ...

  2. python无人机路径规划算法_RRT算法在Python中的实现,快速,拓展,随机,树

    """ <基于智能优化与RRT算法的无人机任务规划方法研究>博士论文 <基于改进人工势场法的路径规划算法研究>硕士论文 ""& ...

  3. rrt算法流程图_RRT算法移动机器人路径规划(快速扩展随机树).pdf

    ( ) 第 34 卷 第 5期 南京理工大学学报 自然科学版 Vo l. 34 No. 5 20 10年 10 月 Journal of N anj ing Un iversity of Scienc ...

  4. 聊聊路径规划算法—快速搜寻随机树算法

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者丨 Li-Jianghao 来源丨古月居 快速搜寻随机树(RRT)算法是一个增量式采样的搜寻技术, ...

  5. 快速搜索随机树(RRT---Rapidly-exploring Random Trees)入门及在Matlab中演示

    转载:http://blog.csdn.net/gpeng832/article/details/71249198?locationNum=1&fps=1   快速搜索随机树(RRT -Rap ...

  6. 左上角到右下角的路径 oj_【机器人路径规划】快速扩展随机树(RRT)算法

    内容无关:最近的课题内容和机器人运动规划方法有关,我把学习的内容整理成为工具箱上传到了我的github仓库,稍后将会发一篇说明介绍使用方法. XM522706601/robotics_tutorial ...

  7. 【运动规划】RRT快速搜索随机树 Rapidly Exploring Random Tree

    Randomized Kinodynamic Planning Steven M. LaValle James J. Kuffner, Jr. 1. Exploring the State Space ...

  8. [matlab] 7.快速搜索随机树(RRT---Rapidly-exploring Random Trees) 路径规划

    RRT是一种多维空间中有效率的规划方法.它以一个初始点作为根节点,通过随机采样增加叶子节点的方式,生成一个随机扩展树,当随机树中的叶子节点包含了目标点或进入了目标区域,便可以在随机树中找到一条由从初始 ...

  9. 【路径规划】基于拓展随机树(RRT)算法的路径规划问题(Matlab代码实现)

最新文章

  1. 【深度】清华黄高等人新作:动态神经网络首篇综述
  2. javascript数字千分位格式化
  3. 恢复从回收站中被删除的文件的方法
  4. 简单图库软件的实现(联网下载图片保存到sdcard在Listview中展示,并作为ContentProvider为其他软件提供图库数据)
  5. 百度关闭新闻源背后的13个趋势风口
  6. 第十一章 “她”值多少钱
  7. 收藏 | 9 个技巧让你的 PyTorch 模型训练变得飞快!
  8. 每日一课(11/75)CPU资源和存储器 之 80x86 内存管理
  9. 西门子宣布美国充电桩扩产计划
  10. linux内核源码多大,Linux内核源代码
  11. “软考”遗失试卷全部追回 相关责任人接受审查
  12. 高分屏更改Adobe Premier CC UI界面字体大小
  13. 图书管理 python excel_爬取python异步社区图书并写入excel
  14. 风险管理计划包括哪些内容
  15. python桌面爬虫_Python爬虫 利用python爬取ZOL桌面壁纸大图
  16. T32. High.最长有效括号
  17. 翁恺 python_翁恺 - 主页
  18. 计算机搜索文件时找不到搜索按钮,win7搜索功能 为什么明明有那个文件却搜索不到呢?-win7搜索不到文件,win7搜索文件内容搜不出来...
  19. MSSQL数据库快捷键大全
  20. Springboot使用Specification连表多条件查询(完整demo)

热门文章

  1. QQ文件及文件夹的一些知识
  2. QQ无法访问个人文件夹,修复失败问题
  3. centos7.4和ubuntu16.0.4常用命令
  4. MPC5746C双核启动配置分析
  5. 大数据研究的若干科学问题——徐宗本
  6. 单片机编程软件很简单(八),Keil单片机编程软件辅助功能讲解
  7. 位图(BMP)文件头格式及数据分析
  8. 火狐浏览器更新版本之后总是在当前页面打开新链接覆盖掉原先内容
  9. 十一届蓝桥模拟赛 元辅音字母 JAVA
  10. ETL工程师 2021-11-14