|
1 |
| -# SimpleFOClibrary - **Simple** Field Oriented Control (FOC) **library** <br> |
2 |
| -### A Cross-Platform FOC implementation for BLDC and Stepper motors<br> based on the Arduino IDE and PlatformIO |
| 1 | +# Espressif Arduino-FOC Fork |
3 | 2 |
|
4 |
| - |
5 |
| - |
6 |
| - |
7 |
| - |
8 |
| - |
| 3 | +This is a fork of upstream [Arduino-FOC](https://github.com/simplefoc/Arduino-FOC) with integration into ESP-IDF build system. |
9 | 4 |
|
10 |
| -[](https://www.ardu-badge.com/badge/Simple%20FOC.svg) |
11 |
| -[](https://opensource.org/licenses/MIT) |
12 |
| -[](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d) |
| 5 | +This fork repository is wrapped as an ESP-IDF component, which offers the algorithm implementation of FOC (Field Oriented Control) for BLDC and stepper motors. |
13 | 6 |
|
| 7 | +To drive the motors, you need to use this component together with [esp_simplefoc](https://github.com/espressif/esp-iot-solution/tree/master/components/motor/esp_simplefoc), which offers the hardware drivers for motors. |
14 | 8 |
|
15 |
| -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. |
16 |
| -The solutions that can be found on-line are almost exclusively very specific for certain hardware configuration and the microcontroller architecture used. |
17 |
| -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. <br> |
18 |
| -Therefore this is an attempt to: |
19 |
| -- 🎯 Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase) |
20 |
| - - <i>Support as many <b>motor + sensor + driver + mcu</b> combinations out there</i> |
21 |
| -- 🎯 Develop a modular FOC supporting BLDC driver boards: |
22 |
| - - ***NEW*** 📢: *Minimalistic* BLDC driver (<3Amps) : [<span class="simple">Simple<b>FOC</b>Mini</span> ](https://github.com/simplefoc/SimpleFOCMini). |
23 |
| - - *Low-power* gimbal driver (<5Amps) : [*Arduino Simple**FOC**Shield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase). |
24 |
| - - *Medium-power* BLDC driver (<30Amps): [Arduino <span class="simple">Simple<b>FOC</b>PowerShield</span> ](https://github.com/simplefoc/Arduino-SimpleFOC-PowerShield). |
25 |
| - - See also [@byDagor](https://github.com/byDagor)'s *fully-integrated* ESP32 based board: [Dagor Brushless Controller](https://github.com/byDagor/Dagor-Brushless-Controller) |
26 | 9 |
|
27 |
| -> NEW RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.0 |
28 |
| -> - Arduino Mega 6pwm more timers supported |
29 |
| -> - Arduino boards - frequency change support either 32kHz or 4kHz |
30 |
| -> - Arduino Uno - synched timers in 3pwm and 6pwm mode [#71](https://github.com/simplefoc/Arduino-FOC/issues/71) |
31 |
| -> - Teensy 3.x initial support for 6pwm |
32 |
| -> - Teensy 4.x initial support for 6pwm |
33 |
| -> - Example for v3.1 SimpleFOCShield |
34 |
| -> - RP2040 compatibility for earlehillpower core [#234](https://github.com/simplefoc/Arduino-FOC/pull/234) [#236](https://github.com/simplefoc/Arduino-FOC/pull/236) |
35 |
| -> - More flexible monitoring API |
36 |
| -> - start, end and separator characters |
37 |
| -> - decimal places (settable through commander) |
38 |
| -> - Added machine readable verbose mode in `Commander` [#233](https://github.com/simplefoc/Arduino-FOC/pull/233) |
39 |
| -> - *Simple**FOC**WebController* - Web based user interface for SimpleFOC by [@geekuillaume](https://github.com/geekuillaume) - [webcontroller.simplefoc.com](webcontroller.simplefoc.com) |
40 |
| -> - bugfix - `MagneticSensorPWM` multiple occasions - [#258](https://github.com/simplefoc/Arduino-FOC/pull/258) |
41 |
| -> - bugfix - current sense align - added offset exchange when exchanging pins |
42 |
| -> - bugfix - trapezoid 150 fixed |
43 |
| -> - bugfix - 4pwm on ESP8266 [#224](https://github.com/simplefoc/Arduino-FOC/pull/224) |
44 |
| -> - Additional `InlineCurrentSense` and `LowsideCurrentSense` constructor using milliVolts per Amp [#253](https://github.com/simplefoc/Arduino-FOC/pull/253) |
45 |
| -> - STM32L4xx current sense support by [@Triple6](https://github.com/Triple6) (discord) [#257](https://github.com/simplefoc/Arduino-FOC/pull/257) |
46 |
| -> - phase disable in 6pwm mode |
47 |
| -> - stm32 - software and hardware 6pwm |
48 |
| -> - atmega328 |
49 |
| -> - atmega2560 |
50 |
| -> - Lag compensation using motor inductance [#246](https://github.com/simplefoc/Arduino-FOC/issues/246) |
51 |
| -> - current control through voltage torque mode enhancement |
52 |
| -> - extended `BLDCMotor` and `StepperMotor` constructors to receive the inductance paramerer |
53 |
| -> - can also be set using `motor.phase_inductance` or through `Commander` |
54 |
| -## Arduino *SimpleFOClibrary* v2.3 |
| 10 | +## How to use |
55 | 11 |
|
56 |
| -<p align=""> |
57 |
| -<a href="https://youtu.be/Y5kLeqTc6Zk"> |
58 |
| -<img src="https://docs.simplefoc.com/extras/Images/youtube.png" height="320px"> |
59 |
| -</a> |
60 |
| -</p> |
| 12 | +### Use this component together with [esp_simplefoc](https://github.com/espressif/esp-iot-solution/tree/master/components/motor/esp_simplefoc). |
61 | 13 |
|
62 |
| -This video demonstrates the *Simple**FOC**library* basic usage, electronic connections and shows its capabilities. |
| 14 | +Just add ``idf_component.yml`` to your main component with the following content:: |
63 | 15 |
|
64 |
| -### Features |
65 |
| -- **Easy install**: |
66 |
| - - Arduino IDE: Arduino Library Manager integration |
67 |
| - - PlatformIO |
68 |
| -- **Open-Source**: Full code and documentation available on github |
69 |
| -- **Goal**: |
70 |
| - - Support as many [sensor](https://docs.simplefoc.com/position_sensors) + [motor](https://docs.simplefoc.com/motors) + [driver](https://docs.simplefoc.com/drivers) + [current sense](https://docs.simplefoc.com/current_sense) combination as possible. |
71 |
| - - Provide the up-to-date and in-depth documentation with API references and the examples |
72 |
| -- **Easy to setup and configure**: |
73 |
| - - Easy hardware configuration |
74 |
| - - Each hardware component is a C++ object (easy to understand) |
75 |
| - - Easy [tuning the control loops](https://docs.simplefoc.com/motion_control) |
76 |
| - - [*Simple**FOC**Studio*](https://docs.simplefoc.com/studio) configuration GUI tool |
77 |
| - - Built-in communication and monitoring |
78 |
| -- **Cross-platform**: |
79 |
| - - Seamless code transfer from one microcontroller family to another |
80 |
| - - Supports multiple [MCU architectures](https://docs.simplefoc.com/microcontrollers): |
81 |
| - - Arduino: UNO, MEGA, DUE, Leonardo .... |
82 |
| - - STM32 |
83 |
| - - ESP32 |
84 |
| - - Teensy |
85 |
| - - many more ... |
86 |
| - |
87 |
| -<p align=""> <img src="https://docs.simplefoc.com/extras/Images/uno_l6234.jpg" height="170px"> <img src="https://docs.simplefoc.com/extras/Images/hmbgc_v22.jpg" height="170px"> <img src="https://docs.simplefoc.com/extras/Images/foc_shield_v13.jpg" height="170px"></p> |
88 |
| - |
89 |
| - |
90 |
| -## Documentation |
91 |
| -Full API code documentation as well as example projects and step by step guides can be found on our [docs website](https://docs.simplefoc.com/). |
92 |
| - |
93 |
| - |
94 |
| - |
95 |
| - |
96 |
| -## Getting Started |
97 |
| -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. |
98 |
| - |
99 |
| -- Full library installation [Docs](https://docs.simplefoc.com/library_download) |
100 |
| -- PlatformIO [Docs](https://docs.simplefoc.com/library_platformio) |
101 |
| - |
102 |
| -### Arduino *SimpleFOClibrary* installation to Arduino IDE |
103 |
| -#### Arduino Library Manager |
104 |
| -The simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager. |
105 |
| -- Open Arduino IDE and start Arduino Library Manager by clicking: `Tools > Manage Libraries...`. |
106 |
| -- Search for `Simple FOC` library and install the latest version. |
107 |
| -- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. |
108 |
| - |
109 |
| -#### Using Github website |
110 |
| -- Go to the [github repository](https://github.com/simplefoc/Arduino-FOC) |
111 |
| -- Click first on `Clone or Download > Download ZIP`. |
112 |
| -- Unzip it and place it in `Arduino Libraries` folder. Windows: `Documents > Arduino > libraries`. |
113 |
| -- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. |
114 |
| - |
115 |
| -#### Using terminal |
116 |
| -- Open terminal and run |
117 |
| -```sh |
118 |
| -cd #Arduino libraries folder |
119 |
| -git clone https://github.com/simplefoc/Arduino-FOC.git |
| 16 | +```yaml |
| 17 | +## IDF Component Manager Manifest File |
| 18 | +dependencies: |
| 19 | + esp_simplefoc: "*" |
120 | 20 | ```
|
121 |
| -- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`. |
122 |
| - |
123 |
| -## Community and contributing |
124 |
| - |
125 |
| -For all the questions regarding the potential implementation, applications, supported hardware and similar please visit our [community forum](https://community.simplefoc.com) or our [discord server](https://discord.gg/kWBwuzY32n). |
126 |
| - |
127 |
| -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! |
128 |
| - |
129 |
| -### Github Issues & Pull requests |
130 |
| - |
131 |
| -Please do not hesitate to leave an issue if you have problems/advices/suggestions regarding the code! |
132 |
| - |
133 |
| -Pull requests are welcome, but let's first discuss them in [community forum](https://community.simplefoc.com)! |
134 | 21 |
|
135 |
| -If you'd like to contribute to this porject 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. |
| 22 | +Or simply run: |
136 | 23 |
|
137 |
| -## Arduino code example |
138 |
| -This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder. |
139 |
| - |
140 |
| -NOTE: This program uses all the default control parameters. |
141 |
| - |
142 |
| -```cpp |
143 |
| -#include <SimpleFOC.h> |
144 |
| - |
145 |
| -// BLDCMotor( pole_pairs ) |
146 |
| -BLDCMotor motor = BLDCMotor(11); |
147 |
| -// BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) ) |
148 |
| -BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8); |
149 |
| -// Encoder(pin_A, pin_B, CPR) |
150 |
| -Encoder encoder = Encoder(2, 3, 2048); |
151 |
| -// channel A and B callbacks |
152 |
| -void doA(){encoder.handleA();} |
153 |
| -void doB(){encoder.handleB();} |
154 |
| - |
155 |
| - |
156 |
| -void setup() { |
157 |
| - // initialize encoder hardware |
158 |
| - encoder.init(); |
159 |
| - // hardware interrupt enable |
160 |
| - encoder.enableInterrupts(doA, doB); |
161 |
| - // link the motor to the sensor |
162 |
| - motor.linkSensor(&encoder); |
163 |
| - |
164 |
| - // power supply voltage [V] |
165 |
| - driver.voltage_power_supply = 12; |
166 |
| - // initialise driver hardware |
167 |
| - driver.init(); |
168 |
| - // link driver |
169 |
| - motor.linkDriver(&driver); |
170 |
| - |
171 |
| - // set control loop type to be used |
172 |
| - motor.controller = MotionControlType::velocity; |
173 |
| - // initialize motor |
174 |
| - motor.init(); |
175 |
| - |
176 |
| - // align encoder and start FOC |
177 |
| - motor.initFOC(); |
178 |
| -} |
179 |
| - |
180 |
| -void loop() { |
181 |
| - // FOC algorithm function |
182 |
| - motor.loopFOC(); |
183 |
| - |
184 |
| - // velocity control loop function |
185 |
| - // setting the target velocity or 2rad/s |
186 |
| - motor.move(2); |
187 |
| -} |
188 | 24 | ```
|
189 |
| -You can find more details in the [SimpleFOC documentation](https://docs.simplefoc.com/). |
190 |
| - |
191 |
| -## Example projects |
192 |
| -Here are some of the *Simple**FOC**library* and *Simple**FOC**Shield* application examples. |
193 |
| -<p align="center"> |
194 |
| -<a href="https://youtu.be/Ih-izQyXJCI"> |
195 |
| -<img src="https://docs.simplefoc.com/extras/Images/youtube_pendulum.png" height="200px" > |
196 |
| -</a> |
197 |
| -<a href="https://youtu.be/xTlv1rPEqv4"> |
198 |
| -<img src="https://docs.simplefoc.com/extras/Images/youtube_haptic.png" height="200px" > |
199 |
| -</a> |
200 |
| -<a href="https://youtu.be/RI4nNMF608I"> |
201 |
| -<img src="https://docs.simplefoc.com/extras/Images/youtube_drv8302.png" height="200px" > |
202 |
| -</a> |
203 |
| -<a href="https://youtu.be/zcb86TRxTxc"> |
204 |
| -<img src="https://docs.simplefoc.com/extras/Images/youtube_stepper.png" height="200px" > |
205 |
| -</a> |
206 |
| -</p> |
207 |
| - |
208 |
| - |
209 |
| -## Citing the *SimpleFOC* |
210 |
| - |
211 |
| -We are very happy that *Simple**FOC**library* 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! |
212 |
| -A short resume paper about *Simple**FOC*** has been published in the Journal of Open Source Software: |
213 |
| -<p> |
214 |
| - <b><i>SimpleFOC</i></b>: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors.<br> |
215 |
| - A. Skuric, HS. Bank, R. Unger, O. Williams, D. González-Reyes<br> |
216 |
| -Journal of Open Source Software, 7(74), 4232, https://doi.org/10.21105/joss.04232 |
217 |
| -</p> |
218 |
| - |
219 |
| -If you are interested in citing *Simple**FOC**library* or some other component of *Simple**FOC**project* in your research, we suggest you to cite our paper: |
| 25 | +idf.py add-dependency "esp_simplefoc" |
| 26 | +``` |
220 | 27 |
|
221 |
| -```bib |
222 |
| -@article{simplefoc2022, |
223 |
| - doi = {10.21105/joss.04232}, |
224 |
| - url = {https://doi.org/10.21105/joss.04232}, |
225 |
| - year = {2022}, |
226 |
| - publisher = {The Open Journal}, |
227 |
| - volume = {7}, |
228 |
| - number = {74}, |
229 |
| - pages = {4232}, |
230 |
| - author = {Antun Skuric and Hasan Sinan Bank and Richard Unger and Owen Williams and David González-Reyes}, |
231 |
| - title = {SimpleFOC: A Field Oriented Control (FOC) Library for Controlling Brushless Direct Current (BLDC) and Stepper Motors}, |
232 |
| - journal = {Journal of Open Source Software} |
233 |
| -} |
| 28 | +## API Documentation |
234 | 29 |
|
235 |
| -``` |
| 30 | +1. Library introduction can be found on [README](https://github.com/simplefoc/Arduino-FOC/blob/master/README.md) from the upstream Arduino-FOC. |
| 31 | +2. Full API code documentation as well as example projects and step by step guides can be found on [SimpleFOC Docs Website](https://docs.simplefoc.com/). |
0 commit comments