当前位置:网站首页>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
边栏推荐
- How to print mybats log plug-in using XML file
- R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
- High frequency interview questions
- Thread application instance
- 仿京东放大镜效果(pink老师版)
- Imitation Jingdong magnifying glass effect (pink teacher version)
- 2022编译原理期末考试 回忆版
- 数据降维——因子分析
- metric_logger小解
- 使用xml文件打印mybaties-log插件的方式
猜你喜欢
[paper reading] Ca net: leveraging contextual features for lung cancer prediction
[daily question] the next day
高级性能测试系列《24. 通过jdbc执行sql脚本》
【JVM调优实战100例】03——JVM堆调优四例
codeforces每日5题(均1700)-第四天
Why should we build an enterprise fixed asset management system and how can enterprises strengthen fixed asset management
High frequency interview questions
ICDE 2023|TKDE Poster Session(CFP)
Markdown基础语法
使用 Cheat Engine 修改 Kingdom Rush 中的金钱、生命、星
随机推荐
golang:[]byte转string
Preprocessing and preprocessing macros
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
Progress-进度条
Markdown基础语法
Develop fixed asset management system, what voice is used to develop fixed asset management system
消息队列消息丢失和消息重复发送的处理策略
Machine learning notes - time series prediction research: monthly sales of French champagne
Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
【JVM调优实战100例】01——JVM的介绍与程序计数器
ORA-01455: converting column overflows integer datatype
[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
Virtual machine initialization script, virtual machine mutual secret key free
R language dplyr package filter function filters dataframe data. If the name of the data column (variable) to be filtered contains quotation marks, you need to use!! SYM syntax processing, otherwise n
教程篇(5.0) 09. RESTful API * FortiEDR * Fortinet 网络安全专家 NSE 5
Tutoriel (5.0) 10. Dépannage * fortiedr * fortinet Network Security expert NSE 5
【测试开发】软件测试—概念篇
R language uses lrtest function of epidisplay package to perform likelihood ratio test on multiple GLM models (logisti regression). Compare whether the performance of the two models is different, and
SIFT特征点提取「建议收藏」
Introduction to the paper | application of machine learning in database cardinality estimation