Skip to content

Commit 8237a12

Browse files
committed
MERGE dev v2.0
2 parents 7ebf6f8 + c678744 commit 8237a12

File tree

79 files changed

+2756
-1086
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+2756
-1086
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ jobs:
1111
uses: ArminJo/[email protected]
1212
with:
1313
libraries: PciManager
14-
examples-exclude: bluepill_position_control, esp32_position_control
14+
examples-exclude: bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example

README.md

Lines changed: 73 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Arduino Simple Field Oriented Control (FOC) library
22

33

4-
![Library Compile](https://github.com/askuric/Arduino-FOC/workflows/Library%20Compile/badge.svg)
4+
![Library Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Compile/badge.svg)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66
[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
77

@@ -11,7 +11,39 @@ Therefore this is an attempt to:
1111
- Develop a modular BLDC driver board: [Arduino *SimpleFOCShield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase).
1212
- ***New 📢:** Develop a modular Stepper motor board for FOC control:* <b>Arduino <span class="simple">Stepper<span class="foc">FOC</span>Shield</span></b>
1313

14-
<blockquote class="info"><p> <b>NEW RELEASE 📢:</b> <i>Simple<b>FOC</b>library v1.6.0</i><br></p><ul><li><strong>Stepper motor FOC support 🎨🎉 🎊 <a href="https://docs.simplefoc.com/motors">See in docs!</a></strong><ul><li>No losing steps</li><li>Backdrivable</li><li>Better dynamics than open-loop, Smoother than open-loop</li><li>short demo <a href="https://youtu.be/w_yIY0eXM5E">youtube video</a></li></ul></li><li>Teensy support by <em>Christopher Parrott</em> <br></li><li>Pull requests by <a href="https://github.com/cousinitt">@cousinitt</a><ul><li>refactoring and c++11 improvements</li><li>pid + low pass filter refactoring</li></ul></li><li>Extended configurability of the sensor classes by <a href="https://github.com/owennewo">@owennewo</a> <b><a href="https://docs.simplefoc.com/magnetic_sensor">See in docs!</a></b></li><li>configurable pwm frequency <b><a href="https://docs.simplefoc.com/motor_initialization#step-33-pwm-frequency-configuration-optional">See in docs!</a></b><ul><li>stm32,teensy,eps32 - not for Arduino</li><li>stm32 added 12bit pwm resolution by <em>Jürgen Frisch</em></li></ul></li><li>Huge refactoring done in the library 😄</li></ul></blockquote>
14+
<blockquote class="info"><p> <b>NEW RELEASE 📢:</b> <i>Simple<b>FOC</b>library v2.0</i><br></p><ul>
15+
<li><strong>6PWM support </strong>
16+
<ul>
17+
<li>Arduino UNO (atmega328)</li>
18+
<li>stm32 boards</li>
19+
<li>esp32 boards</li>
20+
</ul>
21+
</li>
22+
<li>BLDC driver code separated
23+
<ul>
24+
<li> BLDC: 6pwm and 3pwm</li>
25+
<li> Stepper: 4pwm</li>
26+
<li> Hardware specific code in separate files</li>
27+
<li> PWM config</li>
28+
</ul>
29+
</li>
30+
<li>I2C and SPI sensors multiple busses support by <a href="https://github.com/owennewo">@owennewo</a>
31+
</li>
32+
<li>Initial implementation of Block commutation by <a href="https://github.com/owennewo">@owennewo</a>
33+
<ul>
34+
<li> FOCModulationType::Trapezoid_120</li>
35+
<li> FOCModulationType::Trapezoid_150 </li>
36+
</ul>
37+
</li>
38+
<li>Added support for separate setting of <i>U<sub>d</sub></i> and <i>U<sub>q</sub></i> setting.
39+
<ul>
40+
<li> Preparations for current control</li>
41+
<li> Working only for SinePWM modulation at the moment </li>
42+
</ul></li>
43+
<li>A lot of refactoring </li>
44+
</ul>
45+
<i>The library version v2.0 will be released once when it is properly tested and documented!</i>
46+
</blockquote>
1547

1648
## Arduino *SimpleFOCShield*
1749

@@ -33,7 +65,7 @@ Therefore this is an attempt to:
3365
- **Arduino headers**: Arduino UNO, Arduino MEGA, STM32 Nucleo boards...
3466
- **Open Source**: Fully available fabrication files - [how to make it yourself](https://www.simplefoc.com/arduino_simplefoc_shield_fabrication),
3567

36-
##### If you are interested in this board, order your version on this link: [Simple FOC Shop](https://www.simplefoc.com/simplefoc_shield_product)
68+
##### If you are interested in this board, order your version on this link: [Shop](https://www.simplefoc.com/simplefoc_shield_product)
3769

3870
<p align=""><img src="https://docs.simplefoc.com/extras/Images/shield_to_v13.jpg" height="180px"> <img src="https://docs.simplefoc.com/extras/Images/shield_bo_v13.jpg" height="180px"> <img src="https://docs.simplefoc.com/extras/Images/simple_foc_shield_v13_small.gif" height="180x"></p>
3971

@@ -46,7 +78,7 @@ Therefore this is an attempt to:
4678
</a>
4779
</p>
4880

49-
This video demonstrates the Simple FOC library basic usage, electronic connections and shows its capabilities.
81+
This video demonstrates the *Simple**FOC**library* basic usage, electronic connections and shows its capabilities.
5082

5183

5284
### Features
@@ -72,46 +104,37 @@ This video demonstrates the Simple FOC library basic usage, electronic connectio
72104
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.
73105

74106
- Full library installation [Docs](https://docs.simplefoc.com/library_download)
75-
- Minimal code installation [Docs](https://docs.simplefoc.com/minimal_download)
107+
- Minimal project builder [Docs](https://docs.simplefoc.com/minimal_download)
76108

77-
### Arduino SimpleFOC library installation to Arduino IDE
109+
### Arduino *SimpleFOClibrary* installation to Arduino IDE
78110
#### Arduino Library Manager
79111
The simplest way to get hold of the library is directly by using Arduino IDE and its integrated Library Manager.
80112
- Open Arduino IDE and start Arduino Library Manager by clicking: `Tools > Manage Libraries...`.
81113
- Search for `Simple FOC` library and install the latest version.
82114
- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`.
83115

84-
### Using Github website
85-
- Go to the [github repository](https://github.com/askuric/Arduino-FOC)
116+
#### Using Github website
117+
- Go to the [github repository](https://github.com/simplefoc/Arduino-FOC)
86118
- Click first on `Clone or Download > Download ZIP`.
87119
- Unzip it and place it in `Arduino Libraries` folder. Windows: `Documents > Arduino > libraries`.
88120
- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`.
89121

90-
### Using terminal
122+
#### Using terminal
91123
- Open terminal and run
92124
```sh
93-
cd *arduino libraries folder*
94-
git clone https://github.com/askuric/Arduino-FOC.git
125+
cd #Arduino libraries folder
126+
git clone https://github.com/simplefoc/Arduino-FOC.git
95127
```
96128
- Reopen Arduino IDE and you should have the library examples in `File > Examples > Simple FOC`.
97129

98-
### SimpleFOC library minimal sketch example
130+
### *SimpleFOClibrary* minimal project builder
99131

100-
For those willing to experiment and to modify the code I suggest using the [minimal version](https://github.com/askuric/Arduino-FOC/tree/minimal) of the code.
132+
For those willing to experiment and to modify the code I suggest using the minimal project builder [minimal branch](https://github.com/simplefoc/Arduino-FOC/tree/minimal).
101133
> This code is completely independent and you can run it as any other Arduino Sketch without the need for any libraries.
102134
103-
#### Github website download
104-
- Go to [minimal branch](https://github.com/askuric/Arduino-FOC/tree/minimal)
105-
- Download the code by clicking on the `Clone or Download > Download ZIP`.
106-
- Unzip it and open the sketch in Arduino IDE.
107-
108-
#### Using terminal
109-
- Open the terminal:
110-
```sh
111-
cd *to you desired directory*
112-
git clone -b minimal https://github.com/askuric/Arduino-FOC.git
113-
```
114-
- Then you just open it with the Arduino IDE and run it.
135+
All you need to do is:
136+
- Go to [minimal branch](https://github.com/simplefoc/Arduino-FOC/tree/minimal)
137+
- Follow the tutorial in the README file and choose only the library files that are necessary for your application.
115138

116139
## Arduino code example
117140
This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder.
@@ -121,8 +144,10 @@ NOTE: This program uses all the default control parameters.
121144
```cpp
122145
#include <SimpleFOC.h>
123146

124-
// BLDCMotor( pin_pwmA, pin_pwmB, pin_pwmC, pole_pairs, enable (optional))
125-
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
147+
// BLDCMotor( pole_pairs )
148+
BLDCMotor motor = BLDCMotor(11);
149+
// BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) )
150+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
126151
// Encoder(pin_A, pin_B, CPR)
127152
Encoder encoder = Encoder(2, 3, 2048);
128153
// channel A and B callbacks
@@ -138,10 +163,12 @@ void setup() {
138163
// link the motor to the sensor
139164
motor.linkSensor(&encoder);
140165

141-
// use monitoring with the BLDCMotor
142-
Serial.begin(115200);
143-
// monitoring port
144-
motor.useMonitoring(Serial);
166+
// power supply voltage [V]
167+
driver.voltage_power_supply = 12;
168+
// initialise driver hardware
169+
driver.init();
170+
// link driver
171+
motor.linkDriver(&driver);
145172

146173
// set control loop type to be used
147174
motor.controller = ControlType::velocity;
@@ -159,31 +186,27 @@ void loop() {
159186
// velocity control loop function
160187
// setting the target velocity or 2rad/s
161188
motor.move(2);
162-
163-
// monitoring function outputting motor variables to the serial terminal
164-
motor.monitor();
165189
}
166190
```
167191
You can find more details in the [SimpleFOC documentation](https://docs.simplefoc.com/).
168192

169193
## Example projects
170-
Here are some of the SimpleFOC application examples.
171-
### Arduino Field Oriented Controlled Reaction Wheel Inverted Pendulum
172-
This is a very cool open-source project of one of the simplest setups of the Reaction wheel inverted pendulum. Check out all the components and projects notes in the [github repository](https://github.com/askuric/Arduino-FOC-reaction-wheel-inverted-pendulum).
173-
<p align="">
194+
Here are some of the *Simple**FOC**library* and *Simple**FOC**Shield* application examples.
195+
<p align="center">
174196
<a href="https://youtu.be/Ih-izQyXJCI">
175-
<img src="https://docs.simplefoc.com/extras/Images/youtube_pendulum.png" height="320px">
197+
<img src="https://docs.simplefoc.com/extras/Images/youtube_pendulum.png" height="200px" >
198+
</a>
199+
<a href="https://youtu.be/xTlv1rPEqv4">
200+
<img src="https://docs.simplefoc.com/extras/Images/youtube_haptic.png" height="200px" >
201+
</a>
202+
<a href="https://youtu.be/RI4nNMF608I">
203+
<img src="https://docs.simplefoc.com/extras/Images/youtube_drv8302.png" height="200px" >
204+
</a>
205+
<a href="https://youtu.be/zcb86TRxTxc">
206+
<img src="https://docs.simplefoc.com/extras/Images/youtube_stepper.png" height="200px" >
176207
</a>
177208
</p>
178209

179-
**The main benefits of using the BLDC motor in this project are:**
180-
- High torque to weight ratio
181-
- The lighter the better
182-
- Lots of torque for low angular velocities
183-
- No need to spin the motor to very high PRM to achieve high torques
184-
- No gearboxes and backlash
185-
- Very smooth operation = very stable pendulum
186-
187210

188211
## Documentation
189212
Find out more information about the Arduino SimpleFOC project in [docs website](https://docs.simplefoc.com/)
@@ -192,6 +215,6 @@ Find out more information about the Arduino SimpleFOC project in [docs website](
192215
## Arduino FOC repo structure
193216
Branch | Description | Status
194217
------------ | ------------- | ------------
195-
[master](https://github.com/askuric/Arduino-FOC) | Stable and tested library version | ![Library Compile](https://github.com/askuric/Arduino-FOC/workflows/Library%20Compile/badge.svg)
196-
[dev](https://github.com/askuric/Arduino-FOC/tree/dev) | Development library version | ![Library Dev Compile](https://github.com/askuric/Arduino-FOC/workflows/Library%20Dev%20Compile/badge.svg?branch=dev)
197-
[minimal](https://github.com/askuric/Arduino-FOC/tree/minimal) | Minimal Arduino example with integrated library | ![MinimalBuild](https://github.com/askuric/Arduino-FOC/workflows/MinimalBuild/badge.svg?branch=minimal)
218+
[master](https://github.com/simplefoc/Arduino-FOC) | Stable and tested library version | ![Library Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Compile/badge.svg)
219+
[dev](https://github.com/simplefoc/Arduino-FOC/tree/dev) | Development library version | ![Library Dev Compile](https://github.com/simplefoc/Arduino-FOC/workflows/Library%20Dev%20Compile/badge.svg?branch=dev)
220+
[minimal](https://github.com/simplefoc/Arduino-FOC/tree/minimal) | Minimal Arduino example with integrated library | ![MinimalBuild](https://github.com/simplefoc/Arduino-FOC/workflows/MinimalBuild/badge.svg?branch=minimal)

examples/hardware_specific_examples/Bluepill_examples/encoder/bluepill_position_control/bluepill_position_control.ino

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
*/
88
#include <SimpleFOC.h>
99

10-
// motor instance
11-
BLDCMotor motor = BLDCMotor(PB6, PB7, PB8, 11, PB5);
10+
// Motor instance
11+
BLDCMotor motor = BLDCMotor(11);
12+
// BLDCDriver3PWM(IN1, IN2, IN3, enable(optional))
13+
BLDCDriver3PWM driver = BLDCDriver3PWM(PB6, PB7, PB8, PB5);
14+
// BLDCDriver6PWM(IN1_H, IN1_L, IN2_H, IN2_L, IN3_H, IN3_L, enable(optional))
15+
//BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15, PB12);
1216

1317
// encoder instance
1418
Encoder encoder = Encoder(PA8, PA9, 8192, PA10);
@@ -24,12 +28,16 @@ void setup() {
2428
// initialize encoder sensor hardware
2529
encoder.init();
2630
encoder.enableInterrupts(doA, doB, doI);
27-
2831
// link the motor to the sensor
2932
motor.linkSensor(&encoder);
3033

34+
// driver config
3135
// power supply voltage [V]
32-
motor.voltage_power_supply = 12;
36+
driver.voltage_power_supply = 12;
37+
driver.init();
38+
// link the motor and the driver
39+
motor.linkDriver(&driver);
40+
3341
// aligning voltage [V]
3442
motor.voltage_sensor_align = 3;
3543
// index search velocity [rad/s]

examples/hardware_specific_examples/Bluepill_examples/magnetic_sensor/bluepill_position_control/bluepill_position_control.ino

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ MagneticSensorSPI sensor = MagneticSensorSPI(PA4, 14, 0x3FFF);
2020
//MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
2121

2222
// Motor instance
23-
BLDCMotor motor = BLDCMotor(PA3, PA2, PA1, 11, PA0);
23+
BLDCMotor motor = BLDCMotor(11);
24+
// BLDCDriver3PWM(IN1, IN2, IN3, enable(optional))
25+
BLDCDriver3PWM driver = BLDCDriver3PWM(PB6, PB7, PB8, PB5);
26+
// BLDCDriver6PWM(IN1_H, IN1_L, IN2_H, IN2_L, IN3_H, IN3_L, enable(optional))
27+
//BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PB13, PA9, PB14, PA10, PB15, PB12);
2428

2529
void setup() {
2630

@@ -29,9 +33,12 @@ void setup() {
2933
// link the motor to the sensor
3034
motor.linkSensor(&sensor);
3135

32-
// power supply voltage
33-
// default 12V
34-
motor.voltage_power_supply = 12;
36+
// driver config
37+
// power supply voltage [V]
38+
driver.voltage_power_supply = 12;
39+
driver.init();
40+
// link the motor and the driver
41+
motor.linkDriver(&driver);
3542

3643
// choose FOC modulation (optional)
3744
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
#define INH_A 9
1919
#define INH_B 10
2020
#define INH_C 11
21+
2122
#define EN_GATE 7
2223
#define M_PWM A1
2324
#define M_OC A2
2425
#define OC_ADJ A3
2526

26-
// motor instance
27-
BLDCMotor motor = BLDCMotor(INH_A, INH_B, INH_C, 11, EN_GATE);
27+
// Motor instance
28+
BLDCMotor motor = BLDCMotor(11);
29+
BLDCDriver3PWM driver = BLDCDriver3PWM(INH_A, INH_B, INH_C, EN_GATE);
2830

2931
// encoder instance
3032
Encoder encoder = Encoder(2, 3, 8192);
@@ -54,11 +56,17 @@ void setup() {
5456
pinMode(OC_ADJ,OUTPUT);
5557
digitalWrite(OC_ADJ,HIGH);
5658

57-
// choose FOC modulation
58-
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
5959

60+
// driver config
6061
// power supply voltage [V]
61-
motor.voltage_power_supply = 12;
62+
driver.voltage_power_supply = 12;
63+
driver.init();
64+
// link the motor and the driver
65+
motor.linkDriver(&driver);
66+
67+
68+
// choose FOC modulation
69+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
6270

6371
// set control loop type to be used
6472
motor.controller = ControlType::voltage;

0 commit comments

Comments
 (0)