Bayes Filter Overview
Implementation of Bayes Filter
Prediction Step
- Compute Control
To predict the pose of the robot, I need the the odometry motion model , which needs the relative odometry motion of the robot. The relative odometry motion is in the format (initial rotation 'delta_rot_1', translation 'delta_trans', final rotation 'delta_rot_2') and can be computed from the previous pose(state) and the current pose(state) of the robot.
- Odometry Motion Model
Then, the odometry motion model can be built to calculate how likely it is that the robot's state transitions from the previous pose to the current pose under the actual control actions.
- Prediction Step
Finally, the probability of the robot reaching each potential state can be calculated based on its previous state and control inputs. This requires two nested sets of loops, each with three loops iterating over the x, y, and theta dimensions of the previous and current states, respectively. To reduce the computation time, I omits states with a probability lower than 0.0001, as they have negligible impact. After prediction and update, the belief matrix is normalized to ensure that the sum of probabilities across all states equals 1.
Update Step
Sensor Model
The filter next requires a sensor model to update the estimate of the robot state based on the sensor data. The model aims to compute the probability of actual sensor observations and store these probabilities in a one-dimensional array with 18 elements. It utilizes the sensor noise variable and computes each probability using a Gaussian distribution.
Update Step
The update step for the Bayesian filter is to adjust the belief matrix based on the robot's sensor readings. This involves examining each cell in the grid and calculating the likelihood that the robot is located in that cell based on the sensor data. After calculating the likelihood of each cell, the belief matrix is updated accordingly. Finally, the matrix is normalized to ensure that the total probability of all cells is equal to 1, thus ensuring that it remains a valid probability distribution.
Demo
Discussion
In the video, the blue line represents "beliefs" which is the most likely state after each iteration of the Bayes Filter, the green line represents "ground truth", and the red line represents "measurements". You can see that the blue line follows the red line in most cases, only when the robot moves a short distance, the updated position will be inaccurate because we only split the map into large grids.