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

Function convertScaledAngleToDegrees in fullFunction example returns incorrect angle

Nkawu opened this issue · comments

Describe the bug
In the fullFunction.ino example, function convertScaledAngleToDegrees returns an unexpected angle value when a startPosistion has been set (and EndPosition == MaxAngle == 0)

To Reproduce
Steps to reproduce the behavior:

  1. Rotate magnet to, e.g. 30º
  2. Run '1 - Set start position'
  3. Run '5 - Get start position' and confirm value is correct, e.g. 30º
  4. Confirm '4 - Get max angle range' is 0
  5. Confirm '6 - get end position' is 0
  6. Run '7 - get raw angle' and note value
  7. Run '8 - get scaled angle' and note value

Expected behavior

  1. Set start position as shown above
  2. Rotate the magnet to 90º
  3. Run '7 - get raw angle', value should be 90º
  4. Run '8 - get scaled angle', value should be (90º - 30º = 60º) but is not

Solution
I believe the issue is in lines 133-4 in function convertScaledAngleToDegrees:

else if ((startPos > 0 ) && (endPos == 0))
      multipler = ((360 * 0.0878) - (startPos * 0.0878)) / 4096;

as the value of newAngle passed into the function has already been adjusted relative to the start position, this block should be

        else if ((startPos > 0) && (endPos == 0))
            multiplier = 0.0878;

which returns the expected value

Closing this. I may have misunderstood the functions to set the angular range. I was trying to use the ZPOS as an offset to correct a device or magnet misalignment.