FOC d, q, and alignment

I’m adapting the FOC library to a non arduino environment that uses FreeRTOS. Motor is Gimbal GL35 from cubemars, and AS5048SPI sensor, voltage mode.

I have it mostly working, however, I find in experimenting with d and q values that the d value does different things depending on the zero_electric_angle apparently. After some alignments, a positive d value increases rpm, and after others it decreases rpm. What could I be missing here?

In a related question, in BLDCMotor.cpp in the case MotionControlType::velocity: in ::move what are the actual values? shaft_velocity is unclear, and why are pole pairs part of this equation?

        if(!_isset(phase_inductance)) voltage.d = 0;
        else voltage.d = _constrain( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);

Hi @Erik_Friesen , please take a look at the concept of „field weakening“, perhaps it explains the effect you’re seeing…

Ok, but what I don’t understand is why positive and negative values do different things depending on zero_electrical_angle calculation.

Im not sure I’m the best person to explain it, but basically applying some d-axis current gives the field weakening effect.

Because the alignment isn’t very precise for some motors, you already have an incorrect 0-angle, so there is already some D axis current present which is not intentional. By changing the zero angle some more, you further change the amount of D-axis current. The effect depends on the amount and direction of the change in angle, combined with the error in electrical zero.

Thank you, I also came to a similar conclusion. This particular model uses the AS5048A with 7 poles, and I don’t think a single point calibration is enough. So in this case, I measured all 7 poles and averaged their center, then used the lowest one. Once I did this, d axis current really didn’t make any difference. At that point, I added some advance in the angle calcs.