Kalman Filter

From Bike Wiki
Revision as of 15:11, 10 May 2019 by 128.84.127.65 (talk) (The Kalman Filter Equation)
Jump to navigation Jump to search

The Kalman Filter provides a way to filter GPS data, reducing the effects of noise and increasing accuracy.

The Kalman Filter Equation

The problem with GPS data

The idea behind the bike’s GPS system is to receive live GPS data while the bike is running, and use that data to determine the current position of the bike and where it needs to go. In theory, simply receiving GPS data and interpreting it without any filtering would work properly, however, with inaccuracies and noise affecting the GPS, a filter is needed to more accurately determine the location of the bike. The Kalman filter is the bike’s current solution to sensor fusion and filtering method for GPS data, and it helps reduce noise and increase the accuracy of the GPS plotting.

Basic Filtering

The general idea behind the Kalman filter is to combine a number of averaging techniques that give an accurate estimate of the actual location. One of these techniques used is Dead Reckoning, which determines position based on previous position and speed. Say the position of the bike at time k is represented by the variable xk. We can inductively define xk to be equal to axk-1, where a is some constant, and xk-1 is the position of the bike at time k-1. Using this, we define each position based on the previous position, only requiring GPS data for the start position. In the case of the bike, the position needs to be calculated as pairs of x y or lat long coordinates, and the function would be applied to each separately, making the position formula (xk,yk) = (a+xk-1, b+yk-1). Notice that a and b are being added to the old position rather than multiplied. This is because we can calculate the distance traveled during the timestep between kand k-1using the bike’s velocity data and the heading at time k-1. We use basic trig functions to calculate this distance, with a=speed cos(heading) timestep and b=speed sin(heading) timestep.

Another simple formula used in the Kalman filter states that the observed position at time k is equal to the actual position plus some random noise value. Although intuitive, this formula is an integral part of the filter, as we can combine it with the first formula to get the equation xk = xk-1+gk(zk-xk-1). In this equation, xk represents our estimated state at time k, gk is our gain at time k and zk is our observed state at time k. This equation estimates the state taking into account both the observed state and the previous state, and the gain is some value between 0 and 1 that represents which one you put more emphasis on. We can calculate gain given the average noise of the GPS, for example, if the gain was 1, xk would be equal to zk, in other words, we have no noise. //TODO

Some if the issues with the Kalman filter are that it depends a lot on noise, otherwise it could be inaccurate at times

Sensor Fusion

As previously mentioned, the sole usage of GPS data to determine position is theoretically fine, but impractical. Specifically, the motivating factor for sensor fusion is a path width of approximately 2 meters, while the current GPS has a published accuracy of 2.5m. The purpose of sensor fusion is to fuse multiple streams of information about the bike state together, as a way of obtaining more accurate position estimation and improving the localization algorithm. The bicycle collects data about its lean angle, steer angle, velocity, and current x- and y- position estimates, along with the position updates from the GPS.

In previous bike tests, we realized that the gyroscope and the accelerometer would still record a change, even if the bicycle was still. Most of the localization algorithm relies more on the signals and data received from the IMU to determine its relative location. Especially in straight travel, we can use the rear wheel to increment the bicycle's internal x- and y- coordinates for travel.

Our current solution for sensor fusion is to use a Kalman-like model. The information received from the GPS coordinates, IMU signals, and Hall sensors are fused to augment the accuracy of our location estimates. This model for sensor fusion only relies on the previous state and the current observations to estimate where the current location is. Throughout the semesters, the sensor fusion algorithm has been modified as more navigation tests fail.

Bike Code