粒子滤波跟踪移动机器人(MATLAB Robotics System Toolbox)
MathWorks从MATLAB 2015a开始推出与ROS集成的Robotics System Toolbox(机器人系统工具箱),它为自主移动机器人的研发提供现成的算法和硬件接口。

- 粒子滤波基本流程
A particle filter is a recursive, Bayesian state estimator that uses discrete particles to approximate the posterior distribution of the estimated state.
The particle filter algorithm computes the state estimate recursively and involves two steps:
Prediction – The algorithm uses the previous state to predict the current state based on a given system model.
Correction – The algorithm uses the current sensor measurement to correct the state estimate.
The algorithm also periodically redistributes, or resamples, the particles in the state space to match the posterior distribution of the estimated state.
The estimated state consists of all the state variables. Each particle represents a discrete state hypothesis. The set of all particles is used to help determine the final state estimate.
When using a particle filter, there is a required set of steps to create the particle filter and estimate state. The prediction and correction steps are the main iteration steps for continuously estimating state.

- 粒子滤波参数
1. 粒子数目:The default number of particles is 1000. Unless performance is an issue, do not use fewer than 1000 particles. A higher number of particles can improve the estimate but sacrifices performance speed, because the algorithm has to process more particles. Tuning the number of particles is the best way to improve the tracking of your particle filter.

2. 初始位置:If you have an initial estimated state, specify it as your initial mean with a covariance relative to your system. This covariance correlates to the uncertainty of your system. The ParticleFilter object distributes particles based on your covariance around the given mean. The algorithm uses this distribution of particles to get the best estimation of state, so an accurate initialization of particles helps to converge to the best state estimation quickly. If an initial state is unknown, you can evenly distribute your particles across a given state bounds. The state bounds are the limits of your state. For example, when estimating the position of a robot, the state bounds are limited to the environment that the robot can actually inhabit. In general, an even distribution of particles is a less efficient way to initialize particles to improve the speed of convergence. The plot shows how the mean and covariance specification can cluster particles much more effectively in a space rather than specifying the full state bounds.

3. 状态转移函数:The state transition function, StateTransitionFcn, of a particle filter helps to evolve the particles to the next state. It is used during the prediction step of the Particle Filter Workflow. In the ParticleFilter object, it is specified as a callback function that takes the previous particles, and any other necessary parameters, and outputs the predicted location. By default, the state transition function assumes a Gaussian motion model with constant velocities. The function uses a Gaussian distribution to determine the position of the particles in the next time step. For your application, it is important to have a state transition function that accurately describes how you expect the system to behave. To accurately evolve all the particles, you must develop and implement a motion model for your system. If particles are not distributed around the next state, the ParticleFilter object does not find an accurate estimate. Therefore, it is important to understand how your system can behave so that you can track it accurately.
4. Measurement Likelihood Function:After predicting the next state, you can use measurements from sensors to correct your predicted state. By specifying a MeasurementLikelihoodFcn in the ParticleFilter object, you can correct your predicted particles using the correct function. This measurement likelihood function, by definition, gives a weight for the state hypotheses (your particles) based on a given measurement. Essentially, it gives you the likelihood that the observed measurement actually matches what each particle observes. This likelihood is used as a weight on the predicted particles to help with correcting them and getting the best estimation
5. 状态估计方法:The final step of the particle filter workflow is the selection of a single state estimate. The particles and their weights sampled across the distribution are used to give the best estimation of the actual state. However, you can use the particles information to get a single state estimate in multiple ways. With the ParticleFilter object, you can either choose the best estimate based on the particle with the highest weight or take a mean of all the particles. Specify the estimtation method in the StateEstimationMethod property as either'mean'(default) or 'maxweight'.
- Track a Robot Using Particle Filter
A remote-controlled robot is being tracked in the outdoor environment. The robot pose measurement is now provided by an on-board GPS, which is noisy. We also know the motion commands sent to the robot, but the robot will not execute the exact commanded motion due to mechanical part slacks and/or model inaccuracy. This example will show how to use to reduce the effects of noise in the measurement data and get a more accurate estimation of the pose of the robot. The kinematic model of a car-like robot is described by the following non-linear system.robotics.ParticleFilter


移动机器人可以控制线速度
和转向角速度
,其位置和姿态(
,
,
)可以通过GPS定位系统或光学捕捉系统等手段获取。由于存在噪声因此测量和控制都存在一定误差(There will be some difference between the commanded motion and the actual motion of the robot)。设系统状态变量为 [
,
,
,
,
,
].
机器人转向时可以看作绕着轴线上的瞬时曲率中心(The point that the robot rotates about is known as the ICC - Instantaneous Center of Curvature)旋转,曲率半径为R。假设两轮间距为L,左右轮速度分别为vl、vr,则有:


根据运动学模型,可以得到系统状态方程,状态转移函数的实现如下:
function predictParticles = BotStateTransition(pf, prevParticles, dT, u)
thetas = prevParticles(:,3);
w = u(2);
v = u(1);
n = length(prevParticles); % Generate velocity samples
sd1 = 0.3; % sd1 represents the uncertainty in the linear velocity
sd2 = 1.5; % sd2 represents the uncertainty in the angular velocity
sd3 = 0.02; % sd3 is an additional perturbation on the orientation
vh = v + (sd1)^2*randn(n,1);
wh = w + (sd2)^2*randn(n,1);
gamma = (sd3)^2*randn(n,1); % Add a small number to prevent div/0 error
wh(abs(wh)<1e-19) = 1e-19; % State Transition
predictParticles(:,1) = prevParticles(:,1) - (vh./wh).*sin(thetas) + (vh./wh).*sin(thetas + wh*dT);
predictParticles(:,2) = prevParticles(:,2) + (vh./wh).*cos(thetas) - (vh./wh).*cos(thetas + wh*dT);
predictParticles(:,3) = prevParticles(:,3) + wh*dT + gamma*dT;
predictParticles(:,4) = (- (vh./wh).*sin(thetas) + (vh./wh).*sin(thetas + wh*dT))/dT;
predictParticles(:,5) = ( (vh./wh).*cos(thetas) - (vh./wh).*cos(thetas + wh*dT))/dT;
predictParticles(:,6) = wh + gamma;
end
然后要实现Measurement Likelihood Function,它会根据预测值与测量值之间的误差大小来计算每个粒子的权值。与观测值越接近的粒子权值越大,反之越小。这个例子中粒子是一个N×6的矩阵(N为粒子数目),测量值是1×3的向量。函数的实现如下:
function likelihood = BotMeasurementLikelihood(pf, predictParticles, measurement)
% The measurement contains all state variables
predictMeasurement = predictParticles; % Calculate observed error between predicted and actual measurement
measurementError = bsxfun(@minus, predictMeasurement(:,1:3), measurement); % applies an element-by-element binary operation to arrays
measurementErrorNorm = sqrt(sum(measurementError.^2, 2)); % Normal-distributed noise of measurement
% Assuming measurements on all three pose components have the same error distribution
measurementNoise = eye(3); % Convert error norms into likelihood measure.
% Evaluate the PDF of the multivariate normal distribution
likelihood = 1/sqrt((2*pi).^3 * det(measurementNoise)) * exp(-0.5 * measurementErrorNorm);
end
下面是整个Workflow的代码,其中利用了MATLAB自带的函数ExampleHelperCarBot来创建移动机器人(该模型与汽车类似,前面两轮驱动和转向,本例与该模型存在一定的差异),并利用相关的函数来绘制跟踪图像。注意当机器人运动到有屋顶的区域时,由于遮挡GPS信号丢失,返回的测量值为空。
%% Initialize Robot
rng('default'); % for repeatable result
dt = 0.05; % Time step for simulation of the robot
initialPose = [0 0 0 0]';
carbot = ExampleHelperCarBot(initialPose, dt); %% Set up the Particle Filter
pf = robotics.ParticleFilter; initialize(pf, 5000, [initialPose(1:3)', 0, 0, 0], eye(6), 'CircularVariables',[0 0 1 0 0 0]);
pf.StateEstimationMethod = 'mean';
pf.ResamplingMethod = 'systematic'; % StateTransitionFcn defines how particles evolve without measurement
pf.StateTransitionFcn = @BotStateTransition; % MeasurementLikelihoodFcn defines how measurement affect the our estimation
pf.MeasurementLikelihoodFcn = @BotMeasurementLikelihood; % Last best estimation for x, y and theta
lastBestGuess = [0 0 0]; %% Main Loop
% Run loop at 20 Hz for 20 seconds
r = robotics.Rate(1/dt); % The Rate object enables you to run a loop at a fixed frequency
reset(r); % Reset the fixed-rate object
% Reset simulation time
simulationTime = 0;
while simulationTime < 20 % if time is not up
% Generate motion command that is to be sent to the robot
% NOTE there will be some discrepancy between the commanded motion and the motion actually executed by the robot.
uCmd(1) = 0.7*abs(sin(simulationTime)) + 0.1; % linear velocity
uCmd(2) = 0.08*cos(simulationTime); % angular velocity
drive(carbot, uCmd); % Move the robot forward contaminate commanded motion with noise
% Predict the carbot pose based on the motion model
[statePred, covPred] = predict(pf, dt, uCmd);
% Get GPS reading
% The GPS reading is just simulated by adding Gaussian Noise to the truth data.
% When the robot is in the roofed area, the GPS reading will not be available, the measurement will return an empty matrix.
measurement = exampleHelperCarBotGetGPSReading(carbot); % If measurement is available, then call correct, otherwise just use predicted result
if ~isempty(measurement)
[stateCorrected, covCorrected] = correct(pf, measurement');
else
stateCorrected = statePred;
covCorrected = covPred;
end lastBestGuess = stateCorrected(1:3); % Update plot
if ~isempty(get(groot,'CurrentFigure')) % if figure is not prematurely killed
updatePlot(carbot, pf, lastBestGuess, simulationTime);
else
break
end waitfor(r); % Update simulation time
simulationTime = simulationTime + dt;
end

可以看到在有屋顶的区域,预测值与机器人真实位置出现了较大的偏差。在机器人走出该区域后,接收到GPS测量信号对预测值进行校正,得到的估计值又收敛到真实位置。
参考:
Track a Car-Like Robot Using Particle Filter
Localize TurtleBot Using Monte Carlo Localization
Kalman-and-Bayesian-Filters-in-Python
粒子滤波跟踪移动机器人(MATLAB Robotics System Toolbox)的更多相关文章
- 激光数据匹配(MATLAB Robotics System Toolbox)
正态分布变换算法是一个配准算法,它应用于三维点的统计模型,使用标准最优化技术来确定两个点云间的最优的匹配,因为其在配准过程中不利用对应点的特征计算和匹配,所以时间比其他方法快.算法细节可以参考:NDT ...
- 粒子滤波particle filter和目标跟踪
粒子滤波用于跟踪,参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/18/2404817.html http://blog.csdn.net/ ...
- 基于粒子滤波的物体跟踪 Particle Filter Object Tracking
Video来源地址 一直都觉得粒子滤波是个挺牛的东西,每次试图看文献都被复杂的数学符号搞得看不下去.一个偶然的机会发现了Rob Hess(http://web.engr.oregonstate.edu ...
- 目标跟踪之粒子滤波---Opencv实现粒子滤波算法
目标跟踪学习笔记_2(particle filter初探1) 目标跟踪学习笔记_3(particle filter初探2) 前面2篇博客已经提到当粒子数增加时会内存报错,后面又仔细查了下程序,是代码方 ...
- Matlab Robotics Toolbox 仿真计算:Kinematics, Dynamics, Trajectory Generation
1. 理论知识 理论知识请参考: 机器人学导论++(原书第3版)_(美)HLHN+J.CRAIG著++贠超等译 机器人学课程讲义(丁烨) 机器人学课程讲义(赵言正) 2. Matlab Robotic ...
- 从贝叶斯到粒子滤波——Round 2
上一篇博文已经讲了贝叶斯滤波的原理以及公式的推导:http://www.cnblogs.com/JunhaoWu/p/bayes_filter.html 本篇文章将从贝叶斯滤波引入到粒子滤波,讲诉粒子 ...
- 从贝叶斯到粒子滤波——Round 1
粒子滤波确实是一个挺复杂的东西,从接触粒子滤波到现在半个多月,博主哦勒哇看了N多篇文章,查略了嗨多资料,很多内容都是看了又看,细细斟酌.今日,便在这里验证一下自己的修炼成果,请各位英雄好汉多多指教. ...
- 学习OpenCV——粒子滤波(网上两篇文章总结)
粒子滤波的理论实在是太美妙了,用一组不同权重的随机状态来逼近复杂的概率密度函数.其再非线性.非高斯系统中具有优良的特性.opencv给出了一个实现,但是没有给出范例,学习过程中发现网络上也找不到.le ...
- 理解粒子滤波(particle filter)
1)初始化阶段-提取跟踪目标特征 该阶段要人工指定跟踪目标,程序计算跟踪目标的特征,比如可以采用目标的颜色特征.具体到Rob Hess的代码,开始时需要人工用鼠标拖动出一个跟踪区域,然后程序自动计算该 ...
随机推荐
- 如何使用LaTeX让自己不乱?
虽然说LaTeX声称排版容易,只关注内容,可是混合着源代码的结构很难让我只关注内容,最后看得眼睛疼,找什么都找不到. 匿名用户 30 人赞同 立即想到的几个建议: 选择有折叠功能 (folding) ...
- scrapy框架系列 (3) Item Pipline
item pipeline 当Item在Spider中被收集之后,它将会被传递到Item Pipeline,这些Item Pipeline组件按定义的顺序处理Item. 每个Item Pipeline ...
- mysql 5.1简明教程
第一章Mysql简介与安装 第一节 MySql简介 百度百科 第二节 MySql安装与配置 1.MySql5.1下载及安装 2.MySql数据库编码配置 UTF-8 3.MySql图形页面sqlyog ...
- vue路由跳转传参数
1. router-link <router-link :to="{ path: 'yourPath', params: { name: 'name', dataObj: data } ...
- Zend Studio 实用快捷键大全
编辑功能 组合键 实现功能 适用条件 Ctrl+/ 单行注释.当前为php代码时,则在光标所在行添加双斜杠行注释,选择多行则每一行都添加双斜杠:而当代码为html时则在行前后添加<!-- --& ...
- 利用shell脚本批量提交网站404死链给百度
网站运营人员对于死链这个概念一定不陌生,网站的一些数据删除或页面改版等都容易制造死链,影响用户体验不说,过多的死链还会影响到网站的整体权重或排名. 百度站长平台提供的死链提交工具,可将网站存在的死链( ...
- 数据结构 - 2-路插入排序 具体解释 及 代码(C++)
2-路插入排序 具体解释 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24267679 2-路插入排序的思想非常有意思 ...
- 发布web应用程序是出现unsafe code
找到了解决办法 解决方法参照: https://stackoverflow.com/questions/16567197/publish-web-application-with-unsafe-cod ...
- 10.2.1itools导入不了歌曲
首先下载iTools 4抢先版,下载地址:http://update2.itools.hk/api/v1/redirect?p=itools4&c=pc_Thinksky 点击电脑桌面左下方“ ...
- 使用Snap.svg类库实现的抖动式的幻灯播放效果
在线演示 本地下载 这个幻灯中,使用了SVG来生成具有动画弧度的幻灯背景效果,如果你在项目中能够支持现代浏览器的话,尝试一下这个效果吧,很赞! 想了解基础使用,观看这个轻视频吧:Snap.svg处理和 ...