I know I'm about a month late to this thread, but I'm just wondering why all of this complicated FOC stuff is even needed. Here's how I see a stepper-servo:
Given a 200 step per revolution stepper motor and an encoder which has a multiple of 200 counts per revolution. (Let's use an 800 pulse per revolution encoder.) The multiple between the encoder resolution and the stepper resolution becomes the "Motor direction resolution" - 4 in this case.
So, as for the drive - Let's split it into two parts:
1) The PID controller - A simple controller which takes a step / direction input, an encoder input and outputs a direction and power level that it wants the motor to respond to. Nothing new, non-standard or complicated here so I don't go into the implementation here.
2) The motor driver - This is the new part which takes a direction / power level, an encoder input and outputs the current levels for each winding.
I see #2 as doing the following:
Let's consider 4 full-steps of the stepper motor in terms of degrees 0 - 360 degrees, as we normally would for a stepper driver. We have an encoder which has 4x the "Motor direction resolution" steps over this range.
We know that full torque is generated when the winding is driven 90 degrees from the stepper motor's current position, so depending on the direction / power level requested, we just drive the windings between -90 and 90 degrees of the current position using a sine / cosine lookup.
Am I missing something here because what seems to be needed in my head is a lot simpler than what is being mentioned in this thread and I very much doubt Mariss would go to all this trouble if it wasn't needed ?