Seeed-Studio / Seeed_Arduino_AS5600

The library comes with AS5600. Through this library, we can realize read the angles 、get magnetic from a magnet underneath the sensor.

Repository from Github https://github.comSeeed-Studio/Seeed_Arduino_AS5600Repository from Github https://github.comSeeed-Studio/Seeed_Arduino_AS5600

Wrong angle returned / conversation factor wrong

Neumi opened this issue · comments

commented

A wrong angle is returned in the examples:
examples/fullFunction/fullFunction.ino
examples/readAngle/readAngle.ino

The conversion factor is unprecise and should be 0.087890625 instead of 0.087 / 0.0878. This becomes a problem when precise angle measurements are important.

I wonder if it useful to write this as (angle * 360) / 4096 instead of a fixed numeric constant? That way a reader can see how it is calculated, as well as always using the best floating point precision available on that particular CPU?

I've added this as a standard function in my version of the library:

/*******************************************************
  Method: getDegrees
  In:  none
  Out: value of raw angle register 0..359 degrees
  Description: gets raw value of magnet position, then
  converts to degrees.
  start, end/max angle settings do not apply.
*******************************************************/
float AMS_5600::getDegrees()
{
  return (getRawAngle() * 360.0) / 4096.0;
}

I agree with sheffieldnick. The calculation method does make it more obvious how the conversion is made and provides the maximum precision available.