SimpleFOClibrary  2.1
Simple Field Oriented Control BLDC motor control library

Introduction

Proper low-cost and low-power FOC supporting boards are very hard to find these days and even may not exist.
Even harder to find is a stable and simple FOC algorithm code capable of running on Arduino devices. Therefore this is an attempt to:

  • Demystify FOC algorithm and make a robust but simple Arduino library: Arduino SimpleFOC library
  • Develop a modular BLDC driver board: Arduino SimpleFOC shield.

Features

  • Arduino compatible: Arduino library code
  • Easy to setup and configure:
    • Easy hardware configuration
    • Easy tuning the control loops
  • Modular:
    • Supports as many sensors , BLDC motors and driver boards as possible
    • Supports as many application requirements as possible
  • Plug & play: Arduino SimpleFOC shield

Supported Hardware

  • Motors
    • BLDC motors
    • Stepper motors

Drivers

  • BLDC drivers
  • Gimbal drivers
  • Stepper drivers

Position sensors

  • Encoders
  • Magnetic sensors
  • Hall sensors
  • Open-loop control

Microcontrollers

  • Arduino
  • STM32
  • ESP32
  • Teensy

Example code

#include <SimpleFOC.h>
// BLDCMotor( pole_pairs )
BLDCMotor motor = BLDCMotor(11);
// BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) )
BLDCDriver3PWM motor = BLDCDriver3PWM(9, 10, 11, 8);
// Encoder(pin_A, pin_B, CPR)
Encoder encoder = Encoder(2, 3, 2048);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
void setup() {
// initialize encoder hardware
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// power supply voltage [V]
driver.voltage_power_supply = 12;
// initialise driver hardware
driver.init();
// link driver
motor.linkDriver(&driver);
// set control loop type to be used
motor.controller = MotionControlType::velocity;
// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
}
void loop() {
// FOC algorithm function
motor.loopFOC();
// velocity control loop function
// setting the target velocity or 2rad/s
motor.move(2);
}

License

MIT license, all text here must be included in any redistribution.

BLDCDriver3PWM::init
int init() override
Definition: BLDCDriver3PWM.cpp:43
Encoder::handleB
void handleB()
Definition: Encoder.cpp:63
Encoder::init
void init()
Definition: Encoder.cpp:160
Encoder::enableInterrupts
void enableInterrupts(void(*doA)()=nullptr, void(*doB)()=nullptr, void(*doIndex)()=nullptr)
Definition: Encoder.cpp:190
velocity
@ velocity
Velocity motion control.
Definition: FOCMotor.h:29
BLDCDriver::voltage_power_supply
float voltage_power_supply
power supply voltage
Definition: BLDCDriver.h:17
Encoder
Definition: Encoder.h:18
BLDCMotor
Definition: BLDCMotor.h:16
Encoder::handleA
void handleA()
Definition: Encoder.cpp:42
SimpleFOC.h
BLDCDriver3PWM
Definition: BLDCDriver3PWM.h:14