SimpleFOClibrary 2.4.0
Loading...
Searching...
No Matches
SimpleFOC.h
Go to the documentation of this file.
1/*!
2 * @file SimpleFOC.h
3 *
4 * @mainpage Simple Field Oriented Control BLDC motor control library
5 *
6 * @section intro_sec Introduction
7 *
8 * Proper low-cost and low-power FOC supporting boards are very hard to find these days and even may not exist.<br> Even harder to find is a stable and simple FOC algorithm code capable of running on Arduino devices. Therefore this is an attempt to:
9 * - Demystify FOC algorithm and make a robust but simple Arduino library: Arduino SimpleFOC library
10 * - Develop a modular BLDC driver board: Arduino SimpleFOC shield.
11 *
12 * @section features Features
13 * - Arduino compatible: Arduino library code
14 * - Easy to setup and configure:
15 * - Easy hardware configuration
16 * - Easy tuning the control loops
17 * - Modular:
18 * - Supports as many sensors , BLDC motors and driver boards as possible
19 * - Supports as many application requirements as possible
20 * - Plug & play: Arduino SimpleFOC shield
21 *
22 * @section dependencies Supported Hardware
23 * - Motors
24 * - BLDC motors
25 * - Stepper motors
26 * - Hybrid Stepper motors
27 * - Drivers
28 * - BLDC drivers
29 * - Gimbal drivers
30 * - Stepper drivers
31 * - Position sensors
32 * - Encoders
33 * - Magnetic sensors
34 * - Hall sensors
35 * - Microcontrollers
36 * - Arduino
37 * - STM32
38 * - ESP32
39 * - Teensy
40 * - many more ...
41 *
42 * @section getting_examples How to Use Examples
43 *
44 * 1. **Arduino IDE**: Go to `File > Examples > Simple FOC > [category] > [example]`
45 * 2. **PlatformIO**: Copy example code from the `examples/` directory
46 * 3. **GitHub**: Browse examples at https://github.com/simplefoc/Arduino-FOC/tree/master/examples
47 *
48 * Each example includes:
49 * - Detailed comments explaining the code
50 * - Hardware connection diagrams (where applicable)
51 * - Expected behavior description
52 * - Common troubleshooting tips
53 *
54 * @section example_code Example code
55 * @code
56#include <SimpleFOC.h>
57
58// BLDCMotor( pole_pairs )
59BLDCMotor motor = BLDCMotor(11);
60// BLDCDriver( pin_pwmA, pin_pwmB, pin_pwmC, enable (optional) )
61BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 8);
62// Encoder(pin_A, pin_B, CPR)
63Encoder encoder = Encoder(2, 3, 2048);
64// channel A and B callbacks
65void doA(){encoder.handleA();}
66void doB(){encoder.handleB();}
67
68
69void setup() {
70 // initialize encoder hardware
71 encoder.init();
72 // hardware interrupt enable
73 encoder.enableInterrupts(doA, doB);
74 // link the motor to the sensor
75 motor.linkSensor(&encoder);
76
77 // power supply voltage [V]
78 driver.voltage_power_supply = 12;
79 // initialise driver hardware
80 driver.init();
81 // link driver
82 motor.linkDriver(&driver);
83
84 // set control loop type to be used
85 motor.controller = MotionControlType::velocity;
86 // initialize motor
87 motor.init();
88
89 // align encoder and start FOC
90 motor.initFOC();
91}
92
93void loop() {
94 // FOC algorithm function
95 motor.loopFOC();
96
97 // velocity control loop function
98 // setting the target velocity or 2rad/s
99 motor.move(2);
100}
101 * @endcode
102 *
103 * @section license License
104 *
105 * MIT license, all text here must be included in any redistribution.
106 *
107 */
108
109#ifndef SIMPLEFOC_H
110#define SIMPLEFOC_H
111
112#include "BLDCMotor.h"
113#include "StepperMotor.h"
114#include "HybridStepperMotor.h"
115#include "sensors/Encoder.h"
120#include "sensors/HallSensor.h"
132
133#endif