The short answer is yes. As time goes on without a measurement you trust measurements more and more.
I ended up writing a lot more than I originally though I would so I hope this helps. If you have any questions about something I wrote or something else feel free to ask. I havenât done any college courses or something on the topic so I might not know everything but I will answer to the best of my ability.
The kalman filter has a model which it uses to calculate where it is given the inputs you gave to it (in this case the model is odometry). On top of that you can add measurements to correct errors created by the model.
The kalman filter has a number P (technically this is a matrix) which tells it how much to trust the model (odometry). If P is 0 that means you can trust the model completely and itâs position is completely correct. If P is small that means we can trust the model relatively well because the position it tells us reflects or real position pretty well. If P is large then that means we cannot trust the model a lot and because it is far away from our position. What is important to understand is that P is a representation of how far away our model is from our actual position.
Now the kalman filter can do 2 things
- Use our model to predict where we will be given certain inputs
- Correct our model using certain measurements
We will try to understand how each of these is affected by P and how each of these affects P
Prediction
When we predict where our system is going to be we use our model to calculate where we are going to be in the future. In a world where we had a perfect model we would only need to do this because the model could calculate exactly where we are. Unfortunately we are not on a perfect world and so our model cannot calculate exactly where we will be. There are 2 contributing factors two this. First, the actual model for our system is very complex so we use a simplified one that can predict our system pretty well but not perfectly. Second there is process noise (disturbances we cannot model such as friction or air resistance) in our system and that causes our model to be worse as well. So in the end our model can predict where we will be in the future (in the case of code the next code cycle) but not with perfect accuracy.
Therefore each time we predict statistically the distance between where the model thinks we are and where we actually are grows. Now remember the relationship we said there is between P and this distance between the model and our real position. When we predicted, the distance grew, and therefore P must also grow.
In summary each time we predict our next position P grows and therefore we trust our model less.
Measurement
When we add a measurement we are telling our system were it should actually be. Effectively we are telling our system that itâs model may be incorrect and this new externally measured position may be more correct. Of course the measurement is also not necessarily completely correct and so we should not trust it entirely either. Therefore we need to find some way to combine the position the system thinks it is in and the external measurement based on how much we trust each of them.
So how much do we trust actually trust each of them? Well earlier we said that P represents how much we trust our model, and so we will use it to combine the measurements. We also need to know how much we trust the measurement, but this changes based on the type of measurement (Camera, Lidar, etc.) and the situation of the measurement (How fast we were moving when we took the frame, distance from the target, etc.). So to take this into account along with every measurement we add a number R (Technically this is also a matrix) which tells us how much we trust the measurement. Now you probably know this as standard deviation which you put in the code because standard deviation is a slightly simplified version of R (They still work very well for what we are doing).
So how do we combine these two measurements. There is some math behind this but the easiest way to think about this is as a weighted average. We say that
x_{corrected} = \frac{x_{model} * P + x_{measurement} * R}{P + R}
Now this isnât exactly correct because it assumes that we trust P and R more if they are larger which is the opposite of what is true. Therefore it would be closer to the truth if it was 1 / P and 1 / R in the equations but the point is that you combine the two values using P and R as weights.
Now that we have combined the two we can plug the corrected X into the model and continue any other calculations (such as predicting and using this value in our code) using this new X. On top of this because we have now added a measurement this new X should statistically be closer to our real position and therefore P gets smaller.
In summary when we add a measurement we do 2 things
- We find a more correct position based off a combination of our model and measurement. We know how much to trust each of these based off of P and our standard deviations for the measurement.
- Because we know trust our position more as we have more data for it we decrease P and trust our model more from now on.
So in general we have 2 things we can do
- Predict where we our going to be which increases P and decreases how much we trust the model
- Add a measurement which changes our position based off of P and decreases P causing us to trust our model more.
So now to answer your initial question. We are periodically predicting where we will be to keep our model up to date. The more we predict P gets larger, we trust our model less and we trust measurements more. Therefore if we went 0.1 seconds since the last measurement P will be relatively small and therefore we wonât trust our measurement very much compared to our model. If we get 2 seconds since the last measurement P will be large and therefore we will trust our measurements more. if we have 10 seconds since the last measurement then P will be very large as we have predicted a lot and therefore we will trust our measurements almost completely.