-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add linear hall position sensor driver #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hey @nanoparticle, how do you feel about this? There was a SimpleFOC release today, including the changes to the init() code that you wanted... how about this code? is it ready to merge to the drivers? |
I haven't had time to do any real testing on this code beyond seeing if it is a feasible method of sensing. How much testing should it go through before being merged? |
Hey @nanoparticle do we want to merge this? It's still in draft status... For the drivers repository, the bar is not set very high - you don't have to test much. If it runs in some of your own setups it is enough... each folder in the drivers repository has its own README, so we can add a warning note for users to let them know it isn't tested much... |
Also, did you see this one: simplefoc/Arduino-FOC#197 It's a similar implementation, I think... |
This gets my stamp of approval! But I would rather it be placed in the main SimpleFOC sensors folder rather than drivers. I recommend adding a way to auto-calibrate the center values without having to run a separate program and copy them over by hand. I did it by moving the centerA and centerB arguments to init instead of the constructor, and adding a second version of init which takes a FOCMotor*. But this requires calling motor.init before sensor.init so it can use setPhaseVoltage. It doesn't cause any problems, but if Antun prefers the sensor init to always go before motor init, then we could add a hook for custom sensor calibration routines. It would be useful for digital halls too (the zero offset found by alignSensor works for trapezoid120, but sinePWM and SmoothingSensor need manual tuning). I've adapted the center search code from XieMaster's version that runger linked above, with a modification to the angle calculation:
|
Upon further investigation, it looks like ADC configuration is a major problem for this sensor approach. As it is, I'm getting about 250 microseconds per analogRead on STM32G031, which is too slow for real world use. Current sense apparently requires an elaborate HAL configuration sequence for every supported platform to get good ADC performance, and separate ones for each STM32 series. That would be a maintenance nightmare to add that many files just for this one sensor. What to do? |
Hey @dekutree64 , you're absolutely right, and we're keenly aware of this problem. The ultimate plan looks like this:
|
Yes, ADC sampling is too slow, so this linear Hall angle feedback method is more suitable for use in lower-speed projects such as pan/tilts. |
Changes compared to the original pull request in the drivers repository simplefoc/Arduino-FOC-drivers#12 1. Added a version of init which turns the motor one revolution to find the center values of the sensors. 2. Moved the calls to analogRead into a weakly bound function ReadLinearHalls so it can be overridden with custom ADC code on platforms with poor analogRead performance. 3. Commented out the pinMode calls in init, which makes it possible to pass in ADC channel numbers for custom ReadLinearHalls to use without having to remap them every update. 4. Changed to use the much faster _atan2 function that was added to foc_utils recently. 5. Added examples.
Changes compared to the original pull request simplefoc#12 1. Added a version of init which turns the motor one revolution to find the center values of the sensors. 2. Moved the calls to analogRead into a weakly bound function ReadLinearHalls so it can be overridden with custom ADC code on platforms with poor analogRead performance. 3. Commented out the pinMode calls in init, which makes it possible to pass in ADC channel numbers for custom ReadLinearHalls to use without having to remap them every update. 4. Changed to use the much faster _atan2 function that was added to foc_utils recently.
I have just merged deku's implementation to the drivers repository dev branch, it will be part of the next release... do you all agree we can close this PR (which is still in draft status) in favor of the merged implementation? |
Thanks so much to everyone for pulling this over the finish line 👍 |
Changes compared to the original pull request simplefoc#12 1. Added a version of init which turns the motor one revolution to find the center values of the sensors. 2. Moved the calls to analogRead into a weakly bound function ReadLinearHalls so it can be overridden with custom ADC code on platforms with poor analogRead performance. 3. Commented out the pinMode calls in init, which makes it possible to pass in ADC channel numbers for custom ReadLinearHalls to use without having to remap them every update. 4. Changed to use the much faster _atan2 function that was added to foc_utils recently.
Not entirely sure where the driver files should go, or how exactly the includes are structured, but the basic functionality is here and superficially tested.