-
Notifications
You must be signed in to change notification settings - Fork 595
B g431 b esc1 current sense rebase 2 #73
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
B g431 b esc1 current sense rebase 2 #73
Conversation
Hey @sDessens ! |
Any update on this? |
We are very slow lately :/ |
Awesome, thank you!
I can simply work off the fork in the meantime.
… On 4 Sep 2021, at 1:52 am, Antun Skuric ***@***.***> wrote:
We are very slow lately :/
We will definitely integrate this to the library soon, but I cannot promise you when, I'd say end of September.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
The current implementation uses oversampling with It would be great if the community could test whether performance on their specific motor and use case is better with or without oversampling. To disable oversampling, locate: |
@sDessens, I'm currently running into an interesting issue at high speeds, which seems to be affected by the ADC oversampling.
FOC torque control works great at low speeds. At high speed (above ~105rad/s), something related to the current measurement seems to fail, as the output voltage goes straight to the set maximum, and the motor runs very rough. Any idea what could be causing this? |
I was able to obtain speeds up to 600rad/s with a magnetic encoder and speeds up to 1000rad/s with an optical encoder (7 pole pair motor, so 7000 erad/s). Those speeds were only possible after heavy software optimizations, my software loop runs at 12k FOC iterations per second, about 10 FOC iterations per electrical rotation. Could you measure your execution speed and calculate, roughly, how much FOC iterations your setup does per electrical rotation at speed? With my setup, motor performance seems to decrease significantly once I go any slower than 20 FOC iterations per electrical rotation, but I am unsure whether this is a software limitation, motor problem or a sensor issue. Oversampling increases the measurement latency, at high speeds this may cause the FOC algorithm to estimate the current at the wrong electrical angle. I tried modifying the software to calculate the foccurrent with a lagged electrical angle, but found no improvements (possibly related to a sensor issue). Increasing the pwm frequency may also help. Also try lowering the sensor resolution. All the interrupts from the sensor can slow down FOC calculations. |
Thanks for the reply! I've just measured the number of calls to loopFOC(); it sits at around 6500 at idle, and decreases (!) to under 2500 as the shaft speed increases. The trouble RPM of 80 gives roughly 2500-3500 Hz, which is less than 3 iterations per electrical rotation. No wonder I'm having problems here. Assuming the execution time of loopFOC() is unaffected by shaft speed (this seems like a reasonable assumption), there's a LOT of CPU cycles getting eaten up by encoder interrupts. Unfortunately, I can't really decrease the sensor resolution, as it's a code disc with 2048 physical slits. I wonder if it's possible to use the STM32 timer hardware to read the AB encoder... |
That matches my experience with encoders. I have mine set to a low CPR (96) to avoid these issues, although this leads to poor performance at low speeds. You could try to optimize the sensor class, it does more work in the interrupt than strictly necessary. I wasn't able to figure out how to use hardware timers, magnetic sensors looked like the superior solution. This board also supports backemf detection, but nobody has tried to implement this yet. |
STM32 timers have an "encoder mode". I've never used it, but wondered how hard it would be to interface with SimpleFOC. I haven't had much time lately, and have too many other open topics to take it on at the moment though. It's described quite well here: Note there are also magnetic encoders (like the AS5047 or some MagAlpha models) that have both digital SPI and encoder ABI type interfaces. I've been wondering whether using the quadrature mode of the magnetic encoders would lead to lower latencies. In any case, I'm following this discussion with great interest, and look forward to learning what your investigation turns up, if you care to share it. |
for this board, use InlineCurrentSense with: shunt_resistor = 0.003 gain = -64.0/7.0
34684fd
to
c1ce9d7
Compare
I disabled oversampling and rebased my changes on the latest dev branch. You may need the fix described in #99 if the board fails to initialize correctly. |
@sDessens, thanks for linking that workaround, I was banging my head against the wall for a while before I saw it! After increasing the call rate of loopFOC(), torque control performance seems very good with my setup. @runger1101001, thanks for the pointer. I've implemented hardware encoder handling with an STM32 timer at #114; it's not yet portable to other devices, but is working great on my B-G431B-ESC1. |
Hey guys, |
An implementation of current sensing with DMA for the B-G431B-ESC1, with help of scouttman.
#if defined(STM32G4xx)
include guards are used to ensure the lib still compiles on other STM32 boards (I only tested the bluepill).The example is copied from bluepill, only a few lines of code were added, the example is mainly there is serve as documentation for the shunt resistor and gain values for this specific board. I feel this is a bit wasteful,
Here is a simple test function that cycles though a full rotation in pi/12 increments and prints the set voltage and read current: This can be used to verify the readings are sensible.
Sample output:
My motor has about 2.8 ohms phase resistance.