Skip to content

Commit b4a72da

Browse files
committed
FEAT Library version 1.3.0
1 parent fe32107 commit b4a72da

File tree

21 files changed

+413
-77
lines changed

21 files changed

+413
-77
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,36 @@
77

88
Proper low-cost and low-power FOC supporting boards are very hard to find these days and even may not exist. Even harder to find is a stable and simple FOC algorithm code capable of running on Arduino devices.
99
Therefore this is an attempt to:
10-
- Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino SimpleFOC library](https://askuric.github.io/Arduino-FOC/arduino_simplefoc_library_showcase)
11-
- Develop a modular BLDC driver board: [Arduino SimpleFOC shield](https://askuric.github.io/Arduino-FOC/arduino_simplefoc_shield_showcase).
10+
- Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino SimpleFOC library](https://docs.simplefoc.com/arduino_simplefoc_library_showcase)
11+
- Develop a modular BLDC driver board: [Arduino SimpleFOC shield](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase).
1212

1313
## Arduino SimpleFOCShield
1414

1515
<p align="">
1616
<a href="https://youtu.be/G5pbo0C6ujE">
17-
<img src="https://askuric.github.io/Arduino-FOC/extras/Images/foc_shield_video.jpg" height="320px">
17+
<img src="https://docs.simplefoc.com/extras/Images/foc_shield_video.jpg" height="320px">
1818
</a>
1919
</p>
2020

2121
### Features
2222
- **Plug & play**: In combination with Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span>
23-
- **Low-cost**: Price of €20 - [Check the pricing](https://askuric.github.io/simplefoc_shield_product)
24-
- **Open Source**: Fully available fabrication files - [how to make it yourself](https://askuric.github.io/Arduino-FOC/arduino_simplefoc_shield_fabrication)
23+
- **Low-cost**: Price of €20 - [Check the pricing](https://www.simplefoc.com/simplefoc_shield_product)
24+
- **Open Source**: Fully available fabrication files - [how to make it yourself](https://docs.simplefoc.com/arduino_simplefoc_shield_fabrication)
2525
- **Stackable**: running 2 motors in the same time
2626
- **Encoder interface**: Integrated 3kOhm pullups (configurable)
2727
- **Configurable pinout**: Hardware configuration - soldering connections
28+
- **Arduino headers**: Arduino UNO, Arduino MEGA, STM32 Nucleo boards...
2829

29-
##### If you are interested in this board, preorder your version on this link: [Arduino Simple FOC Shield](https://askuric.github.io/simplefoc_shield_product)
30+
##### If you are interested in this board, order your version on this link: [Arduino Simple FOC Shield](https://www.simplefoc.com/simplefoc_shield_product)
3031

31-
<p align=""><img src="https://askuric.github.io/Arduino-FOC/extras/Images/shield_to_v13.jpg" height="180px"> <img src="https://askuric.github.io/Arduino-FOC/extras/Images/shield_bo_v13.jpg" height="180px"> <img src="https://askuric.github.io/Arduino-FOC/extras/Images/simple_foc_shield_v13_small.gif" height="180x"></p>
32+
<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>
3233

3334

3435
## Arduino SimpleFOClibrary
3536

3637
<p align="">
3738
<a href="https://youtu.be/Y5kLeqTc6Zk">
38-
<img src="https://askuric.github.io/Arduino-FOC/extras/Images/youtube.png" height="320px">
39+
<img src="https://docs.simplefoc.com/extras/Images/youtube.png" height="320px">
3940
</a>
4041
</p>
4142

@@ -45,19 +46,23 @@ This video demonstrates the Simple FOC library basic usage, electronic connectio
4546
- **Arduino compatible**: Arduino library code
4647
- **Easy to setup and configure**:
4748
- Easy hardware configuration
48-
- Easy [tuning the control loops](https://askuric.github.io/Arduino-FOC/control_loops)
49+
- Easy [tuning the control loops](https://docs.simplefoc.com/control_loops)
4950
- **Modular**:
50-
- Supports as many [sensors , BLDC motors and driver boards](https://askuric.github.io/Arduino-FOC/supported_hardware) as possible
51+
- Supports as many [sensors , BLDC motors and driver boards](https://docs.simplefoc.com/supported_hardware) as possible
5152
- Supports as many application requirements as possible
52-
- **Plug & play**: Arduino SimpleFOC shield
53+
- Supports multiple [MCU architectures](https://docs.simplefoc.com/microcontrollers):
54+
- Arduino: UNO, MEGA, any board with ATMega328 chips
55+
- STM32 boards: [Nucleo](https://www.st.com/en/evaluation-tools/stm32-nucleo-boards.html) and [Bluepill](https://stm32-base.org/boards/STM32F103C8T6-Blue-Pill.html)
56+
- ESP32 (very soon)
57+
- **Plug & play**: Arduino *SimpleFOCShield*
5358

54-
<p align=""> <img src="https://askuric.github.io/Arduino-FOC/extras/Images/uno_l6234.jpg" height="170px"> <img src="https://askuric.github.io/Arduino-FOC/extras/Images/hmbgc_v22.jpg" height="170px"> <img src="https://askuric.github.io/Arduino-FOC/extras/Images/foc_shield_v13.jpg" height="170px"></p>
59+
<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>
5560

5661
## Getting Started
5762
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.
5863

59-
- Full library installation [Docs](https://askuric.github.io/Arduino-FOC/library_download)
60-
- Minimal code installation [Docs](https://askuric.github.io/Arduino-FOC/minimal_download)
64+
- Full library installation [Docs](https://docs.simplefoc.com/library_download)
65+
- Minimal code installation [Docs](https://docs.simplefoc.com/minimal_download)
6166

6267
### Arduino SimpleFOC library installation to Arduino IDE
6368
#### Arduino Library Manager
@@ -109,7 +114,7 @@ NOTE: This program uses all the default control parameters.
109114
// BLDCMotor( pin_pwmA, pin_pwmB, pin_pwmC, pole_pairs, enable (optional))
110115
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
111116
// Encoder(pin_A, pin_B, CPR)
112-
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 2048);
117+
Encoder encoder = Encoder(2, 3, 2048);
113118
// channel A and B callbacks
114119
void doA(){encoder.handleA();}
115120
void doB(){encoder.handleB();}
@@ -150,15 +155,15 @@ void loop() {
150155
motor.monitor();
151156
}
152157
```
153-
You can find more details in the [SimpleFOC documentation](https://askuric.github.io/Arduino-FOC/).
158+
You can find more details in the [SimpleFOC documentation](https://docs.simplefoc.com/).
154159

155160
## Example projects
156161
Here are some of the SimpleFOC application examples.
157162
### Arduino Field Oriented Controlled Reaction Wheel Inverted Pendulum
158163
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).
159164
<p align="">
160165
<a href="https://youtu.be/Ih-izQyXJCI">
161-
<img src="https://askuric.github.io/Arduino-FOC/extras/Images/youtube_pendulum.png" height="320px">
166+
<img src="https://docs.simplefoc.com/extras/Images/youtube_pendulum.png" height="320px">
162167
</a>
163168
</p>
164169

@@ -172,7 +177,7 @@ This is a very cool open-source project of one of the simplest setups of the Rea
172177

173178

174179
## Documentation
175-
Find out more information about the Arduino SimpleFOC project in [docs website](https://askuric.github.io/Arduino-FOC/)
180+
Find out more information about the Arduino SimpleFOC project in [docs website](https://docs.simplefoc.com/)
176181

177182

178183
## Arduino FOC repo structure

examples/encoder_examples/bluepill_example/bluepill_example.ino renamed to examples/hardware_specific_examples/Bluepill_examples/encoder/bluepill_position_control/bluepill_position_control.ino

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
*
77
*/
88
#include <SimpleFOC.h>
9-
// software interrupt library
10-
#include <PciManager.h>
11-
#include <PciListenerImp.h>
129

1310
// motor instance
1411
BLDCMotor motor = BLDCMotor(PB6, PB7, PB8, 11, PB5);

examples/magnetic_sensor_examples/bluepill_example/bluepill_example.ino renamed to examples/hardware_specific_examples/Bluepill_examples/magnetic_sensor/bluepill_position_control/bluepill_position_control.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void setup() {
4949
// angle P controller
5050
motor.P_angle.P = 20;
5151
// maximal velocity of the position control
52-
motor.P_angle.velocity_limit = 4;
52+
motor.P_angle.velocity_limit = 40;
5353

5454
// use debugging with serial
5555
Serial.begin(115200);

examples/encoder_examples/HMBGC_example/HMBGC_example.ino renamed to examples/hardware_specific_examples/HMBGC_example/position_control/position_control.ino

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
*
33
* HMBGC position motion control example with encoder
44
*
5-
* This board doesn't have any interrupt pins so we need to run all the encoder channels wiht the software interrupt library PciManager
5+
* - Motor is connected the MOT1 connector (MOT1 9,10,11; MOT2 3,5,6)
6+
* - Encoder is connected to A0 and A1
7+
*
8+
* This board doesn't have any interrupt pins so we need to run all the encoder channels with the software interrupt library
9+
* - For this example we use: PciManager library : https://github.com/prampec/arduino-pcimanager
10+
*
11+
* See docs.simplefoc.com for more info.
612
*
713
*/
814
#include <SimpleFOC.h>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
*
3+
* HMBGC torque control example using voltage control loop.
4+
*
5+
* - Motor is connected the MOT1 connector (MOT1 9,10,11; MOT2 3,5,6)
6+
* - Encoder is connected to A0 and A1
7+
*
8+
* Most of the low-end BLDC driver boards doesn't have current measurement therefore SimpleFOC offers
9+
* you a way to control motor torque by setting the voltage to the motor instead hte current.
10+
*
11+
* This makes the BLDC motor effectively a DC motor, and you can use it in a same way. position motion control example with encoder
12+
*
13+
* NOTE:
14+
* > HMBGC doesn't have any interrupt pins so we need to run all the encoder channels with the software interrupt library
15+
* > - For this example we use: PciManager library : https://github.com/prampec/arduino-pcimanager
16+
*
17+
* See docs.simplefoc.com for more info.
18+
*
19+
*/
20+
#include <SimpleFOC.h>
21+
// software interrupt library
22+
#include <PciManager.h>
23+
#include <PciListenerImp.h>
24+
25+
26+
// motor instance
27+
BLDCMotor motor = BLDCMotor(9, 10, 11, 11);
28+
29+
// encoder instance
30+
Encoder encoder = Encoder(A0, A1, 8192);
31+
32+
// Interrupt routine intialisation
33+
// channel A and B callbacks
34+
void doA(){encoder.handleA();}
35+
void doB(){encoder.handleB();}
36+
37+
// encoder interrupt init
38+
PciListenerImp listenerA(encoder.pinA, doA);
39+
PciListenerImp listenerB(encoder.pinB, doB);
40+
41+
void setup() {
42+
43+
// initialize encoder sensor hardware
44+
encoder.init();
45+
// interrupt initialization
46+
PciManager.registerListener(&listenerA);
47+
PciManager.registerListener(&listenerB);
48+
// link the motor to the sensor
49+
motor.linkSensor(&encoder);
50+
51+
// power supply voltage
52+
// default 12V
53+
motor.voltage_power_supply = 12;
54+
55+
// choose FOC modulation (optional)
56+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
57+
58+
// set motion control loop to be used
59+
motor.controller = ControlType::voltage;
60+
61+
// use debugging with serial for motor init
62+
// comment out if not needed
63+
motor.useDebugging(Serial);
64+
65+
// use debugging with serial
66+
Serial.begin(115200);
67+
// comment out if not needed
68+
motor.useDebugging(Serial);
69+
70+
// initialize motor
71+
motor.init();
72+
// align sensor and start FOC
73+
motor.initFOC();
74+
75+
Serial.println("Motor ready.");
76+
Serial.println("Set the target voltage using serial terminal:");
77+
_delay(1000);
78+
}
79+
80+
// target voltage to be set to the motor
81+
float target_voltage = 2;
82+
83+
void loop() {
84+
85+
// main FOC algorithm function
86+
// the faster you run this function the better
87+
// Arduino UNO loop ~1kHz
88+
// Bluepill loop ~10kHz
89+
motor.loopFOC();
90+
91+
// Motion control function
92+
// velocity, position or voltage (defined in motor.controller)
93+
// this function can be run at much lower frequency than loopFOC() function
94+
// You can also use motor.move() and set the motor.target in the code
95+
motor.move(target_voltage);
96+
97+
// communicate with the user
98+
serialReceiveUserCommand();
99+
}
100+
101+
102+
// utility function enabling serial communication with the user to set the target values
103+
// this function can be implemented in serialEvent function as well
104+
void serialReceiveUserCommand() {
105+
106+
// a string to hold incoming data
107+
static String received_chars;
108+
109+
while (Serial.available()) {
110+
// get the new byte:
111+
char inChar = (char)Serial.read();
112+
// add it to the string buffer:
113+
received_chars += inChar;
114+
// end of user input
115+
if (inChar == '\n') {
116+
117+
// change the motor target
118+
target_voltage = received_chars.toFloat();
119+
Serial.print("Target voltage: ");
120+
Serial.println(target_voltage);
121+
122+
// reset the command buffer
123+
received_chars = "";
124+
}
125+
}
126+
}

examples/encoder_examples/angle_control/angle_control.ino renamed to examples/motion_control/position_motion_control/encoder/angle_control/angle_control.ino

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
/**
22
*
3-
* Angle motion control example
3+
* Position/angle motion control example
4+
* Steps:
5+
* 1) Configure the motor and encoder
6+
* 2) Run the code
7+
* 3) Set the target angle (in radians) from serial terminal
48
*
5-
* Arduino UNO example code for running velocity motion control using an encoder with index significantly
6-
* Since Arduino UNO doesn't have enough interrupt pins we have to use software interrupt library PciManager.
9+
*
10+
* NOTE :
11+
* > Arduino UNO example code for running velocity motion control using an encoder with index significantly
12+
* > Since Arduino UNO doesn't have enough interrupt pins we have to use software interrupt library PciManager.
713
*
8-
* If running this code with Nucleo or Bluepill or any other board which has more than 2 interrupt pins
9-
* you can supply doIndex directly to the encoder.enableInterrupts(doA,doB,doIndex) and avoid using PciManger
14+
* > If running this code with Nucleo or Bluepill or any other board which has more than 2 interrupt pins
15+
* > you can supply doIndex directly to the encoder.enableInterrupts(doA,doB,doIndex) and avoid using PciManger
16+
*
17+
* > If you don't want to use index pin initialize the encoder class without index pin number:
18+
* > For example:
19+
* > - Encoder encoder = Encoder(2, 3, 8192);
20+
* > and initialize interrupts like this:
21+
* > - encoder.enableInterrupts(doA,doB)
22+
*
23+
* Check the docs.simplefoc.com for more info about the possible encoder configuration.
1024
*
1125
*/
1226
#include <SimpleFOC.h>

examples/magnetic_sensor_examples/angle_control/angle_control.ino renamed to examples/motion_control/position_motion_control/magnetic_sensor/angle_control/angle_control.ino

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
*
3+
* Position/angle motion control example
4+
* Steps:
5+
* 1) Configure the motor and magnetic sensor
6+
* 2) Run the code
7+
* 3) Set the target angle (in radians) from serial terminal
8+
*
9+
*/
110
#include <SimpleFOC.h>
211

312
// Magnetic sensor instance
@@ -39,7 +48,7 @@ void setup() {
3948
// angle P controller
4049
motor.P_angle.P = 20;
4150
// maximal velocity of the position control
42-
motor.P_angle.velocity_limit = 4;
51+
motor.P_angle.velocity_limit = 20;
4352

4453
// use debugging with serial
4554
Serial.begin(115200);

examples/encoder_examples/voltage_control/voltage_control.ino renamed to examples/motion_control/torque_voltage_control/encoder/voltage_control/voltage_control.ino

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
*
3+
* Torque control example using voltage control loop.
4+
*
5+
* Most of the low-end BLDC driver boards doesn't have current measurement therefore SimpleFOC offers
6+
* you a way to control motor torque by setting the voltage to the motor instead hte current.
7+
*
8+
* This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
9+
*/
110
#include <SimpleFOC.h>
211

312
// motor instance

examples/magnetic_sensor_examples/voltage_control/voltage_control.ino renamed to examples/motion_control/torque_voltage_control/magnetic_sensor/voltage_control/voltage_control.ino

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Torque control example using voltage control loop.
3+
*
4+
* Most of the low-end BLDC driver boards doesn't have current measurement therefore SimpleFOC offers
5+
* you a way to control motor torque by setting the voltage to the motor instead hte current.
6+
*
7+
* This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
8+
*/
19
#include <SimpleFOC.h>
210

311
// Magnetic sensor instance

examples/encoder_examples/velocity_control/velocity_control.ino renamed to examples/motion_control/velocity_motion_control/encoder/velocity_control/velocity_control.ino

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
/**
22
*
33
* Velocity motion control example
4+
* Steps:
5+
* 1) Configure the motor and encoder
6+
* 2) Run the code
7+
* 3) Set the target velocity (in radians per second) from serial terminal
48
*
5-
* Arduino UNO example code for running velocity motion control using an encoder with index significantly
6-
* Since Arduino UNO doesn't have enough interrupt pins we have to use software interrupt library PciManager.
9+
*
10+
*
11+
* NOTE :
12+
* > Arduino UNO example code for running velocity motion control using an encoder with index significantly
13+
* > Since Arduino UNO doesn't have enough interrupt pins we have to use software interrupt library PciManager.
714
*
8-
* If running this code with Nucleo or Bluepill or any other board which has more than 2 interrupt pins
9-
* you can supply doIndex directly to the encoder.enableInterrupts(doA,doB,doIndex) and avoid using PciManger
15+
* > If running this code with Nucleo or Bluepill or any other board which has more than 2 interrupt pins
16+
* > you can supply doIndex directly to the encoder.enableInterrupts(doA,doB,doIndex) and avoid using PciManger
17+
*
18+
* > If you don't want to use index pin initialize the encoder class without index pin number:
19+
* > For example:
20+
* > - Encoder encoder = Encoder(2, 3, 8192);
21+
* > and initialize interrupts like this:
22+
* > - encoder.enableInterrupts(doA,doB)
23+
*
24+
* Check the docs.simplefoc.com for more info about the possible encoder configuration.
1025
*
1126
*/
1227
#include <SimpleFOC.h>

0 commit comments

Comments
 (0)