As5047p magnetic encoder wrong velocity

Hi there,

So standing still the as5047p encoder sends velocities via SPI which are wrong. Has anyone ever had similar problems / encoders which don’t have this problem ?

The angle is correct.

Thanks for the response,

It would be good to see your code to see what you are doing.
I suspect you are calling getVelocity() on sensor.
It is worth looking at the implementation for that function:

The velocity isn’t coming from the sensor (over SPI) but is calculated in software. It works it out as (newAngle - oldAngle) / time since last angle measured.

Some observations.

  1. You are sampling at a very high frequency.
  2. You are showing your angle to 1 decimal place

If you were to show your angle to 4dp you’d see the angle is fluctuating between (for example) 4.2125 and 4.2159. i.e newAngle - oldAngle is constantly changing a small amount and this amount is ‘noise’.

If you are sampling at 1khz your time delays is 0.001.

The function is doing something like

I’d print angle more accurately and ignore or compensate for noise (e.g low pass filter). If you sample at 100hz, you’d see less velocity noise. I think you get a low pass filter for free if you use motor.shaftVelocity()

1 Like

Hey, you’re right @Owen_Williams, but depending on how all this is being used, I would not call motor.shaftVelocity()
This is because the LPF is not stateless, it remembers the last time it was called. motor.move() already calls motor.shaftVelocity() so calling it again from your own code will result in a very short time interval.
Better to use the field motor.shaft_velocity which contains the last LPF-smoothed velocity value as calculated by motor.move()… you can read that field as often as you like and it won’t affect the calculation.