Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NazaDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ uint8_t NazaDecoder::decode(int16_t input) {
if (y < magYMin) {
magYMin = y;
}
heading = computeVectorAngle(y - ((magYMax + magYMin) / 2), x - ((magXMax + magXMin) / 2));
heading = -atan2(y - ((magYMax + magYMin) / 2), x - ((magXMax + magXMin) / 2)) * 180.0 / M_PI;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the contribution.

I believe this code is covered here: https://github.com/dalmirdasilva/ArduinoMagnetometer/blob/master/Magnetometer/Magnetometer.cpp

Is there anything different on they way you are calculating from the dependency above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalmirdasilva I am not an expert here, but I guess issue is in passing the value. You are passing computeVectorAngle(y, x) and in below function its reversed. [computeVectorAngle(x, y)] x & y are getting interchanged and GPS location is showing 360 on west instead of north.

double Magnetometer::computeVectorAngle(int16_t x, int16_t y) {
double degrees = radiansToDegrees(-atan2(y, x));
if (degrees < 0) {
degrees += 360.0;
}
if (degrees > 360.0) {
degrees -= 360.0;
}
return degrees;
}

if(heading < 0) heading += 360.0;
} else if (messageId == NAZA_MESSAGE_MODULE_VERSION_TYPE) {
firmwareVersion.version = pack4(NAZA_MESSAGE_POS_FW, 0x00);
hardwareVersion.version = pack4(NAZA_MESSAGE_POS_HW, 0x00);
Expand Down