Repository navigation
Add optional dq voltage vector limiter (limit_voltage_vector) - #599
Open
Barre-Beavogui wants to merge 2 commits into
Open
Barre-Beavogui wants to merge 2 commits into
Barre-Beavogui wants to merge 2 commits into
Conversation
…r is set Refs simplefoc#561. Scales Vd and Vq together when the vector magnitude exceeds voltage_limit. Opt-in, disabled by default.
Barre-Beavogui
marked this pull request as ready for review
November 25, 2026 23:49
Collaborator
|
Thanks, nice and minimal. A few suggestions:
I could make a PR for this better _sqrtApprox and _invSqrtApprox after testing it. |
Member
|
@Candas1 we already habe the inverse square root approx in the library. :) Arduino-FOC/src/common/foc_utils.cpp Line 87 in b3d8f39 |
|
Ok excuse me It's been a while 😂 |
Collaborator
|
Omg I am mixing the accounts now sorry
|
Collaborator
|
Sorry I am on my computer now, let me clarify:
To be honest this was suggested by Claude so I would trust the limit/speed/accurary only if I test and compare the results. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds an opt-in
FOCMotor::limit_voltage_vectorflag (defaultfalse, so existing behaviour is unchanged). When enabled,loopFOC()scalesvoltage.dandvoltage.qtogether right beforesetPhaseVoltage()whenever the vector magnitude exceedsvoltage_limit, instead of relying only on the independent d/q limits. The direction of the voltage vector is preserved.sqrtfis used instead of_sqrtbecause the fast approximation could slightly exceed the limit.Example from the issue: with
voltage_limit = 6 V,Vd = Vq = 6 Vrequest about 8.5 V in total; with the flag enabled they are scaled to about 4.24 V each, giving a 6 V vector.Fixes #561
Type of change
How Has This Been Tested?
Host-side test (g++, stubbed
Arduino.h, fake sensor and driver) running the realBLDCMotor::loopFOC()code in voltage torque-control mode withvoltage_limit = 6 V:limit_voltage_vectorloopFOC()falsetruefalse/trueFOCMotor.cpp,BLDCMotor.cpp,StepperMotor.cppandHybridStepperMotor.cppalso compile with the change.Test Configuration/Setup:
Open question (see #561): proportional scaling as implemented here, or a d-axis-priority limiter like MathWorks' DQ Limiter block?