simplefoc / Arduino-FOC-drivers

Drivers and support code for SimpleFOC
https://docs.simplefoc.com/drivers_library
MIT License
146 stars 63 forks source link

Improvements to LinearHall #39

Closed dekutree64 closed 7 months ago

dekutree64 commented 7 months ago

Changes compared to the original pull request https://github.com/simplefoc/Arduino-FOC-drivers/pull/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 example
runger1101001 commented 7 months ago

Thank you very much for this PR!

Is it ready for merging? I would be happy to merge it.

There is a compile problem with the example for ESP32s - they don't define pin A1 it seems - many ESP32 boards don't use the Arduino pin conventions.

I would change the example to use numeric pin numbers, or else we can also just remove the ESP32 compile from the test cases, whichever you think is better...

dekutree64 commented 7 months ago

Yes, it's good.

Any solution for the compile error would be fine with me, including scrapping the example entirely. I thought the A0, A1, etc. pin names were part of the Arduino library spec, but if not then it would be better to use numeric pins. It may be a while before I get around to doing it (I have to boot up Windows 10 to use github desktop), so feel free to do it yourself if you'd like to get it merged sooner.

runger1101001 commented 7 months ago

Perfect, lets merge it. Since the example compiles on all the other test architectures, I'll just exclude ESP32.