Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library

License

NotificationsYou must be signed in to change notification settings

simplefoc/Arduino-FOC

Repository files navigation

A Cross-Platform FOC implementation for BLDC and Stepper motors
based on the Arduino IDE and PlatformIO

AVR buildSTM32 buildESP32 buildRP2040 buildSAMD buildTeensy buildMBED build

GitHub release (latest by date)GitHub Release DateGitHub commits since tagged versionGitHub commit activity (branch)

arduino-library-badgePlatformIO RegistryLicense: MITstatus

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:ArduinoSimpleFOClibrary
    • Support as manymotor + sensor + driver + mcu combinations out there
  • 🎯 Develop modular and easy to use FOC supporting BLDC driver boards

NEXT RELEASE 📢 :SimpleFOClibrary v2.3.5

  • ESP32 bugfix
    • after the low-level API changes in the Arduino-ESP32 corePR447
    • Pin is not configuredPR458
    • C6 MCPWM bugfixPR440
  • New fuctionality
  • SAMD21 support for low-side current sensingPR479
  • RP2350 supportPR435PR468
  • STM32
    • New driver codePR442
    • Low-side current sensing support for H7 familyPR460
  • Docs
  • See the complete list of bugfixes and new features of v2.3.5fixes and PRs

ArduinoSimpleFOClibrary v2.3.5

This video demonstrates theSimpleFOClibrary 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 manysensor +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:
  • Cross-platform:
    • Seamless code transfer from one microcontroller family to another
    • Supports multipleMCU 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 ourdocs website.

image

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.

  • Full library installationDocs
  • PlatformIODocs

ArduinoSimpleFOClibrary 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 forSimple FOC library and install the latest version.
  • Reopen Arduino IDE and you should have the library examples inFile > Examples > Simple FOC.

Using Github website

  • Go to thegithub repository
  • Click first onClone or Download > Download ZIP.
  • Unzip it and place it inArduino Libraries folder. Windows:Documents > Arduino > libraries.
  • Reopen Arduino IDE and you should have the library examples inFile > Examples > Simple FOC.

Using terminal

  • Open terminal and run
cd#Arduino libraries foldergit clone https://github.com/simplefoc/Arduino-FOC.git
  • Reopen Arduino IDE and you should have the library examples inFile > Examples > Simple FOC.

Community and contributing

For all the questions regarding the potential implementation, applications, supported hardware and similar please visit ourcommunity forum or ourdiscord 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 incommunity 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.

#include<SimpleFOC.h>//  BLDCMotor( pole_pairs )BLDCMotor motor = BLDCMotor(11);//  BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) )BLDCDriver3PWM driver = BLDCDriver3PWM(9,10,11,8);//  Encoder(pin_A, pin_B, CPR)Encoder encoder = Encoder(2,3,2048);// channel A and B callbacksvoiddoA(){encoder.handleA();}voiddoB(){encoder.handleB();}voidsetup() {// 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();}voidloop() {// 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 theSimpleFOC documentation.

Example projects

Here are some of theSimpleFOClibrary andSimpleFOCShield application examples.

Citing theSimpleFOC

We are very happy thatSimpleFOClibrary 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 aboutSimpleFOC 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 citingSimpleFOClibrary or some other component ofSimpleFOCproject in your research, we suggest you to cite our paper:

@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}}

Packages

No packages published

Contributors43

Languages


[8]ページ先頭

©2009-2025 Movatter.jp