# GPS Course vs IMU Course

Im currently working with Kalman Filter for position and velocity, one of the important parameters that im using is the heading that the sensor fusion of the imu gives me, but i have seen that the GPS also provides me one heading called course over the ground, so i think that i will put the heading information as a state variable as well and compare both heading to produce a better estimate, but i want to know how the GPS calculate this information and have not found some valuable information, is this angle with reference to magnetic north? Can i compare these two headings? or they are distinct information. The figure below in orange is the course that i get with gps and in blue is the heading with sensor fusion that IMU provides me, i collected this data with a displacement around my building and recorded it into a sd card. With these data, it seems a good idea to fuse them to get a better estimate of the actual heading. Now im working with a linear kalman filter,and keep north, east coordinate and north, east velocity. The IMU BNO085 makes the sensor fusion for me, with this i use the heading to get the north and east velocity, using the velocity that is coming from the GPS rmc sentence. And with the R-P-Y angles i rotate the acceleration from body frame to NED frame. With the Lat lon that is coming from the GPS i get the ned coordinates. Im using the equations below to use as the state transition matrix, where $$N_k$$ is the north coordinate, $$E_k$$ is the east coordinate, $$Vn_k$$ is the north velocity abd $$Ve_k$$ is the east velocity:

$$N_k = N_{k-1} + Vn_k * dt +\frac{A_e * dt^2}{2}$$

$$Vn_k = Vn_{k-1} + A_n * dt$$

$$E_k = E_{k-1} + Ve_k * dt +\frac{A_e * dt^2}{2}$$

$$Ve_k = Ve_{k-1} + A_e * dt$$

Since the velocity that is coming from the GPS isn't in north and east coordinate i use the heading to get this information as below:

$$V_n = V_{GPS} * cos(heading)$$

$$V_e = V_{GPS} * sin(heading)$$

This velocity goes to measurement vector and its used at update step of kalman filter together with GPS LAT-LON converted to ned coordinate.

I have GPS and IMU as the sensors, now im trying to increase the accuracy of the results, so im learning about unscented kalman filter and trying to increase the number of state variables. Any suggestions are welcome. Below is the last result i got walking with the device. In red are the gps data and in blue the filter data. • It would be nice if you elaborated a little more on your scenario, What are the attributes of the filter state? From your description I assume it's $(x, y, \theta, v)$, but it would be good to have confirmation. What are all the sensors being used, and what measurements are currently taken from them? Jan 29, 2021 at 19:24

So this probably won't work as course over ground and heading are often 2 different things. Heading is the direction your vehicle is facing, while course over ground is the direction your vehicle is traveling.

Imagine a boat facing north, and it is in a drift current flowing east to west. Your heading is north, but your course over ground is west, as the current is moving the boat westward.

As for how it is calculated it is simply the difference between a start and end position. So the GPS simply continuously records a start and end position over a time interval(e.g 5 seconds). So simply the vector $$v_{cog}=v_{end}-v_{start}=[x_{end}-x_{start},y_{end}-y_{start}]$$. If it reports an angle rather than a vector then they probably just use arctan2 to convert it.

• Ok, but take a look at the GPS course and the heading of the IMU that I get when I make a trip, its seems reasonable equal, thats why i have thought that are a good idea to use both Jan 29, 2021 at 12:57
• I agree. In many cases, they will actually coincide. Because the vehicle generally moves in the same direction as the heading. However, it is not something I would rely on. A Kalman filter does not work nicely when its measurement updates are incorrect. If you do end up using it then I would look into things like outlier detection or covariance adaption to catch the cases where it is wrong. Jan 29, 2021 at 15:26
• There is also the aspect of using the same measurement updates twice. Technically you are never supposed to use a measurement, or any derived measurements multiple times. (It breaks some independence assumptions or something I can't exactly remember why). Since COG is computed from GPS positions it is a derived measurement. Now people do ignore this aspect, and their systems end up working fine. So it is not an absolute must. But it can cause subtle issues that then become super hard to diagnose. Jan 29, 2021 at 15:34
• The issue with derived measurements is that Kalman filters assume measurements from different sources are independent from one another. That won't be the case if one measurement is (partially) computed from another — e.g. if the formula for computing GPS heading angle used IMU inputs, that would make it a derived measurement. It doesn't mean you can't make any sort of calculation from raw sensor inputs when generating a measurement. Jan 29, 2021 at 16:30
• @xperroni. Agreed you can calculate a new measurement from the raw measurements. But in this case, if you utilize the GPS position updates, and then additionally utilize a COG update then you are using a primary and a derived measurement. Jan 29, 2021 at 19:05

If GPS course heading angle is computed as edwinem described — that is, as the slope of a line crossing the sensor's current and previous coordinates in $$(x, y)$$ notation — and the robot's always headed towards the direction of movement, then IMU heading and GPS heading readings are relative to the same reference frame, and they can be directly fed to the Kalman filter in the update step.

Even if course heading doesn't exactly agree with the direction the robot is pointed to, so long it's never completely off, that can still be accounted for in the variance attributed to the measurement.