Link

Arduino Simple Field Oriented Control (FOC) project

License: MIT arduino-library-badge PlatformIO Registry status

GitHub release (latest by date) GitHub Release Date GitHub commits since tagged version GitHub commit activity (branch)

We live in very exciting times πŸ˜ƒ! BLDC motors are entering the hobby community more and more and many great projects have already emerged leveraging their far superior dynamics and power capabilities. These motors have numerous advantages over regular DC motors but they have one big disadvantage, the complexity of control. Even though it has become relatively easy to design and manufacture PCBs and create our own hardware solutions for driving BLDC motors, the proper low-cost solutions have been challenging to develop. One of the reasons for this is the apparent complexity of writing the driving algorithms, Field Oriented Control (FOC) being one of the most efficient ones. The solutions that can be found online are almost exclusively very specific for certain hardware configurations and microcontroller architectures. Similar to BLDCs, Stepper motors can hugely benefit from FOC control, but the solutions for FOC controlled stepper motors are even more scarce.
Therefore this is an attempt to:

  • 🎯 Demystify FOC algorithm and make a robust but simple Arduino library: Arduino SimpleFOClibrary
    • Support as many motor + sensor + driver + mcu combinations out there
    • Make transitioning from one hardware combination to another as seamless as possible
  • 🎯 Develop modular and easy to use FOC supporting driver boards

NEW RELEASE πŸ“’: SimpleFOClibrary v2.4.0 see release

  • STM32
    • Added support for ADC reads in addition to Lowside current sense #506 - see in docs
    • Added support for multiple motors low-side CS (one per ADC) with ADC current sensing #503
    • BG341 low-side current sense sync was lost in v2.3.5 - fixed #482
  • ESP32
    • Many ESP32 safety optimisations by @uLipe: #490,#491,#492,#493,#495
    • Better ADC-Timer alignement for more stable current sensing See this commit
    • Now compiles for all v3.x arduino-esp32 versions (v2.3.5 was compatible with v3.2.x)
    • adcRead small refactor - no more magic numbers
  • Others
  • Major New features
    • Add current and voltage feed forward terms to motor classes by @Copper280z in #454
    • Velocity Calculation rework by @Copper280z in #45
    • Motion control - docs
      • Added custom motion control mode - see in docs and in examples
      • Added angle_nocascade control mode for position control without velocity cascade - see in docs - #384
      • Now all the closed and open loop modes can be used with any torque control modes (voltage and current)
        • Ex. velocity_openloop with foc_current torque control
    • Torque control - docs
      • Added estimated_current torque control mode for model-based current estimation without current sensing - see in docs
      • Now we can easily switch between voltage and estimated current control
  • Docs updates - see docs
    • Write the code page updated - see docs
    • Better step-by-step setup guides - see docs
    • New motion control documentation - see docs
    • New torque/FOC control documentation - see docs
    • Theory corner updated and extended - see docs
    • Library source updated and extended - see docs
    • Practical guides updated and extended - see docs
      • Motor parameter measurement guide - see docs
      • PID tuning guides - see docs
  • Examples
    • align_current_sense.ino example added to the examples/utils/current_sense_test allowing to verify the alignment between the driver and the current sense phases
  • Changelog

Arduino SimpleFOClibrary - Read more …

License: MIT GitHub release (latest by date) GitHub Release Date

This video is a bit outdated but it demonstrates the SimpleFOClibrary basic usage, electronic connections and shows its capabilities.

Features

  • Easy install:
    • Arduino IDE: Arduino Library Manager integration
    • PlatformIO
  • Open-Source: Full code and documentation available on github
  • Goal:
    • Support as many sensor + motor + driver + current sense combinations as possible
    • Make transitioning from one hardware combination to another as seamless as possible
    • Provide up-to-date and in-depth documentation with API references and examples
  • Easy to setup and configure:
    • Easy hardware configuration
    • Each hardware component is a C++ object (easy to understand)
    • Easy tuning the control loops
    • Advanced control features: velocity and current feed-forward, improved velocity calculation
    • SimpleFOCStudio configuration GUI tool for real-time tuning and monitoring
    • Built-in communication and monitoring via Serial, I2C, or custom protocols
  • Cross-platform:
    • Seamless code transfer from one microcontroller family to another
    • Supports multiple MCU architectures:
      • Arduino: UNO R4, UNO, MEGA, DUE, Leonardo, Nano, Nano33, MKR ….
      • STM32 (Nucleo, Bluepill, B-G431B-ESC1, H7 family, etc.)
      • ESP32 (ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6)
      • Teensy (3.x, 4.x)
      • RP2040/RP2350 (Raspberry Pi Pico)
      • SAMD (Arduino Zero, MKR boards)
      • MBED (Portenta, Nano 33 BLE)
      • Silabs
      • many more …

SimpleFOCBoards - Read more …

One of the goals of the SimpleFOCproject is to develop low-cost easy to use BLDC driver boards compatible with the SimpleFOClibraryand completely open source! Therefore, SimpleFOC team members have developed a set of boards, designed specifically for ease of use, to help you kickstart your FOC journey. In addition to being easy to use, the goal of these boards is serve as a reference design for the community to build upon. And finally, even though some of these boards are available in our shop, our docs provide a lot of documentation and step-by-step guides on how to fabricate the boards yourself.

In addition to the official boards, there are many other boards compatible with SimpleFOClibrary that you can explore, see the docs. Additionally, some other cool hardware designs have been proposed by the community. Check out our community forum for more info.

Here are some of the official boards developed by the SimpleFOC team:

SimpleFOCShield

License: MIT GitHub release (latest by date) GitHub Release Date

Features

  • DRV8313 based - datasheet
    • Power supply: 8-35V
    • Max current: 2A per phase (3Amp peak)
  • Absolute max ratings - Designed for Gimbal motors with the internal resistance >10 Ξ©s.
    • Max current: 3A,
    • Max input voltage: 35V
  • In-line current sensing: Up to 5Amps bidirectional
    • ACS712 hall current sensor
  • Integrated 8V regulator:
    • Enable/disable by soldering pads
  • Stackable: running 2 motors in the same time
  • Encoder/Hall sensors interface: Integrated 3.3kΞ© pullups (configurable)
  • I2C interface: Integrated 4.7kΞ© pullups (configurable)
  • Configurable pinout: Hardware configuration - soldering connections
  • Arduino headers: Arduino UNO, Arduino MEGA, STM32 Nucleo boards…
  • Open Source:
  • Low-cost:
    • JLCPCB production cost ~10-15€
    • Available in the shop: 15-30€

SimpleFOCMini

License: MIT GitHub release (latest by date) GitHub Release Date

Features

  • DRV8313 based - datasheet
    • Power supply: 8-35V
    • Max current: 2A per phase (3Amp peak)
  • Absolute max ratings - Designed for Gimbal motors with the internal resistance >10 Ξ©s.
    • Max current: 3A,
    • Max input voltage: 35V
  • Small size: 26x21 mm
  • Open Source:
  • Low-cost:
    • JLCPCB production cost ~3-5€
    • Available in the shop: 7-15€

A short demo video for the SimpleFOCShield (its a bit outdated but still relevant)

Find out more about the boards and how to make them yourself in the boards section.

Alternative FOC supporting projects

The focus of SimpleFOC is making the FOC simple (:D) and supporting as many motor + sensor + driver + mcu combinations as possible. If you are a bit less concerned with the firmware simplicity and don’t mind trading-off cross-platform flexibility for performance, there are several other projects out there that also use FOC and could provide a more compact, more prefromant or more robust solutions for your applications. Many of these projects are open-source and have been our inspiration from the start, especially VESC and Odrive. Make sure to check them out if you are starting your FOC journey!

P.S. None of these projects uses SimpleFOClibrary, but SimpleFOClibrary can be used as a firware for several driver boards developed in these projects.

Project Open Source Hardware Open source firmware Simple to use Low cost Power rating Stepper Support SimpleFOC support

Odrive
βœ”οΈ/(❌ from recently) βœ”οΈ/(❌ from recently) βœ”οΈ ❌ (>200$) High >50A ❌ βœ”οΈ

Vesc
βœ”οΈ βœ”οΈ βœ”οΈ ❌ (>100$) Vey High >100A ❌ βœ”οΈ

Trinamic
❌ ❌ βœ”οΈ ❌ (>200$) Low ~10A βœ”οΈ ❌

Infineon
βœ”οΈ ❌ βœ”οΈ βœ”οΈ (50$) Low ~10A ❌ ❌

FOC-Arduino-Brushless
βœ”οΈ βœ”οΈ ❌ βœ”οΈ (Price ?) Low ~10A ❌ ? (not tested)

Tinymovr R5.2
❌ βœ”οΈ βœ”οΈ ❌ (~90$) High (~30A) ❌ ? (not tested)

Tinymovr M5.2
❌ βœ”οΈ βœ”οΈ ❌ (~90$) Low (~6Amps) ❌ ? (not tested)

Mjbots moteus
βœ”οΈ βœ”οΈ βœ”οΈ ❌ (70-160$) Mid (20Amps)
to
High (100Amps)
❌ ? (not tested)


Open robotics initiative
MicroDriver
βœ”οΈ βœ”οΈ ❌ βœ”οΈ(~50$) Mid (~20Amps) ❌ ? (not tested)


SOLO
❌ ❌ βœ”οΈ ❌(70$-600$) Mid (~16Amps)
to
Very high (~120Amps)
❌ ❌
⚠️ This list is certainly not exhaustive, feel free to contribute to extending/completing/correcting it!