SimpleFOC
SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors - Published in JOSS (2022)
Science Score: 98.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 6 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
○Committers with academic emails
-
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Repository
Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
Basic Info
- Host: GitHub
- Owner: simplefoc
- License: mit
- Language: C++
- Default Branch: master
- Homepage: https://docs.simplefoc.com
- Size: 10.3 MB
Statistics
- Stars: 2,466
- Watchers: 82
- Forks: 628
- Open Issues: 72
- Releases: 26
Topics
Metadata Files
README.md
SimpleFOClibrary - Simple Field Oriented Control (FOC) library
A Cross-Platform FOC implementation for BLDC and Stepper motors
based on the Arduino IDE and PlatformIO
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. BLDC 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 are yet to come. One of the reasons for this is the apparent complexity of writing the BLDC driving algorithms, Field oriented control (FOC) being an example of one of the most efficient ones.
The solutions that can be found on-line are almost exclusively very specific for certain hardware configuration and the microcontroller architecture used.
Additionally, most of the efforts at this moment are still channeled towards the high-power applications of the BLDC motors and proper low-cost and low-power FOC supporting boards are very hard to find today and even may not exist.
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
- 🎯 Develop modular and easy to use FOC supporting BLDC driver boards
- For official driver boards see SimpleFOCBoards
- Many many more boards developed by the community members, see SimpleFOCCommunity
NEXT RELEASE 📢 : SimpleFOClibrary v2.3.5
- ESP32 bugfix
- New fuctionality
- HybridStepperMotor added to the main library PR457 - see in docs
- Motor characterisation (phase resistance and inductance) PR436 - see in docs
- SAMD21 support for low-side current sensing PR479
- RP2350 support PR435 PR468
- STM32
- Docs
- Hybrid stepper motor example see in docs
- Sensorless FOC example see in docs
- A short guide to synchronous loop - see in docs
- See the complete list of bugfixes and new features of v2.3.5 fixes and PRs
Arduino SimpleFOClibrary v2.3.5
This video 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 combination as possible.
- Provide the up-to-date and in-depth documentation with API references and the examples
- Easy to setup and configure:
- Easy hardware configuration
- Each hardware component is a C++ object (easy to understand)
- Easy tuning the control loops
- SimpleFOCStudio configuration GUI tool
- Built-in communication and monitoring
- Cross-platform:
- Seamless code transfer from one microcontroller family to another
- Supports multiple MCU architectures:
- Arduino: UNO R4, UNO, MEGA, DUE, Leonardo, Nano, Nano33 ....
- STM32
- ESP32
- Teensy
- many more ...

Documentation
Full API code documentation as well as example projects and step by step guides can be found on our docs website.

Getting Started
Depending on if you want to use this library as the plug and play Arduino library or you want to get insight in the algorithm and make changes there are two ways to install this code.
Arduino SimpleFOClibrary installation to Arduino IDE
Arduino Library Manager
The simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager.
- Open Arduino IDE and start Arduino Library Manager by clicking: Tools > Manage Libraries....
- Search for Simple FOC library and install the latest version.
- Reopen Arduino IDE and you should have the library examples in File > Examples > Simple FOC.
Using Github website
- Go to the github repository
- Click first on
Clone or Download > Download ZIP. - Unzip it and place it in
Arduino Librariesfolder. Windows:Documents > Arduino > libraries. - Reopen Arduino IDE and you should have the library examples in
File > Examples > Simple FOC.
Using terminal
- Open terminal and run
sh cd #Arduino libraries folder git clone https://github.com/simplefoc/Arduino-FOC.git - Reopen Arduino IDE and you should have the library examples in
File > Examples > Simple FOC.
Community and contributing
For all the questions regarding the potential implementation, applications, supported hardware and similar please visit our community forum or our discord server.
It is always helpful to hear the stories/problems/suggestions of people implementing the code and you might find a lot of answered questions there already!
Github Issues & Pull requests
Please do not hesitate to leave an issue if you have problems/advices/suggestions regarding the code!
Pull requests are welcome, but let's first discuss them in community forum!
If you'd like to contribute to this project but you are not very familiar with github, don't worry, let us know either by posting at the community forum , by posting a github issue or at our discord server.
If you are familiar, we accept pull requests to the dev branch!
Arduino code example
This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder.
NOTE: This program uses all the default control parameters.
```cpp
include
// BLDCMotor( polepairs ) BLDCMotor motor = BLDCMotor(11); // BLDCDriver( pinpwmA, pinpwmB, pinpwmC, enable (optional) ) BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8); // Encoder(pinA, pinB, 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.voltagepowersupply = 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); } ``` You can find more details in the SimpleFOC documentation.
Example projects
Here are some of the SimpleFOClibrary and SimpleFOCShield application examples.
Citing the SimpleFOC
We are very happy that SimpleFOClibrary has been used as a component of several research project and has made its way to several scientific papers. We are hoping that this trend is going to continue as the project matures and becomes more robust! A short resume paper about SimpleFOC** has been published in the Journal of Open Source Software:
SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors.
A. Skuric, HS. Bank, R. Unger, O. Williams, D. González-Reyes
Journal of Open Source Software, 7(74), 4232, https://doi.org/10.21105/joss.04232
If you are interested in citing SimpleFOClibrary or some other component of SimpleFOCproject in your research, we suggest you to cite our paper:
```bib @article{simplefoc2022, doi = {10.21105/joss.04232}, url = {https://doi.org/10.21105/joss.04232}, year = {2022}, publisher = {The Open Journal}, volume = {7}, number = {74}, pages = {4232}, author = {Antun Skuric and Hasan Sinan Bank and Richard Unger and Owen Williams and David González-Reyes}, title = {SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors}, journal = {Journal of Open Source Software} }
```
Owner
- Name: SimpleFOCproject
- Login: simplefoc
- Kind: organization
- Email: info@simplefoc.com
- Location: France
- Website: https://simplefoc.com
- Repositories: 10
- Profile: https://github.com/simplefoc
Arduino FOC for BLDC motors - Arduino based Field Oriented Control algorithm implementation
JOSS Publication
SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors
Authors
California State University, Chico, United States of America, Craftnetics Inc., United States of America
Community Member
Community Member
Tags
Motor Control Dynamical Robot Control Applied Control Theory cppCitation (CITATION.cff)
cff-version: 1.0.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Skuric"
given-names: "Antun"
orcid: "https://orcid.org/0000-0002-3323-4482"
- family-names: "Bank"
given-names: "Hasan Sinan"
orcid: "https://orcid.org/0000-0002-0626-2664"
- family-names: "Unger"
given-names: "Richard"
- family-names: "Williams"
given-names: "Owen"
- family-names: "González-Reyes"
given-names: "David"
orcid: "https://orcid.org/0000-0002-1535-3007"
title: "SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors"
version: 2.2.2
doi: 10.21105/joss.04232
date-released: 2022-06-26
url: "https://github.com/simplefoc/Arduino-FOC"
preferred-citation:
type: article
authors:
- family-names: "Skuric"
given-names: "Antun"
orcid: "https://orcid.org/0000-0002-3323-4482"
- family-names: "Bank"
given-names: "Hasan Sinan"
orcid: "https://orcid.org/0000-0002-0626-2664"
- family-names: "Unger"
given-names: "Richard"
- family-names: "Williams"
given-names: "Owen"
- family-names: "González-Reyes"
given-names: "David"
orcid: "https://orcid.org/0000-0002-1535-3007"
doi: "10.21105/joss.04232"
journal: "Journal of Open Source Software"
url: "https://doi.org/10.21105/joss.04232"
month: 6
start: 4232 # First page number
end: 4232 # Last page number
title: "SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors"
volume: 7
issue: 74
year: 2022
GitHub Events
Total
- Create event: 6
- Release event: 1
- Issues event: 26
- Watch event: 361
- Issue comment event: 86
- Push event: 38
- Pull request review comment event: 2
- Pull request review event: 2
- Pull request event: 34
- Fork event: 90
Last Year
- Create event: 6
- Release event: 1
- Issues event: 26
- Watch event: 361
- Issue comment event: 86
- Push event: 38
- Pull request review comment event: 2
- Pull request review event: 2
- Pull request event: 34
- Fork event: 90
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| askuric | a****c@o****m | 666 |
| Richard Unger | r****r@n****m | 132 |
| Richard Unger | r****r@a****t | 79 |
| Owen Williams | w****n@g****m | 28 |
| Candas1 | c****g@h****m | 18 |
| Stefan Dessens | s****s@g****m | 9 |
| dekutree64 | 5****4 | 9 |
| maxime | m****r@g****m | 9 |
| gagarcr | g****m@g****m | 7 |
| mcells | 3****s | 7 |
| David | d****s@g****m | 6 |
| askuric | y****u@e****m | 5 |
| maxime | m****r@n****m | 4 |
| Tim Meehan | b****n@g****m | 3 |
| copper280z | r****9@g****m | 3 |
| Adam | a****t@g****m | 2 |
| Chimera | 5****e | 2 |
| Jordan Cormack | 3****k | 2 |
| Louis Frank | l****w@g****m | 2 |
| Arturo Hernandez | a****z@c****m | 2 |
| Rob Deutsch | r****h | 2 |
| Sam | w****i@g****m | 2 |
| nmscode | 1****e | 2 |
| qazxswedcvfrtgbnhyujmkiolp | 2****d@g****m | 1 |
| ABA | a****n@n****m | 1 |
| gabriel.garcia | g****a@s****m | 1 |
| jeroen | j****l@t****l | 1 |
| candyriver | 3****r | 1 |
| Yuyang Wang | 3****t | 1 |
| Yannik Stradmann | 4****n | 1 |
| and 18 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 106
- Total pull requests: 148
- Average time to close issues: 6 months
- Average time to close pull requests: about 2 months
- Total issue authors: 70
- Total pull request authors: 40
- Average comments per issue: 3.0
- Average comments per pull request: 2.01
- Merged pull requests: 93
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 20
- Pull requests: 47
- Average time to close issues: 10 days
- Average time to close pull requests: 21 days
- Issue authors: 19
- Pull request authors: 15
- Average comments per issue: 0.6
- Average comments per pull request: 1.19
- Merged pull requests: 26
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- runger1101001 (9)
- sylque (6)
- askuric (5)
- owennewo (5)
- dekutree64 (3)
- z13660 (2)
- steph643 (2)
- Theexternaldisk (2)
- binsruby (2)
- GK-383 (2)
- MGJ520 (2)
- sDessens (2)
- Kurburis (2)
- bgvsan (2)
- Wenuo (2)
Pull Request Authors
- runger1101001 (39)
- askuric (25)
- owennewo (9)
- Candas1 (8)
- Copper280z (7)
- cousinitt (6)
- AntonEvmenenko (4)
- KaSroka (3)
- sDessens (3)
- maxlem (3)
- mcells (3)
- rob-deutsch (3)
- charizardavi (2)
- tikonen (2)
- adamgerhant (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- ArminJo/arduino-test-compile master composite
- actions/checkout master composite