Skip to main content
Field Oriented Control (FOC) is the default and most capable motor control algorithm in VESC firmware. It controls the d-axis and q-axis currents independently in a rotating reference frame, enabling smooth torque, high efficiency, and precise speed and position control.

Sensor modes

FOC sensor mode is configured via mc_foc_sensor_mode in datatypes.h. The default is FOC_SENSOR_MODE_SENSORLESS.
The flux observer estimates rotor position from stator voltages and currents. No position sensor is required. The motor coasts through open-loop at low speeds until the observer locks in, controlled by MCCONF_FOC_OPENLOOP_RPM (default: 1500 ERPM) and the open-loop hysteresis/timing parameters.
Uses an incremental (ABI) encoder for rotor position. Requires encoder offset calibration. Ratio and inversion are set by MCCONF_FOC_ENCODER_RATIO (default: 7.0) and MCCONF_FOC_ENCODER_INVERTED (default: false).
Encoder AB mode — uses only the A and B signals (no index pulse). Useful when the index channel is unavailable.
Hall effect sensors provide 60-degree resolution commutation. Sensor angles are stored in the FOC hall table (MCCONF_FOC_HALL_TAB_0 through MCCONF_FOC_HALL_TAB_7). Hall interpolation is disabled below MCCONF_FOC_HALL_INTERP_ERPM (default: 500 ERPM) to avoid noise at low speeds.
High-Frequency Injection. A high-frequency voltage is superimposed on the motor to detect rotor position from inductance anisotropy. Intended for salient-pole motors (e.g., IPM motors). See the HFI section below.
Sensorless mode that uses HFI only during startup and low-speed operation to resolve initial rotor position, then hands off to the sensorless observer. Avoids open-loop coasting on startup.
Revised HFI algorithm (V2) with a correction gain (MCCONF_FOC_HFI_GAIN, default: 0.3) and max error truncation (MCCONF_FOC_HFI_MAX_ERR, default: 0.30).
HFI V3 — an incremental variation of the V2 algorithm.
HFI V4 — further refined HFI variant.
HFI V5 — latest HFI variant with additional hysteresis control via MCCONF_FOC_HFI_HYST (default: 0.0).

HFI (High-Frequency Injection)

HFI detects rotor position at standstill and low speeds by injecting a high-frequency test voltage and measuring the resulting current response. It requires a motor with significant inductance anisotropy (Ld ≠ Lq).

HFI key parameters

HFI ambiguity resolution mode

Because inductance anisotropy is 180° ambiguous, HFI requires a separate step to resolve the correct pole. The ambiguity mode is set by mc_foc_hfi_amb_mode:
Ambiguity current and threshold are set by MCCONF_FOC_HFI_AMB_CURRENT (default: 60.0 A) and MCCONF_FOC_HFI_AMB_TRES (default: 15).

Position observer

For sensorless operation, the flux observer estimates rotor position. The observer type is selected by mc_foc_observer_type:
The default observer is FOC_OBSERVER_MXLEMMING_LAMBDA_COMP. Observer gain is set by MCCONF_FOC_OBSERVER_GAIN (default: 9×10⁷; suggested starting value: 600 / L). At low duty cycles the gain is scaled down by MCCONF_FOC_OBSERVER_GAIN_SLOW (default: 0.05).

Hybrid sensor / sensorless

When using Hall or encoder feedback, you can configure the firmware to blend in the observer at higher speeds: Between MCCONF_FOC_SL_ERPM_START and MCCONF_FOC_SL_ERPM the two sources are blended linearly.

Open-loop startup (sensorless)

In sensorless mode the motor runs open-loop at low speeds before the observer has locked in. Key parameters:

Current controller

The FOC current controller (inner PI loop) operates on the d and q axes:

Current controller decoupling

The default is FOC_CC_DECOUPLING_DISABLED. Cross-coupling and BEMF feedforward can improve dynamic response at high speeds.

Motor parameters

The observer and current controller use these motor-specific parameters:
Use VESC Tool’s motor measurement wizard to automatically detect resistance, inductance, and flux linkage for your specific motor.

PLL speed estimator

A phase-locked loop (PLL) tracks the rotor angle from the observer output:

Field weakening

Field weakening extends operating speed above the rated RPM by injecting negative d-axis current:
Field weakening increases motor and controller temperatures. Ensure adequate thermal headroom before enabling it.

MTPA (Maximum Torque Per Amp)

MTPA exploits d/q inductance asymmetry to maximize torque output at a given current. It is configured by MCCONF_FOC_MTPA_MODE and requires MCCONF_FOC_MOTOR_LD_LQ_DIFF to be non-zero.

FOC functions (mcpwm_foc)

The mcpwm_foc module implements the FOC algorithm. You typically call it through mc_interface, but the direct API is available:

Sample modes

FOC sampling behavior is configurable:
Defaults are FOC_CONTROL_SAMPLE_MODE_V0 and FOC_CURRENT_SAMPLE_MODE_LONGEST_ZERO.