360 on north direction instead of West#3
360 on north direction instead of West#3vishal-adhikari wants to merge 1 commit intodalmirdasilva:masterfrom
Conversation
| 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@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;
}
No description provided.