Skip to content

Commit 0c28772

Browse files
committed
Merge branch 'dev'
2 parents dcfbb77 + 7e5df4e commit 0c28772

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

README.md

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

3+
34
![Library Compile](https://github.com/askuric/Arduino-FOC/workflows/Library%20Compile/badge.svg)
45
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
56
[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
@@ -95,6 +96,78 @@ For those willing to experiment and to modify the code I suggest using the [mini
9596
```
9697
- Then you just open it with the Arduino IDE and run it.
9798

99+
## Arduino code example
100+
This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder.
101+
102+
NOTE: This program uses all the default control parameters.
103+
104+
```cpp
105+
#include <SimpleFOC.h>
106+
107+
// BLDCMotor( pin_pwmA, pin_pwmB, pin_pwmC, pole_pairs, enable (optional))
108+
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
109+
// Encoder(pin_A, pin_B, CPR)
110+
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 2048);
111+
// channel A and B callbacks
112+
void doA(){encoder.handleA();}
113+
void doB(){encoder.handleB();}
114+
115+
116+
void setup() {
117+
// initialize encoder hardware
118+
encoder.init();
119+
// hardware interrupt enable
120+
encoder.enableInterrupts(doA, doB);
121+
122+
// set control loop type to be used
123+
motor.controller = ControlType::velocity;
124+
125+
// use debugging with the BLDCMotor
126+
// debugging port
127+
motor.useDebugging(Serial);
128+
129+
// link the motor to the sensor
130+
motor.linkSensor(&encoder);
131+
132+
// initialize motor
133+
motor.init();
134+
// align encoder and start FOC
135+
motor.initFOC();
136+
}
137+
138+
void loop() {
139+
// FOC algorithm function
140+
motor.loopFOC();
141+
142+
// velocity control loop function
143+
// setting the target velocity or 2rad/s
144+
motor.move(2);
145+
146+
// debugging function outputting motor variables to the serial terminal
147+
motor.monitor();
148+
}
149+
```
150+
You can find more details in the [SimpleFOC documentation](https://askuric.github.io/Arduino-FOC/).
151+
152+
## Example projects
153+
Here are some of the SimpleFOC application examples.
154+
### Arduino Field Oriented Controlled Reaction Wheel Inverted Pendulum
155+
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).
156+
<p align="">
157+
<a href="https://youtu.be/Ih-izQyXJCI">
158+
<img src="https://askuric.github.io/Arduino-FOC/extras/Images/youtube_pendulum.png" height="350px">
159+
</a>
160+
</p>
161+
162+
**The main benefits of using the BLDC motor in this project are:**
163+
- High torque to weight ratio
164+
- The lighter the better
165+
- Lots of torque for low angular velocities
166+
- No need to spin the motor to very high PRM to achieve high torques
167+
- No gearboxes and backlash
168+
- Very smooth operation = very stable pendulum
169+
170+
98171
## Documentation
99172
Find out more information about the Arduino SimpleFOC project in [docs website](https://askuric.github.io/Arduino-FOC/)
100173

0 commit comments

Comments
 (0)