if(ground_speed >= 50){
//Only updates data if we are really moving...
intUnion.byte[1] = gps_buffer[j++];
intUnion.byte[0] = gps_buffer[j++];
ground_course = intUnion.word; // degrees * 100
ground_course = abs(ground_course);//The GPS has a BUG sometimes give you the correct value but negative, weird!!
}else{
Since the integer used in the intUnion is a 16 bit signed integer, only numbers up to 32768 is supported, this fact yields negative values when the value is above, from the bit pattern interpretation.
The solution is to use the longUnion instead of the intUnion. This solves the buggy ground course.
if(ground_speed >= 50){
//Only updates data if we are really moving...
longUnion.byte[1] = gps_buffer[j++];
longUnion.byte[0] = gps_buffer[j++];
ground_course = longUnion.dword; // degrees * 100
//ground_course = abs(ground_course); //The GPS has a BUG sometimes give you the correct value but negative, weird!!
}else{
I hope that this helps somebody.
Best regards
Niklas
Comments
Looking at Niklas code that the top shouldn't these be longUnion?? not intUnion??
Also just below this code there is also :-
j = 45;
intUnion.byte[1] = gps_buffer[j++];
intUnion.byte[0] = gps_buffer[j++];
should these be longUnion too??
Tony
http://code.google.com/p/ardupilot/issues/list
The correct code should be :