-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle_filter.h
121 lines (94 loc) · 3.46 KB
/
particle_filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* particle_filter.h
*
* 2D particle filter class.
* Created on: Dec 12, 2016
* Author: Tiffany Huang
*/
#ifndef PARTICLE_FILTER_H_
#define PARTICLE_FILTER_H_
#include "helper_functions.h"
struct Particle {
int id;
double x;
double y;
double theta;
double weight;
std::vector<int> associations;
std::vector<double> sense_x;
std::vector<double> sense_y;
};
class ParticleFilter {
// Number of particles to draw
int num_particles;
// Flag, if filter is initialized
bool is_initialized;
// Vector of weights of all particles
std::vector<double> weights;
public:
// Set of current particles
std::vector<Particle> particles;
// Constructor
// @param num_particles Number of particles
ParticleFilter() : num_particles(0), is_initialized(false) {}
// Destructor
~ParticleFilter() {}
/**
* init Initializes particle filter by initializing particles to Gaussian
* distribution around first position and all the weights to 1.
* @param x Initial x position [m] (simulated estimate from GPS)
* @param y Initial y position [m]
* @param theta Initial orientation [rad]
* @param std[] Array of dimension 3 [standard deviation of x [m], standard deviation of y [m]
* standard deviation of yaw [rad]]
*/
void init(double x, double y, double theta, double std[]);
/**
* prediction Predicts the state for the next time step
* using the process model.
* @param delta_t Time between time step t and t+1 in measurements [s]
* @param std_pos[] Array of dimension 3 [standard deviation of x [m], standard deviation of y [m]
* standard deviation of yaw [rad]]
* @param velocity Velocity of car from t to t+1 [m/s]
* @param yaw_rate Yaw rate of car from t to t+1 [rad/s]
*/
void prediction(double delta_t, double std_pos[], double velocity, double yaw_rate);
/**
* dataAssociation Finds which observations correspond to which landmarks (likely by using
* a nearest-neighbors data association).
* @param predicted Vector of predicted landmark observations
* @param observations Vector of landmark observations
*/
void dataAssociation(std::vector<LandmarkObs> predicted, std::vector<LandmarkObs>& observations);
/**
* updateWeights Updates the weights for each particle based on the likelihood of the
* observed measurements.
* @param sensor_range Range [m] of sensor
* @param std_landmark[] Array of dimension 2 [standard deviation of range [m],
* standard deviation of bearing [rad]]
* @param observations Vector of landmark observations
* @param map Map class containing map landmarks
*/
void updateWeights(double sensor_range, double std_landmark[], std::vector<LandmarkObs> observations,
Map map_landmarks);
/**
* resample Resamples from the updated set of particles to form
* the new set of particles.
*/
void resample();
/*
* Set a particles list of associations, along with the associations calculated world x,y coordinates
* This can be a very useful debugging tool to make sure transformations are correct and assocations correctly connected
*/
Particle SetAssociations(Particle particle, std::vector<int> associations, std::vector<double> sense_x, std::vector<double> sense_y);
std::string getAssociations(Particle best);
std::string getSenseX(Particle best);
std::string getSenseY(Particle best);
/**
* initialized Returns whether particle filter is initialized yet or not.
*/
const bool initialized() const {
return is_initialized;
}
};
#endif /* PARTICLE_FILTER_H_ */