This repository implements Field Oriented Control (FOC) for BLDC motors in Matlab/Simulink. The controller was deployed and tested on a real-time hoverboard embedded platform:
The FOC algorithm architecture is illustrated in the figure below:

In this implementation 3 control types are available:
- Commutation
- SIN (Sinusoidal)
- FOC (Field Oriented Control) with the following 3 control modes:
- **VOLTAGE MODE**: in this mode the controller applies a constant Voltage to the motors.
- **SPEED MODE**: in this mode a closed-loop controller realizes the input speed target by rejecting any of the disturbance (resistive load) applied to the motor.
- **TORQUE MODE**: in this mode the input torque target is realized. This mode enables motor "freewheeling" when the torque target is `0`.

The C code for the controller is capable for auto-code generated using [Matlab/Simulink](https://nl.mathworks.com/solutions/embedded-code-generation.html). The controller is designed for [stock hoverboard motors](https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/master/docs/pictures/motor_inside.jpg) with the motor windings construction as shown [here](https://github.com/EmanuelFeru/hoverboard-firmware-hack-FOC/blob/master/docs/pictures/motor_winding.png). However, with slight modifications, the controller can be adapted to other available BLDC motors.
Every contribution to this repository is highly appreciated! Feel free to create pull requests to improve this repository as ultimately you are going to help everyone.
If you want to donate to keep this repository updated, please use the link below: