python无人机路径规划算法_快速拓展随机树(RRT)路径规划,python
1 """2 version1.1,2018-05-09
3 《基于智能优化与RRT算法的无人机任务规划方法研究》博士论文4 《基于改进人工势场法的路径规划算法研究》硕士论文5
6 """7
8 import matplotlib.pyplot asplt9 import random10 import math11 import copy12
13 show_animation =True14
15
16 class Node(object):17 """18 RRT Node19 """20
21 def __init__(self, x, y):22 self.x =x23 self.y =y24 self.parent =None25
26
27 class RRT(object):28 """29 Class forRRT Planning30 """31
32 def __init__(self, start, goal, obstacle_list, rand_area):33 """34 Setting Parameter35
36 start:Start Position [x,y]37 goal:Goal Position [x,y]38 obstacleList:obstacle Positions [[x,y,size],...]39 randArea:random sampling Area [min,max]40
41 """42 self.start = Node(start[0], start[1])43 self.end = Node(goal[0], goal[1])44 self.min_rand = rand_area[0]45 self.max_rand = rand_area[1]46 self.expandDis = 1.0
47 self.goalSampleRate = 0.05 # 选择终点的概率是0.05
48 self.maxIter = 500
49 self.obstacleList =obstacle_list50 self.nodeList =[self.start]51
52 def random_node(self):53 """54 产生随机节点55 :return:56 """57 node_x =random.uniform(self.min_rand, self.max_rand)58 node_y =random.uniform(self.min_rand, self.max_rand)59 node =[node_x, node_y]60
61 returnnode62
63 @staticmethod64 def get_nearest_list_index(node_list, rnd):65 """66 :param node_list:67 :param rnd:68 :return:69 """70 d_list = [(node.x - rnd[0]) ** 2 + (node.y - rnd[1]) ** 2 for node innode_list]71 min_index =d_list.index(min(d_list))72 returnmin_index73
74 @staticmethod75 def collision_check(new_node, obstacle_list):76 a = 1
77 for (ox, oy, size) inobstacle_list:78 dx = ox -new_node.x79 dy = oy -new_node.y80 d = math.sqrt(dx * dx + dy *dy)81 if d <=size:82 a = 0# collision83
84 returna # safe85
86 def planning(self):87 """88 Path planning89
90 animation: flag foranimation on or off91 """92
93 whileTrue:94 # Random Sampling95 if random.random() >self.goalSampleRate:96 rnd =self.random_node()97 else:98 rnd =[self.end.x, self.end.y]99
100 # Find nearest node101 min_index =self.get_nearest_list_index(self.nodeList, rnd)102 # print(min_index)103
104 # expand tree105 nearest_node =self.nodeList[min_index]106
107 # 返回弧度制108 theta = math.atan2(rnd[1] - nearest_node.y, rnd[0] -nearest_node.x)109
110 new_node =copy.deepcopy(nearest_node)111 new_node.x += self.expandDis *math.cos(theta)112 new_node.y += self.expandDis *math.sin(theta)113 new_node.parent =min_index114
115 ifnot self.collision_check(new_node, self.obstacleList):116 continue
117
118 self.nodeList.append(new_node)119
120 # check goal121 dx = new_node.x -self.end.x122 dy = new_node.y -self.end.y123 d = math.sqrt(dx * dx + dy *dy)124 if d <=self.expandDis:125 print("Goal!!")126 break
127
128 ifTrue:129 self.draw_graph(rnd)130
131 path =[[self.end.x, self.end.y]]132 last_index = len(self.nodeList) - 1
133 while self.nodeList[last_index].parent isnot None:134 node =self.nodeList[last_index]135 path.append([node.x, node.y])136 last_index =node.parent137 path.append([self.start.x, self.start.y])138
139 returnpath140
141 def draw_graph(self, rnd=None):142 """143 Draw Graph144 """145 print('aaa')146 plt.clf() # 清除上次画的图147 if rnd isnot None:148 plt.plot(rnd[0], rnd[1], "^g")149 for node inself.nodeList:150 if node.parent isnot None:151 plt.plot([node.x, self.nodeList[node.parent].x], [152 node.y, self.nodeList[node.parent].y], "-g")153
154 for (ox, oy, size) inself.obstacleList:155 plt.plot(ox, oy, "sk", ms=10*size)156
157 plt.plot(self.start.x, self.start.y, "^r")158 plt.plot(self.end.x, self.end.y, "^b")159 plt.axis([self.min_rand, self.max_rand, self.min_rand, self.max_rand])160 plt.grid(True)161 plt.pause(0.01)162
163 def draw_static(self, path):164 """165 画出静态图像166 :return:167 """168 plt.clf() # 清除上次画的图169
170 for node inself.nodeList:171 if node.parent isnot None:172 plt.plot([node.x, self.nodeList[node.parent].x], [173 node.y, self.nodeList[node.parent].y], "-g")174
175 for (ox, oy, size) inself.obstacleList:176 plt.plot(ox, oy, "sk", ms=10*size)177
178 plt.plot(self.start.x, self.start.y, "^r")179 plt.plot(self.end.x, self.end.y, "^b")180 plt.axis([self.min_rand, self.max_rand, self.min_rand, self.max_rand])181
182 plt.plot([data[0] for data in path], [data[1] for data in path], '-r')183 plt.grid(True)184 plt.show()185
186
187 def main():188 print("start RRT path planning")189
190 obstacle_list =[191 (5, 1, 1),192 (3, 6, 2),193 (3, 8, 2),194 (1, 1, 2),195 (3, 5, 2),196 (9, 5, 2)]197
198 # Set Initial parameters199 rrt = RRT(start=[0, 0], goal=[8, 9], rand_area=[-2, 10], obstacle_list=obstacle_list)200 path =rrt.planning()201 print(path)202
203 # Draw final path204 ifshow_animation:205 plt.close()206 rrt.draw_static(path)207
208
209 if __name__ == '__main__':210 main()
python无人机路径规划算法_快速拓展随机树(RRT)路径规划,python相关推荐
- 左上角到右下角的路径 oj_【机器人路径规划】快速扩展随机树(RRT)算法
内容无关:最近的课题内容和机器人运动规划方法有关,我把学习的内容整理成为工具箱上传到了我的github仓库,稍后将会发一篇说明介绍使用方法. XM522706601/robotics_tutorial ...
- python无人机路径规划算法_RRT算法在Python中的实现,快速,拓展,随机,树
""" <基于智能优化与RRT算法的无人机任务规划方法研究>博士论文 <基于改进人工势场法的路径规划算法研究>硕士论文 ""& ...
- RRT算法(快速拓展随机树)的Python实现
""" <基于智能优化与RRT算法的无人机任务规划方法研究>博士论文 <基于改进人工势场法的路径规划算法研究>硕士论文""&q ...
- rapidly exploring random tree(快速搜索随机树)路径规划
直接上程序 %% 流程初始化 clear all; close all; pic_num=1;%制作gif所需参数 x_I=1; y_I=1; % 设置初始点 x_G=600; y_G=600; % ...
- 基于快速探索随机树RRT和Dubins路径规划与避障研究(Matlab代码实现)
- rrt算法流程图_RRT算法移动机器人路径规划(快速扩展随机树).pdf
( ) 第 34 卷 第 5期 南京理工大学学报 自然科学版 Vo l. 34 No. 5 20 10年 10 月 Journal of N anj ing Un iversity of Scienc ...
- Dijkstra 路径规划算法在二维仿真环境中的应用 -- Python代码实现
在上一节中,介绍了 Dijkstra 算法的原理以及在图中的应用,这一节将一步步实现 Dijkstra 路径规划算法在二维环境中的路径规划,来进一步加深对 Dijkstra 算法的理解. 所需要用到的 ...
- 路径规划算法_自动驾驶汽车路径规划算法浅析
自动驾驶汽车的路径规划算法最早源于机器人的路径规划研究,但是就工况而言却比机器人的路径规划复杂得多,自动驾驶车辆需要考虑车速.道路的附着情况.车辆最小转弯半径.外界天气环境等因素. 本文将为大家介绍四 ...
- RRT路径规划算法在二维仿真环境中的应用 -- Python代码实现
在上一节中,介绍了 RRT 算法的原理,这一节将一步步实现 RRT 路径规划算法在二维环境中的路径规划,来进一步加深对 RRT 算法的理解. 二维环境的搭建 我们将搭建下图所示的二维环境,绿色点为起点 ...
最新文章
- ‘grep‘ 不是内部或外部命令,也不是可运行的程序或批处理文件-adb shell ps | grep ***
- 手把手教你用SPSS做出二元logistic回归分析
- linux slab 内存 清理,linux系统slab内存占用
- keil5选择ST-Link Debugger时候setting点击不了问题
- 大型门户网站架构分析
- 钱符号怎么打出来(如何在文档中输入人民币符号?)
- 翁恺老师 | 城堡游戏解读
- 接口测试简介及用例设计思路
- 如需定义元素内容与边框间的空间,可使用 padding 属性,并可使用负值?
- 基于深度学习的显著性目标检测方法综述
- python布尔类型(bool)
- [转贴]去除迅雷广告和弹出广告窗口
- 977. 有序数组的平方
- 云安全问题及其解决方案
- 【系统分析师之路】系统安全章节错题集锦
- 腾讯云数据库TDSQL:分布式数据库,你真的了解吗?
- 计算机中丢失hvdailt.dll,修复hvdailt.dll
- SpringBoot 整合【Mybatis-Plus实现分页查询】
- C++核心——类中的const关键字
- nginx-反向代理和负载均衡
热门文章
- 张家口以太坊智能合约开发实战pdf_以太坊2.0:实现可扩展性之路漫长而曲折
- u盘解密软件_企业都使用哪些数据防泄密软件
- ftp linux 服务器 麒麟_麒麟系统安装ftp
- ubuntu查看python安装路径
- C++之文件操作探究(二):读文件——文本文件
- C++之指针探究(十六):typedef结合函数指针
- 字段缺失_数据科学| 手把手教你用 pandas 索引、汇总、处理缺失数据
- java 反射 proper_JAVA提高四:反射基本应用
- git add remote_git命令
- linux 编译配置文件,Linux程序源码编译安装的configure配置详解