Prticle Filter Project
Your robot has been kidnapped and transported to a new location! Luckily it has a map of this location, a (noisy) GPS estimate of its initial location, and lots of (noisy) sensor and control data.
In this project you will implement a 2 dimensional particle filter in C++. Your particle filter will be given a map and some initial localization information (analogous to what a GPS would provide). At each time step your filter will also get observation and control data.
The program main.cpp has already been filled out, but feel free to modify it.
Here is the main protocol that main.cpp uses for uWebSocketIO in communicating with the simulator.
INPUT: values provided by the simulator to the c++ program
// sense noisy position data from the simulator
["sense_x"]
["sense_y"]
["sense_theta"]
// get the previous velocity and yaw rate to predict the particle's transitioned state
["previous_velocity"]
["previous_yawrate"]
// receive noisy observation data from the simulator, in a respective list of x/y values
["sense_observations_x"]
["sense_observations_y"]
OUTPUT: values provided by the c++ program to the simulator
// best particle values used for calculating the error evaluation
["best_particle_x"]
["best_particle_y"]
["best_particle_theta"]
//Optional message data used for debugging particle's sensing and associations
// for respective (x,y) sensed positions ID label
["best_particle_associations"]
// for respective (x,y) sensed positions
["best_particle_sense_x"] <= list of sensed x positions
["best_particle_sense_y"] <= list of sensed y positions
Your job is to build out the methods in particle_filter.cpp
until the simulator output says:
Success! Your particle filter passed!
The directory structure of this repository is as follows:
root
| build.sh
| clean.sh
| CMakeLists.txt
| README.md
| run.sh
|
|___data
| |
| | map_data.txt
|
|
|___src
| helper_functions.h
| main.cpp
| map.h
| particle_filter.cpp
| particle_filter.h
The only file you should modify is particle_filter.cpp
in the src
directory. The file contains the scaffolding of a ParticleFilter
class and some associated methods. Read through the code, the comments, and the header file particle_filter.h
to get a sense for what this code is expected to do.
If you are interested, take a look at src/main.cpp
as well. This file contains the code that will actually be running your particle filter and calling the associated methods.
You can find the inputs to the particle filter in the data
directory.
map_data.txt
includes the position of landmarks (in meters) on an arbitrary Cartesian coordinate system. Each row has three columns
- x position
- y position
- landmark id
- Map data provided by 3D Mapping Solutions GmbH.
- Open Eclipse IDE
Linux:
docker run --rm --name kidnap \
--net=host -e DISPLAY=$DISPLAY \
-v $HOME/.Xauthority:/root/.Xauthority \
dragon7/carnd-kidnapped-vehicle-project
Mac:
socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"
docker run --rm --name kidnap \
-e DISPLAY=[IP_ADDRESS]:0 \
-p 4567:4567 \
dragon7/carnd-kidnapped-vehicle-project
-
Import the project into Eclipse
- Open Eclipse.
- Import project using Menu
File > Import
- Select
General > Existing projects into workspace
- Browse
/root/workspace/CarND-Kidnapped-Vehicle-Project/build
and select the root build tree directory. Keep "Copy projects into workspace" unchecked. - Now you should have a fully functional eclipse project
-
Code Style
- From Eclipse go to
Window > Preferences > C/C++ > Code Style > Formatter
- Click Import
- Select
/root/workspace/eclipse-cpp-google-style.xml
- Click Ok
- From Eclipse go to
-
Build
OPTIONAL: Build on command line
cd /root/workspace/CarND-Kidnapped-Vehicle-Project/build make
-
Run
OPTIONAL: Run on command line
/particle_filter
-
Launch simulator
- Set the number of particles.
num_particles = 100;
- Initialize all particles to first position (based on estimates of x, y, theta and their uncertainties from GPS) and all weights to 1.
- Add random Gaussian noise to each particle.
NOTE: When adding noise you may find std::normal_distribution
and std::default_random_engine
useful.
- Add measurements to each particle and add random Gaussian noise.
Yaw rate = 0 | Yaw rate != 0 |
---|---|
NOTE: Here we will use what we learned in the motion models lesson to predict where the vehicle will be at the next time step, by updating based on yaw rate and velocity, while accounting for Gaussian sensor noise.
-
Update the weights of each particle using a mult-variate Gaussian distribution.
- Transform observations from vehicle coordinates to map coordinates.
NOTE: The observations are given in the VEHICLE'S coordinate system. Your particles are located according to the MAP'S coordinate system. You will need to transform between the two systems. Keep in mind that this transformation requires both rotation AND translation (but no scaling).
-
Filter map landmarks to keep only those which are in the sensor_range of current particle. Push them to predictions vector.
-
Associate observations to predicted landmarks using nearest neighbor algorithm.
NOTE: Find the predicted measurement that is closest to each observed measurement and assign the observed measurement to this particular landmark.
- Calculate the weight of each particle using Multivariate Gaussian distribution.
- Normalize the weights of all particles since resampling using probabilistic approach.
- Resample particles with replacement with probability proportional to their weight.