ZoetropeLabs / AS5048A-Arduino

A simple SPI library to interface with Austria Microsystem's AS5048A angle sensor
MIT License
39 stars 28 forks source link

setZeroPosition #3

Closed mjones7947 closed 7 years ago

mjones7947 commented 8 years ago

I am trying to use the setZeroPosition function. I want to reset the position at startup to 0 before start up. The code I am trying to use is:

word set = angleSensor.getRotation(); angleSensor.setZeroPosition(set);

Not sure if thats right, it doesn't work. Looking at the Data sheet it says:

  1. Write 0 into OTP zero position register to clear
  2. Read angle information
  3. Write previous read angle position into OTP zero position register

Can't see where that is happening.. Any help and your my hero. Thanks Matt

benhowes commented 8 years ago

Hi Matt,

So currently, this library doesn't use the angle sensors built in zero position - largely because it allows us to be more flexible.

So the getRotation function returns a relative angle to 0 (signed int, +/-180 degrees) which is useful if you're making a PID system (as I was when I made this).

If that's not what you're after, you need to set the zero position in the device and get the raw angle from the device. I suggest:

  1. Have a look at the modification made here: https://github.com/dutchmillbt/AS5048A-Arduino/commit/73a2082fcf465628b610ac0cef0bc0c6db6fccca. This modification to set zero writes the zero position to the sensor
  2. Use the getRawRotation() method instead - this will return exactly what the sensor sends over

Let me know how you get on!

Ben

mjones7947 commented 8 years ago

MY HERO!! DutchMillbt too! Thanks. Looks like I'll have to mess with the getRotation as well I see now your swinging between -180 and 180. I'm just shooting to get 0 - 359. I'll keep ya up to date. Thanks Again Matt

benhowes commented 8 years ago

You can use getRawRotation to get the 0-360 (in 0x000-0x3FF form) without modification

mjones7947 commented 8 years ago

Ya thats what I started with but then to set zero you have to burn in zero or build to factory zero. I just want to soft set zero to align to the machine as the machine may change position slightly over iterations of the build. You've got a real good starting point here its why I chose the sensor.

Thanks Matt

mjones7947 commented 8 years ago

Nothing personal just buisness... So further study I finally got a clear picture of the whole thing. Setting the ZeroPosition bit on the sensor is kinda worthless even with DutchMillbt's option. It doesn't appear the sensor will respond to that in its angle setup, It really has to be burned in to be anything other than something to do. Buts thats all OK since you already have a method (I don't know what to call it in C++) wrote. Seems it could be used to call get raw rotation ( AS5048A angle) Set a variable then in GetRotation just subtract that initial value. So the one thing I have question about is if I change this thing significantly should I submit a branch. I have never used github, programming is just not my forte but I have to do it this time. Any suggestion on how this stuff works and the protocol for it would be appreciated.

Thanks Matt

benhowes commented 7 years ago

@mjones7947 I completely forgot to reply to this, sorry! I know it was over a year ago, but I hope you got things worked out!