Skip to content

Commit

Permalink
Term 2: project 3 implementation: Particle Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz Reichert committed Dec 9, 2017
1 parent 9dd9a37 commit 5788d92
Show file tree
Hide file tree
Showing 16 changed files with 13,941 additions and 0 deletions.
28 changes: 28 additions & 0 deletions particle-filter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
project(PARTICLE_FILTER)

cmake_minimum_required (VERSION 3.5)

add_definitions(-std=c++11)

set(CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS, "${CXX_FLAGS}")

set(sources src/io.cpp src/particle_filter.cpp src/main.cpp)


if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

include_directories(/usr/local/include)
include_directories(/usr/local/opt/openssl/include)
link_directories(/usr/local/lib)
link_directories(/usr/local/opt/openssl/lib)
link_directories(/usr/local/Cellar/libuv/1.11.0/lib)

endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")


add_executable(particle_filter ${sources})


target_link_libraries(particle_filter z ssl uv uWS)

134 changes: 134 additions & 0 deletions particle-filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Overview
This repository contains all the code needed to complete the final project for the Localization course in Udacity's Self-Driving Car Nanodegree.

#### Submission
All you will submit is your completed version of `particle_filter.cpp`, which is located in the `src` directory. You should probably do a `git pull` before submitting to verify that your project passes the most up-to-date version of the grading code (there are some parameters in `src/main.cpp` which govern the requirements on accuracy and run time.)

## Project Introduction
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.

## Running the Code
This project involves the Term 2 Simulator which can be downloaded [here](https://github.com/udacity/self-driving-car-sim/releases)

This repository includes two files that can be used to set up and intall 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

Note that the programs that need to be written to accomplish the project are src/particle_filter.cpp, and particle_filter.h

The program main.cpp has already been filled out, but feel free to modify it.

Here is the main protcol 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!
```

# Implementing the Particle Filter
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.

## Inputs to the Particle Filter
You can find the inputs to the particle filter in the `data` directory.

#### The Map*
`map_data.txt` includes the position of landmarks (in meters) on an arbitrary Cartesian coordinate system. Each row has three columns
1. x position
2. y position
3. landmark id

### All other data the simulator provides, such as observations and controls.

> * Map data provided by 3D Mapping Solutions GmbH.
## Success Criteria
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:


1. **Accuracy**: your particle filter should localize vehicle position and yaw to within the values specified in the parameters `max_translation_error` and `max_yaw_error` in `src/main.cpp`.

2. **Performance**: your particle filter should complete execution within the time of 100 seconds.


19 changes: 19 additions & 0 deletions particle-filter/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Script to build all components from scratch, using the maximum available CPU power
#
# Given parameters are passed over to CMake.
# Examples:
# * ./build_all.sh -DCMAKE_BUILD_TYPE=Debug
# * ./build_all.sh VERBOSE=1
#
# Written by Tiffany Huang, 12/14/2016
#

# Go into the directory where this bash script is contained.
cd `dirname $0`

# Compile code.
mkdir -p build
cd build
cmake ..
make -j `nproc` $*
14 changes: 14 additions & 0 deletions particle-filter/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Script to clean the tree from all compiled files.
# You can rebuild them afterwards using "build.sh".
#
# Written by Tiffany Huang, 12/14/2016
#

# Remove the dedicated output directories
cd `dirname $0`

rm -rf build

# We're done!
echo Cleaned up the project!
21 changes: 21 additions & 0 deletions particle-filter/cmakepatch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- CMakeLists.txt 2017-03-23 20:58:47.000000000 +0900
+++ CMakeListsnew.txt 2017-03-23 20:57:33.000000000 +0900
@@ -32,10 +32,16 @@
target_link_libraries (uWS LINK_PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
target_link_libraries (uWS LINK_PUBLIC ${ZLIB_LIBRARY})

-if (UNIX)
+if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries (uWS LINK_PUBLIC pthread)
install (TARGETS uWS DESTINATION /usr/lib64)
install (FILES src/Extensions.h src/WebSocketProtocol.h src/Networking.h src/WebSocket.h src/Hub.h src/Group.h src/Node.h src/Socket.h src/HTTPSocket.h src/uWS.h src/uUV.h DESTINATION /usr/include/uWS)
-endif (UNIX)
+endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+
+if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+target_link_libraries (uWS LINK_PUBLIC pthread)
+install (TARGETS uWS DESTINATION /usr/local/lib)
+install (FILES src/Extensions.h src/WebSocketProtocol.h src/Networking.h src/WebSocket.h src/Hub.h src/Group.h src/Node.h src/Socket.h src/HTTPSocket.h src/uWS.h src/uUV.h DESTINATION /usr/local/include/uWS)
+endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

add_subdirectory(examples)
42 changes: 42 additions & 0 deletions particle-filter/data/map_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
92.064 -34.777 1
61.109 -47.132 2
17.42 -4.5993 3
-7.1285 -34.54 4
232.32 32.032 5
177.43 28.083 6
286.89 18.159 7
274.37 31.197 8
47.484 -36.786 9
69.2 -78.217 10
124.61 24.277 11
36.203 14.827 12
-39.786 -12.615 13
-38.025 -99.976 14
267.33 -14.272 15
28.898 -39.754 16
-29.836 -23.277 17
255.67 9.8137 18
13.452 -72.827 19
102.04 5.1777 20
62.838 1.9057 21
-14.947 -61.919 22
15.162 -97.037 23
36.626 -28.898 24
172.16 -15.217 25
136.95 -14.13 26
-41.714 -61.328 27
39.556 -47.361 28
195.65 8.6677 29
278 13.181 30
151.03 8.9127 31
8.7638 7.5647 32
83.006 20.959 33
205.39 29.686 34
264.51 24.454 35
214.54 -7.8711 36
53.27 -55.233 37
20.139 -20.15 38
8.2018 -20.97 39
-13.641 -0.098341 40
278.92 21.918 41
170.62 28.733 42
14 changes: 14 additions & 0 deletions particle-filter/install-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
brew install openssl libuv cmake
git clone https://github.com/uWebSockets/uWebSockets
cd uWebSockets
git checkout e94b6e1
patch CMakeLists.txt < ../cmakepatch.txt
mkdir build
export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
cd build
cmake ..
make
sudo make install
cd ..
cd ..
sudo rm -r uWebSockets
13 changes: 13 additions & 0 deletions particle-filter/install-ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
sudo apt-get install libuv1-dev libssl-dev
git clone https://github.com/uWebSockets/uWebSockets
cd uWebSockets
git checkout e94b6e1
mkdir build
cd build
cmake ..
make
sudo make install
cd ..
cd ..
sudo ln -s /usr/lib64/libuWS.so /usr/lib/libuWS.so
sudo rm -r uWebSockets
9 changes: 9 additions & 0 deletions particle-filter/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Script to run particle filter!
#
# Written by Tiffany Huang, 12/14/2016
#

# Run particle filter
cd ./build
./particle_filter
17 changes: 17 additions & 0 deletions particle-filter/src/io.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <fstream>

#include "map.hpp"

namespace particle_filter_project {

using std::istream;

istream& operator>>(istream& ins, Landmark& l) {
ins >> l.x
>> l.y
>> l.id;

return ins;
}

} // namespace particle_filter_project
Loading

0 comments on commit 5788d92

Please sign in to comment.