# Field oriented control of brushless motors

If I was controlling a normal brushed motor as a servo, I would measure the motor's position, and adjust the PWM signal to control the voltage. This way I could achieve a precise velocity/position profile if my control was good enough.

pwm_duty = CalcPID(motor_position - target_position);


When doing Field Oriented Control (FOC) of a brushless motor, there are two parameters I can control: The voltage angle, and the voltage magnitude. There are three things I can measure, the current angle and magnitude, and the rotor position.

I want to achieve a precise velocity/position profile including good control down to zero speed and reverse.

Question: how can I calculate the correct voltage field angle (or phase lead) and magnitude? Do I need two PID algorithms?

phase_lead  = CalcPID_1( ... );
voltage_mag = CalcPID_2( ... );


Assume I can take any reasonable measurements of the motor state, including rotor position and winding current.