当前位置:网站首页>Mobile robot path planning: artificial potential field method [easy to understand]
Mobile robot path planning: artificial potential field method [easy to understand]
2022-07-02 19:21:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
The artificial potential field method is a simple method Move robot Path planning algorithm , It regards the position of the target point as the lowest point of potential energy , Treat obstacles in the map as potential energy highs , Calculate the potential field diagram of the whole known map , And then, ideally , The robot is like a rolling ball , Automatically avoid all obstacles and roll to the target point .
- Reference resources : Source code potential_field_planning.py Courseware CMU RI 16-735 Robot path planning 4 speak : Artificial potential field method
In particular , The potential energy formula of the target point is :
It reads , In order to prevent the speed from being too fast when it is far away from the target point , It can be described in the form of piecewise function , It will be shown later . The potential energy of the obstacle is expressed as :
That is, it has high potential energy in a certain range around the obstacle , The influence of out of range visual obstacles is 0. Finally, add the potential energy of the target point and the obstacle , Get the whole potential energy map :
The following is the source code in the reference link , It's easier to understand :
""" Potential Field based path planner author: Atsushi Sakai (@Atsushi_twi) Ref: https://www.cs.cmu.edu/~motionplanning/lecture/Chap4-Potential-Field_howie.pdf """
from collections import deque
import numpy as np
import matplotlib.pyplot as plt
# Parameters
KP = 5.0 # attractive potential gain
ETA = 100.0 # repulsive potential gain
AREA_WIDTH = 30.0 # potential area width [m]
# the number of previous positions used to check oscillations
OSCILLATIONS_DETECTION_LENGTH = 3
show_animation = True
def calc_potential_field(gx, gy, ox, oy, reso, rr, sx, sy):
""" Calculate the potential field diagram gx,gy: Target coordinates ox,oy: Obstacle coordinate list reso: Potential field diagram resolution rr: Robot radius sx,sy: Starting point coordinates """
# Determine the coordinate range of the potential field diagram :
minx = min(min(ox), sx, gx) - AREA_WIDTH / 2.0
miny = min(min(oy), sy, gy) - AREA_WIDTH / 2.0
maxx = max(max(ox), sx, gx) + AREA_WIDTH / 2.0
maxy = max(max(oy), sy, gy) + AREA_WIDTH / 2.0
# Determine the number of cells according to the range and resolution :
xw = int(round((maxx - minx) / reso))
yw = int(round((maxy - miny) / reso))
# calc each potential
pmap = [[0.0 for i in range(yw)] for i in range(xw)]
for ix in range(xw):
x = ix * reso + minx # According to index and resolution x coordinate
for iy in range(yw):
y = iy * reso + miny # According to index and resolution x coordinate
ug = calc_attractive_potential(x, y, gx, gy) # Calculate gravity
uo = calc_repulsive_potential(x, y, ox, oy, rr) # Calculated repulsion
uf = ug + uo
pmap[ix][iy] = uf
return pmap, minx, miny
def calc_attractive_potential(x, y, gx, gy):
""" Calculate the gravitational potential energy :1/2*KP*d """
return 0.5 * KP * np.hypot(x - gx, y - gy)
def calc_repulsive_potential(x, y, ox, oy, rr):
""" Calculate the repulsive potential energy : If the distance from the nearest obstacle dq In the robot expansion radius rr within :1/2*ETA*(1/dq-1/rr)**2 otherwise :0.0 """
# search nearest obstacle
minid = -1
dmin = float("inf")
for i, _ in enumerate(ox):
d = np.hypot(x - ox[i], y - oy[i])
if dmin >= d:
dmin = d
minid = i
# calc repulsive potential
dq = np.hypot(x - ox[minid], y - oy[minid])
if dq <= rr:
if dq <= 0.1:
dq = 0.1
return 0.5 * ETA * (1.0 / dq - 1.0 / rr) ** 2
else:
return 0.0
def get_motion_model():
# dx, dy
# Jiugonggezhong 8 Possible directions of motion
motion = [[1, 0],
[0, 1],
[-1, 0],
[0, -1],
[-1, -1],
[-1, 1],
[1, -1],
[1, 1]]
return motion
def oscillations_detection(previous_ids, ix, iy):
""" Oscillation detection : avoid “ Repeat the cross jump ” """
previous_ids.append((ix, iy))
if (len(previous_ids) > OSCILLATIONS_DETECTION_LENGTH):
previous_ids.popleft()
# check if contains any duplicates by copying into a set
previous_ids_set = set()
for index in previous_ids:
if index in previous_ids_set:
return True
else:
previous_ids_set.add(index)
return False
def potential_field_planning(sx, sy, gx, gy, ox, oy, reso, rr):
# calc potential field
pmap, minx, miny = calc_potential_field(gx, gy, ox, oy, reso, rr, sx, sy)
# search path
d = np.hypot(sx - gx, sy - gy)
ix = round((sx - minx) / reso)
iy = round((sy - miny) / reso)
gix = round((gx - minx) / reso)
giy = round((gy - miny) / reso)
if show_animation:
draw_heatmap(pmap)
# for stopping simulation with the esc key.
plt.gcf().canvas.mpl_connect('key_release_event',
lambda event: [exit(0) if event.key == 'escape' else None])
plt.plot(ix, iy, "*k")
plt.plot(gix, giy, "*m")
rx, ry = [sx], [sy]
motion = get_motion_model()
previous_ids = deque()
while d >= reso:
minp = float("inf")
minix, miniy = -1, -1
# seek 8 The direction in which the potential field is the smallest among the three directions of motion
for i, _ in enumerate(motion):
inx = int(ix + motion[i][0])
iny = int(iy + motion[i][1])
if inx >= len(pmap) or iny >= len(pmap[0]) or inx < 0 or iny < 0:
p = float("inf") # outside area
print("outside potential!")
else:
p = pmap[inx][iny]
if minp > p:
minp = p
minix = inx
miniy = iny
ix = minix
iy = miniy
xp = ix * reso + minx
yp = iy * reso + miny
d = np.hypot(gx - xp, gy - yp)
rx.append(xp)
ry.append(yp)
# Oscillation detection , To avoid falling into a local minimum :
if (oscillations_detection(previous_ids, ix, iy)):
print("Oscillation detected at ({},{})!".format(ix, iy))
break
if show_animation:
plt.plot(ix, iy, ".r")
plt.pause(0.01)
print("Goal!!")
return rx, ry
def draw_heatmap(data):
data = np.array(data).T
plt.pcolor(data, vmax=100.0, cmap=plt.cm.Blues)
def main():
print("potential_field_planning start")
sx = 0.0 # start x position [m]
sy = 10.0 # start y positon [m]
gx = 30.0 # goal x position [m]
gy = 30.0 # goal y position [m]
grid_size = 0.5 # potential grid size [m]
robot_radius = 5.0 # robot radius [m]
# The following obstacle coordinates are my modified , It is used to show the situation that the artificial potential field method is trapped in local optimization :
ox = [15.0, 5.0, 20.0, 25.0, 12.0, 15.0, 19.0, 28.0, 27.0, 23.0, 30.0, 32.0] # obstacle x position list [m]
oy = [25.0, 15.0, 26.0, 25.0, 12.0, 20.0, 29.0, 28.0, 26.0, 25.0, 28.0, 27.0] # obstacle y position list [m]
if show_animation:
plt.grid(True)
plt.axis("equal")
# path generation
_, _ = potential_field_planning(
sx, sy, gx, gy, ox, oy, grid_size, robot_radius)
if show_animation:
plt.show()
if __name__ == '__main__':
print(__file__ + " start!!")
main()
print(__file__ + " Done!!")
One of the main disadvantages of the artificial potential field method is that it may fall into the local optimal solution , The following figure is the result of running the source code :
Here is after I added some obstacles , The artificial potential field method is trapped in the case of local optimal solution : Although the target point has not been reached , But the potential field determines that the path cannot go any further .
It should be noted that , When calculating the potential field of the target point in the source code , It uses a x,y A term of the distance between the position and the target point , The quadratic term is not used as shown in the courseware , It is also to make the potential field change less quickly . The following is according to the courseware , The result of using the quadratic term of distance , We can see , For normal operation ,KP It needs to be adjusted very low :
KP = 0.1
def calc_attractive_potential(x, y, gx, gy):
""" Calculate the gravitational potential energy :1/2*KP*d^2 """
return 0.5 * KP * np.hypot(x - gx, y - gy)**2
The normal operation :
Trapped in local best :
You can see from the potential field diagram , Gravity changes much faster than the previous example .
Last , We modify the program into the segmentation function shown in the screenshot of the courseware above :
KP = 0.25
dgoal = 10
def calc_attractive_potential(x, y, gx, gy):
""" Calculate gravity : Such as courseware screenshot """
dg = np.hypot(x - gx, y - gy)
if dg<=dgoal:
U = 0.5 * KP * np.hypot(x - gx, y - gy)**2
else:
U = dgoal*KP*np.hypot(x - gx, y - gy) - 0.5*KP*dgoal
return U
The normal operation :
Trapped in local optima :
You can see the effect of gravitational potential field segmentation .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/148611.html Link to the original text :https://javaforall.cn
边栏推荐
- 9D电影是怎样的?(+维度空间常识)
- Stm32g0 USB DFU upgrade verification error -2
- 聊聊电商系统中红包活动设计
- ORA-01455: converting column overflows integer datatype
- reduce--遍历元素计算 具体的计算公式需要传入 结合BigDecimal
- Gamefi链游系统开发(NFT链游开发功能)丨NFT链游系统开发(Gamefi链游开发源码)
- 论文导读 | 机器学习在数据库基数估计中的应用
- 消息队列消息丢失和消息重复发送的处理策略
- Excel查找一列中的相同值,删除该行或替换为空值
- Juypter notebook modify the default open folder and default browser
猜你喜欢
【JVM调优实战100例】01——JVM的介绍与程序计数器
yolov3 训练自己的数据集之生成train.txt
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
Learning summary of MySQL advanced 6: concept and understanding of index, detailed explanation of b+ tree generation process, comparison between MyISAM and InnoDB
仿京东放大镜效果(pink老师版)
PHP-Parser羽毛球预约小程序开发require线上系统
Markdown基础语法
新手必看,点击两个按钮切换至不同的内容
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
ICDE 2023|TKDE Poster Session(CFP)
随机推荐
R language uses Cox of epidisplay package Display function obtains the summary statistical information of Cox regression model (risk rate HR, adjusted risk rate and its confidence interval, P value of
Processing strategy of message queue message loss and repeated message sending
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
聊聊电商系统中红包活动设计
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
论文导读 | 关于将预训练语言模型作为知识库的分析与批评
SIFT特征点提取「建议收藏」
Markdown基础语法
Data dimensionality reduction factor analysis
电脑使用哪个录制视频软件比较好
mysql备份后缀是什么_mysql备份还原
How performance testing creates business value
How to delete the border of links in IE? [repeat] - how to remove borders around links in IE? [duplicate]
Learning summary of MySQL advanced 6: concept and understanding of index, detailed explanation of b+ tree generation process, comparison between MyISAM and InnoDB
Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比
使用xml文件打印mybaties-log插件的方式
Mysql高级篇学习总结8:InnoDB数据存储结构页的概述、页的内部结构、行格式
[fluent] dart data type (VaR data type | object data type)
《病人家属,请来一下》读书笔记
golang:[]byte转string