此文章为Motion planning for self-driving cars上第二课的笔记,主要讲述占据栅格地图的生成。由于课程中算法也是参考《probability robot》这本书,书中对算法的解释更为详尽,因此本文同时参考了课程内容和中文版《概率机器人》。
**

1. 占用栅格地图算法简介

**
占用栅格的基本思想是用一系列随机变量来表示地图。每个随机变量是一个二值数据,表示该位置是否被占用,一般用{0,1}表示,1代表占用。占用栅格地图构建算法对以上随机变量进行近似后验估计,最终得到地图中每个栅格被占用的概率,即
式中m 为地图; Z1:t为从开始到时刻 t 的所有测量值; X1:t为用所有固定于车辆上的雷达位姿定义的路径。对于无人驾驶汽车来说,测量值Z表示测得的障碍物到雷达的距离,X包括车辆在二维平面内的全局坐标和航向角。
标准的占用栅格方法将构建地图这一问题划分为一些独立的间题,即为所有的栅格单元 mi建立后验概率:
由于概率取值范围为[0,1],直接用概率相乘在接近0或1处会出现不稳定且浪费计算资源,因此转换成对数占用概率表示方法
对数占用概率(log odds)取值范围为(-inf,inf),如下图所示
应用二值贝叶斯滤波算法(具体推导过程见《概率机器人》第4章),概率更新算法步骤如下图所示:

其中,
注意式9.8中的下标为t,代表根据当前时刻的测量值和车辆位置计算的对数占用概率,下一节对此重点介绍。即若mi在雷达测量范围内,则t时刻mi的对数占用概率等于上一时刻的对数占用概率加上当前时刻测量计算的对数概率,减去初始对数概率。

根据上述算法得到每个栅格的对数占用概率后,再转换回概论值,就可以得到占用网格地图。
**

2. inverse_sensor_model算法

**
如图所示,t时刻雷达向四周发送一定数目的波束,到达障碍物后反射回来,整个地图可划分为三大区域
雷达探测到的障碍物点附近,为高概率区域;超过雷达检测范围或检测的障碍物点更远的位置为未知区域;车辆到检测到的障碍物点之间为低概率区域。其中,高概率区域范围的确认方法如下:

对于单个波束来说,波束角为β,α定义为高概率区域宽度,上下边界分别离雷达检测点α/2距离,如上图所示,若栅格中心落在这个红色区域内,则此栅格为高概率区域。
基于以上的概率区域划分方法,inverse_sensor_model算法如下:
第3,4步:计算当前栅格到车辆的距离r和在全局坐标下与车辆之间的角度
第5步:计算返回当前时刻离栅格和车辆连线最近的波束索引k
第6,7步:若r大于雷达测量范围,或者r超过了第k个波束的高概率区域,则将当前时刻此栅格对数占用概率设为l0
第8,9步:若栅格中心落在高概率区域,则将当前时刻此栅格对数占用概率设为locc
第10,11步:若栅格中心落在低概率区域,则将当前时刻此栅格对数占用概率设为lfree

其中,l0,locc,lfree为预先定义好的值。
**

3. 示例程序(课程第2课作业)

**
inverse_sensor_model实现函数,这里返回的是概率,后面主循环中会再转换为对数占用概率

def inverse_scanner(num_rows, num_cols, x, y, theta, meas_phi, meas_r, rmax, alpha, beta):m = np.zeros((M, N))for i in range(num_rows):for j in range(num_cols):# Find range and bearing relative to the input state (x, y, theta).r = math.sqrt((i - x)**2 + (j - y)**2)phi = (math.atan2(j - y, i - x) - theta + math.pi) % (2 * math.pi) - math.pi# Find the range measurement associated with the relative bearing.k = np.argmin(np.abs(np.subtract(phi, meas_phi)))# If the range is greater than the maximum sensor range, or behind our range# measurement, or is outside of the field of view of the sensor, then no# new information is available.if (r > min(rmax, meas_r[k] + alpha / 2.0)) or (abs(phi - meas_phi[k]) > beta / 2.0):m[i, j] = 0.5# If the range measurement lied within this cell, it is likely to be an object.elif (meas_r[k] < rmax) and (abs(r - meas_r[k]) < alpha / 2.0):m[i, j] = 0.7# If the cell is in front of the range measurement, it is likely to be empty.elif r < meas_r[k]:m[i, j] = 0.3return m

基于真值地图和某一时刻车辆位置生成的雷达测量值函数

def get_ranges(true_map, X, meas_phi, rmax):(M, N) = np.shape(true_map)x = X[0]y = X[1]theta = X[2]meas_r = rmax * np.ones(meas_phi.shape)# Iterate for each measurement bearing.for i in range(len(meas_phi)):# Iterate over each unit step up to and including rmax.for r in range(1, rmax+1):# Determine the coordinates of the cell.xi = int(round(x + r * math.cos(theta + meas_phi[i])))yi = int(round(y + r * math.sin(theta + meas_phi[i])))# If not in the map, set measurement there and stop going further.if (xi <= 0 or xi >= M-1 or yi <= 0 or yi >= N-1):meas_r[i] = rbreak# If in the map, but hitting an obstacle, set the measurement range# and stop ray tracing.elif true_map[int(round(xi)), int(round(yi))] == 1:meas_r[i] = rbreakreturn meas_r

仿真参数设置,包括仿真步数,车辆初始位置,车辆运动参数,雷达参数及真值地图定义

# Simulation time initialization.
T_MAX = 150
time_steps = np.arange(T_MAX)#[0 1 2 ...149]# Initializing the robot's location.
x_0 = [30, 30, 0]# The sequence of robot motions.
u = np.array([[3, 0, -3, 0], [0, 3, 0, -3]])
u_i = 1# Robot sensor rotation command
w = np.multiply(0.3, np.ones(len(time_steps)))# True map (note, columns of map correspond to y axis and rows to x axis, so
# robot position x = x(1) and y = x(2) are reversed when plotted to match
M = 50
N = 60
true_map = np.zeros((M, N))#真值地图
true_map[0:10, 0:10] = 1
true_map[30:35, 40:45] = 1
true_map[3:6,40:60] = 1;
true_map[20:30,25:29] = 1;
true_map[40:50,5:25] = 1;# Initialize the belief map.
# We are assuming a uniform prior.
m = np.multiply(0.5, np.ones((M, N)))#置信度地图,初始化都为0.5# Initialize the log odds ratio.
L0 = np.log(np.divide(m, np.subtract(1, m)))#初始化l0
L = L0# Parameters for the sensor model.
meas_phi = np.arange(-0.4, 0.4, 0.05)#[-0.4,-0.35,...0,0.05,...0.35],弧度
rmax = 30 # Max beam range.
alpha = 1 # Width of an obstacle (distance about measurement to fill in).
beta = 0.05 # Angular width of a beam.# Initialize the vector of states for our simulation.
x = np.zeros((3, len(time_steps)))
x[:, 0] = x_0

主程序,循环更新地图中每个栅格占用概率

meas_rs = []
meas_r = get_ranges(true_map, x[:, 0], meas_phi, rmax)#0时刻测量半径范围
meas_rs.append(meas_r)
invmods = []
invmod = inverse_scanner(M, N, x[0, 0], x[1, 0], x[2, 0], meas_phi, meas_r, \rmax, alpha, beta)#0时刻概率图
invmods.append(invmod)
ms = []
ms.append(m)# Main simulation loop.
for t in range(1, len(time_steps)):# Perform robot motion.move = np.add(x[0:2, t-1], u[:, u_i]) # If we hit the map boundaries, or a collision would occur, remain still.if (move[0] >= M - 1) or (move[1] >= N - 1) or (move[0] <= 0) or (move[1] <= 0) \or true_map[int(round(move[0])), int(round(move[1]))] == 1:x[:, t] = x[:, t-1]u_i = (u_i + 1) % 4else:x[0:2, t] = movex[2, t] = (x[2, t-1] + w[t]) % (2 * math.pi)# TODO Gather the measurement range data, which we will convert to occupancy probabilities# using our inverse measurement model.meas_r = get_ranges(true_map, x[:, t], meas_phi, rmax)#t时刻测量半径范围meas_rs.append(meas_r)# TODO Given our range measurements and our robot location, apply our inverse scanner model# to get our measure probabilities of occupancy.invmod = inverse_scanner(M, N, x[0, t], x[1, t], x[2, t], meas_phi, meas_r, \rmax, alpha, beta)#t时刻概率图invmods.append(invmod)# TODO Calculate and update the log odds of our occupancy grid, given our measured# occupancy probabilities from the inverse model.L = np.log(np.divide(invmod, np.subtract(1, invmod)))#t时刻inverse_sensor_model# TODO Calculate a grid of probabilities from the log odds.Lt = np.subtract(np.add(np.log(np.divide(ms[t-1], np.subtract(1, ms[t-1]))),L),L0)m=np.subtract(1,np.divide(1,np.add(1,np.exp(Lt))))ms.append(m)

**

4. 仿真效果验证

**
真值地图和车辆行驶路径如下所示

选取[10, 40]、[40, 30]、[40, 35]、[50, 0]、[5, 10]、[15, 20]、[50, 25]这几个点进行计算,得出的占用概率分别为:
0.9857478005865102
0.9988631799564817
0.8448275862068966
0.5
0.072972972972973
0.00020899763468718024
1.2953015129379963e-06

可以看出,计算结果与实际相符,前三个点被占用,第4个点因为雷达未扫描到,占用是否未知,后3个点为未占用点。

最终根据概率绘制的占用栅格地图如下图所示,可以看出,很接近真值地图,算法效果较好。

**

5. 参考

**
[1].Coursera无人驾驶课程:Motion planning for self-driving cars
[2].《概率机器人》第4、9章

Motion planning for self-driving cars课程笔记1:应用雷达数据生成占用栅格地图(Occupancy Grid Map)相关推荐

  1. Apollo进阶课程㉒丨Apollo规划技术详解——Motion Planning with Autonomous Driving

    原文链接:进阶课程㉒丨Apollo规划技术详解--Motion Planning with Autonomous Driving 自动驾驶车辆的规划决策模块负责生成车辆的行驶行为,是体现车辆智慧水平的 ...

  2. 【R】【课程笔记】04+05 数据预处理+收益率计算

    本文是课程<数据科学与金融计算>第4-5章的学习笔记,主要介绍金融数据处理.收益率计算和R与C++调用,用于知识点总结和代码练习,Q&A为问题及解决方案. 往期回顾: 博文 内容 ...

  3. <Principles of fMRI 1>课程笔记2 功能核磁数据的分析

    fmri是一种非侵入技术:fmri扫描没有已知的副作用.在fmri实验中,在被试完成任务时测量一系列的大脑图像.然后单个图片的测量信号的变化被用来推断任务-相关的脑活动. fmri是在一段时间内多次测 ...

  4. Apollo进阶课程㉓丨Apollo规划技术详解——Motion Planning with Environment

    原文链接:进阶课程㉓丨Apollo规划技术详解--Motion Planning with Environment 当行为层决定要在当前环境中执行的驾驶行为时,其可以是例如巡航-车道,改变车道或右转, ...

  5. Motion Planning中的问题与挑战

    在自动驾驶系统中包含定位.感知.预测.决策规划和控制算法模块,其中决策规划模块相当于自动驾驶系统的大脑.SAE将自动驾驶分为L0-L5六个等级,随着自动驾驶等级的提供,决策规划模块的重要性也随之提高. ...

  6. 【R】【课程笔记】07 分位数回归与VaR(ES)计算

    本文是课程<数据科学与金融计算>第7章的学习笔记,主要介绍计算VaR/ES风险测度的各种方法和极值理论等,用于知识点总结和代码练习,Q&A为问题及解决方案. 往期回顾: 博文 内容 ...

  7. 【R】【课程笔记】02+03 基于R软件的计算

    本文是课程<数据科学与金融计算>第2-3章的学习笔记,主要介绍R语言在统计和机器学习中的应用,用于知识点总结和代码练习,Q&A为问题及解决方案,参考书籍为<R软件及其在金融定 ...

  8. 【R】【课程笔记】08 金融投资组合决策分析

    本文是课程<数据科学与金融计算>第8章的学习笔记,主要介绍均值-方差模型.均值-VaR模型.均值-CVaR模型,用于知识点总结和代码练习,Q&A为问题及解决方案. 往期回顾: 博文 ...

  9. 4 Motion Planning for Self-Driving Cars 课程习题编程解答及笔记

    自动驾驶课程 - The 4th 运动规划 - 课后答案及部分解释 Module 1 Graded Quiz Module 3 Graded Quiz Module 4 Graded Quiz Mod ...

最新文章

  1. 【BZOJ】3542: DZY Loves March
  2. 你的肠道菌群是遗传自你父母,还是后天环境塑造的?
  3. Android 源码分析之 EventBus 的源码解析
  4. 经典排序算法 - 冒泡排序Bubble sort
  5. jquery template.js前端模板引擎
  6. 《阿里巴巴Android开发手册》正式发布,献给移动开发者的新年礼物
  7. 超好看的自适应蜘蛛池官网首页源码
  8. 使用PL/SQL Developer给Oracle生成漂亮的数据库说明文档
  9. python与专业相结合应用案例_Office高级应用与Python综合案例教程(普通高等教育十三五规划教材)...
  10. 【PyQt5】连接 mysql 查询数据 并显示在 tableWidget 表格
  11. python基础教程电子版-Python基础教程(第2版)PDF文档下载
  12. 小秘书的福音——使用Word VBA打造自动排版工具
  13. 【Unity】制作圆形进度条
  14. 分享大学生关于创新创业的想法,包括外卖私人订制化,网购衣服3D化远程试衣,睡眠耳机开发等等创新创业想法。
  15. swfobject2.2参数详解(swfobject.embedSWF)
  16. kindle 4.1.1越狱换中文字体
  17. lv蒙田包二手价格_盘点 | LV家保值性最高,最值得入手的五款包包
  18. 中国红薯淀粉市场供需现状调研及前景策略分析报告2022年版
  19. 首席新媒体黎想教程:3千字抖音运营攻略!
  20. 【社会调研】访谈个案案例分享

热门文章

  1. 计算机毕业设计JAVA图书个性化推荐系统mybatis+源码+调试部署+系统+数据库+lw
  2. 时间戳转换年月日——记一次字节面试题(C++实现)
  3. Excel应用技巧:不规则合并单元格之批量填充序列
  4. 【1024程序员节】创作创富-对话议题-直播笔记
  5. HTML5期末大作业:电影票务网站设计——电影票务网站整套(24页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码
  6. 实现文字后面加一条横线的效果
  7. 拼多多产品点击低怎么办?
  8. idea如何设置导包不带*号
  9. 长寿命电池密码,电池包均衡控制算法详解
  10. 邮箱如何群发邮件,公司邮件群发教程