This project focuses on implementing a Particle Filter for robot localization. Particle filters are a powerful technique used in robotics and AI to estimate the state of a system based on noisy sensor measurements. In this project, we demonstrate the effectiveness of particle filters in localizing a robot within a simulated environment.
The particle filter algorithm is implemented in C++ and simulates the process of estimating the robot's position and orientation using a set of particles. Each particle represents a possible state of the robot, and the algorithm updates the particles' weights based on sensor measurements and motion updates.
- Particle Initialization: Particles are initialized randomly across the environment.
- Motion Model: The robot's motion is simulated using a forward and rotation model.
- Sensor Model: The sensor model updates particle weights based on the robot's position in the environment.
- Resampling: Particles are resampled based on their weights to focus on the most likely states.
- Localization: The algorithm estimates the robot's position and orientation by computing the mean and variance of the particles.
- Programming Language:
C++
- Number of Particles:
100
- Sensor Model: Binary environment (Black/White regions)
- Motion Model:
Forward
movement androtation
- Resampling Method: Importance Sampling
Particle-Filter-Implementation/
│── robot.csv # CSV file containing robot motion data
│── particle_filter.cpp # Main implementation file
│── README.md # Project documentation
The code is structured as follows:
- Particle Structure: Each particle is represented by a struct
PFStruct
containing its position (x
,y
), orientation (theta
), and weight (w
). - Normalization: The
normalize
function ensures that the sum of all particle weights is 1. - CSV Reading: The
readCSVLine
function reads robot data (position, displacement, and angle) fromrobot.csv
file. - Sampling: The
sample
function selects a particle based on its weight. - Motion Update: The
forward
androtate
functions simulate the robot's motion. - Sensor Update: The
update
function updates particle weights based on sensor measurements. - Particle Filter: The
particleFilter
function performs the core particle filter algorithm, including motion and sensor updates. - Initialization: The
initializeParticles
function initializes particles randomly. - Reporting: The
report
function computes and prints the mean and variance of the particles' positions. - Sensor Simulation: The
sensor
function simulates the robot's sensor readings based on its position.
To compile the code, use the following command:
./particle_filter
The program will read the robot's data from robot.csv
, simulate the particle filter algorithm, and output the estimated position and variance of the robot.
The input file (robot.csv
) should contain the following columns:
- x: Robot's x-coordinate.
- y: Robot's y-coordinate.
- displacement: Robot's displacement.
- angle: Robot's rotation angle.
Example robot.csv
:
x,y,displacement,angle
10,20,5,30
15,25,6,45
...
The program outputs the following for each step:
- Robot's true position:
robotX
,robotY
- Estimated position:
meanParticleX
,meanParticleY
- Variance:
varParticleX
,varParticleY
Example output:
10 20 12.5 22.3 1.2 0.8
15 25 16.7 24.1 1.1 0.9
...