# 4.4. Field-Oriented Control (FOC)

FOC consists of a velocity controller, a current controller, and commutation and estmation subcomponents. A high-level block diagram of the FOC components is shown in Figure 4.3.

Figure 4.3 Block diagram of MCAF Field Oriented Control

This diagram shows a number of features that are described in the test harness.

## 4.4.1. Velocity Control

The velocity control loop is a straightforward, scalar PI controller, with managed saturation features to prevent integrator windup when either the velocity or current controller saturates.

It is preceded by a rate limiter, to provide more gentle trajectory shaping and reduce transient overshoot.

Saturation and antiwindup features are present and covered in a separate document.

## 4.4.2. Current Control

The current control loop is a vector control loop that operates in the dq reference frame, with reference transforms to convert to/from the ABC stationary reference frame in which currents are measured and duty cycles are commanded. The vector control loop itself is a straightforward pair of PI controllers, with managed saturation features to prevent integrator windup when the current controller saturates. (Saturation and antiwindup features are covered in more detail in a separate document.)

Figure 4.3 shows a filter block preceding the current controller. It is intended to slow down incoming commands from the velocity loop, which typically executes at a slower rate. This filter is unimplemented for MCAF v1.0, but is reserved for a future version.

Figure 4.3 also shows DC link voltage compensation prior to the Inverse Park Transform. This is also not implemented for MCAF v1.0, but is reserved for MCAF v2.0.

## 4.4.3. Position and Velocity Estimator

The sensorless estimator used to estimate position and velocity is essentially the one used in AN1292.

## 4.4.4. Implementation Notes

### 4.4.4.1. Modules

#### 4.4.4.1.1. Core FOC

Module | Files | Description | Comments
--- | --- | --- | ---
`parameters/foc_params` | `parameters/foc_params.h` | FOC control parameters |
`parameters/init_params` | `parameters/init_params.c` `parameters/init_params.h` | Initialization of FOC control parameters |
`parameters/sat_PI_params` | `parameters/sat_PI_params.h` | PI Saturation parameters |
`foc` | `foc.c` `foc.h` `foc_types.h` | Top-level FOC | These functions are called from the state machine modules, as described in the implementation notes.
`sat_PI` | `sat_PI.c` `sat_PI.h` `sat_PI_types.h` | PI loop saturation management |

The `field_weak` module, covering flux weakening and not included in the above table, is presently disabled in MCAF v1.0, and is being redesigned for a future version. In MCAF v1.0, the velocity controller sets the d-axis current command to zero.

#### 4.4.4.1.2. Commutation

Module | Files | Description | Comments
--- | --- | --- | ---
`parameters/pll_params` | `parameters/pll_params.h` | PLL estimator parameters |
`commutation` | `commutation.c` `commutation.h` `commutation_types.h` | Top-level commutation / estimation |
`pll` | `pll.c` `pll.h` | PLL (AN1292 sensorless estimator) |
`qei` | `qei.c` `qei.h` | Quadrature encoder estimator | The quadrature encoder is used to obtain a reference position for testing estimator performance.