Main Content

getParticles

Get particles from localization algorithm

Description

example

[particles,weights] = getParticles(mcl) returns the current particles used by the monteCarloLocalization object. particles is an n-by-3 matrix that contains the location and orientation of each particle. Each row has a corresponding weight value specified in weights. The number of rows can change with each iteration of the MCL algorithm. Use this method to extract the particles and analyze them separately from the algorithm.

Examples

collapse all

Get particles from the particle filter used in the Monte Carlo Localization object.

Create a map and a Monte Carlo localization object.

map = binaryOccupancyMap(10,10,20);
mcl = monteCarloLocalization(map);

Create robot data for the range sensor and pose.

ranges = 10*ones(1,300);
ranges(1,130:170) = 1.0;
angles = linspace(-pi/2,pi/2,300);
odometryPose = [0 0 0];

Initialize particles using step.

[isUpdated,estimatedPose,covariance] = step(mcl,odometryPose,ranges,angles);

Get particles from the updated object.

[particles,weights] = getParticles(mcl);

Input Arguments

collapse all

monteCarloLocalization object, specified as an object handle.

Output Arguments

collapse all

Estimation particles, returned as an n-by-3 vector, [x y theta]. Each row corresponds to the position and orientation of a single particle. The length can change with each iteration of the algorithm.

Weights of particles, returned as a n-by-1 vector. Each row corresponds to the weight of the particle in the matching row of particles. These weights are used in the final estimate of the pose of the vehicle. The length can change with each iteration of the algorithm.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2019b