Search code examples
positionsensorsrobotkalman-filterproximitysensor

2 questions about this simple 1D Kalman case


So I'm trying to learn how to use Kalman filters to implement them in a small robot at some point. This video and the following webpage have been really good sources for me to understand these filters:

YouTube: Kalman Filter Tutorial
http://bilgin.esme.org/BitsBytes/KalmanFilterforDummies.aspx

Let's take a simple 1D case where I have a sensor platform that has 1 distance sensor on either side, we'll say L is the left side sensor and R is the right side. The robot is bound in a box that is 100 units long, each sensor has a range of only 10 units and we consider any value from them greater than ~7.5 to be invalid.

The platform will move forward while X <= 95, then reverse while X >= 5, I want to use the filter to estimate X, and use the data coming in from L/R to correct X when I get close to a wall. My points of contention are as follows:

  1. At 15:50 in the video, Francis Govers says that if you lose a sensor then the error will go to infinity, and you'll be able to tell that your sensor isn't giving good data. However when I implement that 1D case presented on the webpage, the error continues to decrease even when I feed it wildly varying data. Why? Shouldn't the error increase?

  2. Relating to 1, what do I do when the error gets too high or I know a sensor is giving invalid data? Do I simply not include the sensor in the correction step until otherwise?

I'm sorry if these have been asked before, I'm normally very adept at finding answers myself, but these questions seem to be a bit obscure (or more likely the answer is obvious) but I just can't seem to find it myself.


Solution

    1. I'm not familiar with that video at all, but he might mean that if you repeatedly add process noise (P = FPF' + Q) but never reduce P via measurement, then P can only increase. In general, though, I would caution you against considering the covariance matrix P as an output of your filter. You'll notice that it isn't affected by your measurements (other than the lack of them) or your state. It's only affected by repeatedly applying your own estimates of process and measurement noise (Q and R) so if you are wrong (for example, as you tried, putting in garbage measurements with the same R) you will still get the same P.
    2. One of the fundamental assumptions of the Kalman Filter is that all of your noise is Gaussian (classic bell curve distribution) and zero mean. You can fudge a lot on the distribution, but it is very important that your noise averages out to zero. This is written as E(v) = 0, the expected value. If your sensor reads "about 5" or 5 + v where v is a random variable with zero mean then averaging your sensor readings will get you a result very close to 5. This is how your sensor works when it is in range. The magnitude of v is what you're estimating in R so the filter knows how much averaging is required. If your sensor is out of range then you are better off not including it in the measurement. When the sensor reads off-scale the value is not "about 10" it's "probably at least 10 and maybe a lot more" and your noise has a bias.