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 robotics.ParticleFilter 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.

  移动机器人可以控制线速度和转向角速度,其位置和姿态(, , )可以通过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测量信号对预测值进行校正,得到的估计值又收敛到真实位置。

参考:

Particle Filter Workflow

Particle Filter Parameters

Track a Car-Like Robot Using Particle Filter

Localize TurtleBot Using Monte Carlo Localization

机器人粒子滤波定位(蒙特卡罗定位)

Kalman-and-Bayesian-Filters-in-Python

粒子滤波跟踪移动机器人(MATLAB Robotics System Toolbox)的更多相关文章

  1. 激光数据匹配(MATLAB Robotics System Toolbox)

    正态分布变换算法是一个配准算法,它应用于三维点的统计模型,使用标准最优化技术来确定两个点云间的最优的匹配,因为其在配准过程中不利用对应点的特征计算和匹配,所以时间比其他方法快.算法细节可以参考:NDT ...

  2. 粒子滤波particle filter和目标跟踪

    粒子滤波用于跟踪,参考:http://www.cnblogs.com/tornadomeet/archive/2012/03/18/2404817.html http://blog.csdn.net/ ...

  3. 基于粒子滤波的物体跟踪 Particle Filter Object Tracking

    Video来源地址 一直都觉得粒子滤波是个挺牛的东西,每次试图看文献都被复杂的数学符号搞得看不下去.一个偶然的机会发现了Rob Hess(http://web.engr.oregonstate.edu ...

  4. 目标跟踪之粒子滤波---Opencv实现粒子滤波算法

    目标跟踪学习笔记_2(particle filter初探1) 目标跟踪学习笔记_3(particle filter初探2) 前面2篇博客已经提到当粒子数增加时会内存报错,后面又仔细查了下程序,是代码方 ...

  5. Matlab Robotics Toolbox 仿真计算:Kinematics, Dynamics, Trajectory Generation

    1. 理论知识 理论知识请参考: 机器人学导论++(原书第3版)_(美)HLHN+J.CRAIG著++贠超等译 机器人学课程讲义(丁烨) 机器人学课程讲义(赵言正) 2. Matlab Robotic ...

  6. 从贝叶斯到粒子滤波——Round 2

    上一篇博文已经讲了贝叶斯滤波的原理以及公式的推导:http://www.cnblogs.com/JunhaoWu/p/bayes_filter.html 本篇文章将从贝叶斯滤波引入到粒子滤波,讲诉粒子 ...

  7. 从贝叶斯到粒子滤波——Round 1

    粒子滤波确实是一个挺复杂的东西,从接触粒子滤波到现在半个多月,博主哦勒哇看了N多篇文章,查略了嗨多资料,很多内容都是看了又看,细细斟酌.今日,便在这里验证一下自己的修炼成果,请各位英雄好汉多多指教. ...

  8. 学习OpenCV——粒子滤波(网上两篇文章总结)

    粒子滤波的理论实在是太美妙了,用一组不同权重的随机状态来逼近复杂的概率密度函数.其再非线性.非高斯系统中具有优良的特性.opencv给出了一个实现,但是没有给出范例,学习过程中发现网络上也找不到.le ...

  9. 理解粒子滤波(particle filter)

    1)初始化阶段-提取跟踪目标特征 该阶段要人工指定跟踪目标,程序计算跟踪目标的特征,比如可以采用目标的颜色特征.具体到Rob Hess的代码,开始时需要人工用鼠标拖动出一个跟踪区域,然后程序自动计算该 ...

随机推荐

  1. SRE学习笔记:分布式共识系统、Paxos协议

    最近阅读了<SRE Google运维解密>的第23章,有一些感触,记录一下. 日常工作中,我们经常需要一些服务分布式的运行.跨区域如跨城.跨洲部署运行分布式系统往往是容易的,但是如何保证各 ...

  2. Java反编译工具CFR,Procyon简介

    Java反编译工具有很多,个人觉得使用最方便的是jd-gui,当然jad也不错,jd-gui主要提供了图形界面,操作起来很方便,但是jd-gui很久没有更新了,java 7出来很久了,jd-gui在反 ...

  3. Linux命令之du

    Linux du命令用来查看文件或目录所占用磁盘空间的大小(Summarize disk usage of each FILE, recursively for directories.) 语法: d ...

  4. Identifier:GUID (全局唯一标识符)

    ylbtech-Miscellaneos-Identifier:GUID (全局唯一标识符) A,返回顶部 1, 全局唯一标识符(GUID,Globally Unique Identifier)是一种 ...

  5. 聊聊jdbc statement的fetchSize

    在使用MySQL的JDBC时,如果查询结果集过大,使用一次查询,可能会出现Java.lang.OutOfMemoryError: Java heap space问题,因为DB服务器端一次将查询到的结果 ...

  6. Asp.net WebAPi Restful 的实现和跨域

    现在实际开发中用webapi来实现Restful接口开发很多,我们项目组前一段时间也在用这东西,发现大家用的还是不那么顺畅,所以这里写一个Demo给大家讲解一下,我的出发点不是如何实现,而是为什么? ...

  7. Word Ladder leetcode java

    题目: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...

  8. Cognos11只需简单几步创建你的Dashboard

    一.环境 操作系统:win10 数据库   :SQLserver 2008 R2 软件版本:IBM Cognos Analytics 11.0.6 浏览器   :IE 11 二.开始创建仪表板 2.1 ...

  9. Xamarin/Mono IOS Limitations

    http://developer.xamarin.com/guides/ios/advanced_topics/limitations/ Since applications on the iPhon ...

  10. MFC对话框:模态对话框及其弹出过程

    From: http://www.jizhuomi.com/school/c/160.html 加法计算器对话框程序大家照着做一遍后,相信对基于对话框的程序有些了解了,有个好的开始对于以后的学习大有裨 ...