Your vehicle 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.
This project implements a 2 dimensional particle filter in C++. The 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.
Note that despite what the name suggests, due to the way it is implemented, the particle filter won't work well (or at all) in situations where the vehicle is indeed kidnapped during the simulation. Speficially, particles are only resampled with replacement from the previous generation; however, no new particles will ever be created at random. This means that after convergence on a good pose estimate, the filter would need to be reinitialized completely to handle a kidnapping situation. In this case, each generation's particle weights should be low, so this situation could at least be detected.
This code makes use of the libssrckdtree library
for aligning measurements and landmarks. The code is bundled in the vendor/libssrckdtree
directory
and is licensed under an Apache 2.0 License.
This project involves the Term 2 Simulator which can be downloaded here
This repository includes two files that can be used to set up and install uWebSocketIO for either Linux or Mac systems. For windows you can use either Docker, VMware, or even Windows 10 Bash on Ubuntu to install uWebSocketIO.
Once the install for uWebSocketIO is complete, the main program can be built and ran by doing the following from the project top directory.
mkdir build
cd build
cmake ..
make
./particle_filter
If, for whatever reason, you do not want to build using libssrc, e.g. because it requires libraries not available on your system, you can enable "naive" keypoint matching mode by running CMake as follows:
cmake -DUSE_ASSOCIATION_NAIVE=On -DNUM_PARTICLES=100 ..
Note that the number of particles will be reduced to improve performance.
Alternatively some scripts have been included to streamline this process, these can be leveraged by executing the following in the top directory of the project:
./clean.sh
./build.sh
./run.sh
Tips for setting up your environment can be found here
Here is the main protocol that main.cpp uses for uWebSocketIO in communicating with the simulator.
Sense noisy position data from the simulator:
["sense_x"]
<= X coordinate["sense_y"]
<= Y coordinate["sense_theta"]
<= Orientation in radians
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"]
Best particle values used for calculating the error evaluation:
["best_particle_x"]
["best_particle_y"]
["best_particle_theta"]
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
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
| | data_association_naive.cpp
| | data_association_libssrckdtree.cpp
|
|
|___vendor
|___libssrckdtree
| ...
The main file of interest particle_filter.cpp
in the src
directory.
The file contains the scaffolding of a ParticleFilter
class and some associated methods. Different methods of
associating landmarks with measurements are implemented; these can be found in the data_association_naive.cpp
and
data_association_libssrckdtree.cpp
files.
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.
If your particle filter passes the current grading code in the simulator (you can make sure you have the current
version at any time by doing a git pull
), then you should pass!
The things the grading code is looking for are:
- Accuracy: your particle filter should localize vehicle position and yaw to within the values specified in the parameters
max_translation_error
andmax_yaw_error
insrc/main.cpp
. - Performance: your particle filter should complete execution within the time of 100 seconds.