There were two things specifically which confused the hell out of me when trying to learn this stuff: the Space Vector Modulation thing, and for AC induction motors, the magical "flux estimator" black box. For BLDC, luckily, the latter does not exist.
In all BLDC implementations I have done, I just always skipped the space vector modulation thing. None of the microcontrollers I use came with Space Vector Modulator peripheral, but they all come with classic three-phase center-aligned PWM modules (e.g., in STM32, "advanced control timer"; it can even synchronize ADC and look at analog comparator for overcurrent signal, saving MOSFETs when your PI loop is wrongly tuned). The claimed use case for Space Vector Modulator is that you don't have to perform inverse Clarke transform (from 2-phase duty cycles to 3-phase duty cycles) but could drive the modulator "directly" with the 2 phases, but OTOH, inverse Clarke is a few multiplications and additions, two lines of code and maybe 10-15 CPU instructions cycles so I don't see what's the big deal - then you can just use bog standard PWM timers.
I used third harmonic injection once, and just generated the waveform in Matlab by gut feeling. The idea is that it should resemble a "softly clipped sine wave", pretty close to what you get by just multiplying and clipping a sine, but softer - no higher harmonics. What you gain is better utilization of DC link voltage especially in the case you have mismatched DC link voltage and motor nominal rating, i.e., can't go for higher voltage but want a tad more output power. I don't think there are any other advantages, maybe a tiny reduction in switching losses when running at absolute maximum output voltage. I did that only in an experimental EV conversion project where we had designed the motor windings for 300V or so but only had 96V of batteries.
Re sinusoidal vs. triangular current waveform: there is a lot of confusion and probably no authoritative answer, but what is true that when a BLDC motor is driven from hall sensors directly i.e. just applying input voltage to the windings in square wave, emulating how actual brushes work, then naturally the motor current after the motor inductance will be integral of that, triangle wave. Some people miss the important point that this is just a consequence of simplistic low-cost drive, not some kind of ideal design target. To muddy the waters, those BLDC motors that are primarily designed to be driven this stupidly, maybe possibly perhaps have different physical construction which kinda sorta evens out the rotation of the magnetic field even when driven with triangular current, and some further think that the distinctive factor is the "name": BLDC is trapezoidal, AC PMSM is sinusoidal. I don't know - but if such mechanical compensation really exists and is performed perfectly ideally, then it indeed would be ideal to use triangle wave in FOC (thus, use triangle function in Park / Inverse Park calculation). I have always used just sine wave even with cheapest of BLDC motors and with accurately interpolated angle, they run really smooth, much smoother than when driven "BLDC way" with square waves, where +/- 30deg torque ripple is easily observable. If the physical construction tries to compensate for the triangle wave, Chinese do it poorly. For a sine to perform worse than triangular, this mechanical compensation should need to work to at least 50% perfection.
In essence, BLDC motor control is:
* Apply a magnetic field, direction of which is 90 degrees advanced from the measured electrical position
Then for the current (torque) control:
For a motor which turns very very slowly, you could just use three PI loops which measure current of each phase and output a duty cycle for that phase, then make the three current setpoints change sinusoidally and make the motor rotate that way. It works; the only problem is the delay in the feedback loop: optimal 90 degrees starts being less than 90 when speed increases, and worst, the delay isn't exactly constant per speed but depends on motor resistance which depends on temperature, so...
All FOC does is, it makes the generation of sine waves a separate issue from the PI regulators; their setpoints and outputs will be constants over a short time, and sine waves applied before and after the PI loops. (Setpoints change when you desire different torque; outputs change slowly as for example temperature differences changes motor resistance.)
In essence, FOC achieves this by:
* measure current of two phases
* calculate the third by knowing the sum of the three is zero
* convert the 3-phase (120deg separated) current measurement vectors into 2-phase (90deg separated) vectors, i.e. copy the (simple) Clarke formula from Wikipedia.
* rotate this 2D vector by the measured electrical angle of the rotor, so that it's rotated always to same stationary position (simple 2D vector rotation, the formula you see in computer graphics etc., for some weird reason called "Park transform" in this context; again, copy from Wikipedia). THIS is where the sine wave is introduced.
* Use two PI loops, one for each component of the 2D vector
* One of the component you want to usually regulate at zero - this is Id, the part which generates magnetic field into the current (or opposite) direction of the rotor. It tries to keep the rotor standstill, or if negated, fight against the magnets to weaken them.
* Other one, Iq, creates magnetic field 90 degrees (or -90, if negative) from the current rotor position - this is what drives the motor forward/backward at optimum efficiency. Set at +/- desired current (torque).
* Output of the two PI loops is again a stationary 2D vector, you can call it "voltage" or "duty cycle" command.
* Follow the input steps in reverse and inverse order:
* Opposite 2D rotation
* Conversion from 2-phase to 3-phase (inverse clarke)
* Write to PWM control registers of the timer peripheral and enjoy.