This is the branch of the SimpleFOClibrary repository intended to be used to simplify the creation of the projects with minimal code possible which is specific for certain motor+sensor+driver combination.
Library source code structure
├─── library_source
| |
| ├─── common # Contains all the common utility classes and functions
| | |
| | ├─ defaults.h # default motion control parameters
| | |
| | ├─ foc_utils.cpp./h # utility functions of the FOC algorithm
| | ├─ hardware_utils.cpp./h # all the hardware specific implementations are in these files
| | ├─ pid.cpp./h # class implementing PID controller
| | ├─ lowpass_filter.cpp./h # class implementing Low pass filter
| | |
| | ├─ FOCMotor.cpp./h # common class for all implemented motors
| | └─ Sensor./h # common class for all implemented sensors
| |
| ├─ BLDCMotor.cpp/h # BLDC motor handling class
| ├─ StepperMotor.cpp/h # Stepper motor handling class
│ │
│ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
│ ├─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
│ ├─ MagneticSensorI2C.cpp/h # class implementing I2C communication for Magnetic sensors
│ ├─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors
└─ HallSensor.cpp/h # class implementing Hall sensor
Minimal project examples provided for quick start:
├─── minimal_project_examples # Project examples
│ ├─ arduino_foc_bldc_openloop # BLDC motor + Open loop control
│ ├─ arduino_foc_bldc_encoder # BLDC motor + Encoder
│ ├─ arduino_foc_bldc_hall # BLDC motor + Hall sensors
│ ├─ arduino_foc_bldc_magnetic_i2c # BLDC motor + I2C magnetic sensor
│ ├─ arduino_foc_bldc_magnetic_spi # BLDC motor + SPI magnetic sensor
│ |
│ ├─ arduino_foc_stepper_openloop # Stepper motor + Open loop control
│ ├─ arduino_foc_stepper_encoder # Stepper motor + Encoder
└─ arduino_foc_stepper_magnetic_i2c # Stepper motor + I2C magnetic sensor
Creating your own minimal project version is very simple and is done in four steps:
- Step 0: Download minimal branch contents to your PC
- Step 1: Create your the arduino project
- Step 2: Add motor specific code
- Step 3: Add sensor specific code
- Make sure you are in minimal branch
- Download the code by clicking on the
Clone or Download > Download ZIP
. - Unzip it
- Open the terminal:
cd *to you desired directory* git clone -b minimal https://github.com/askuric/Arduino-FOC.git
Open a directory you want to use as your arduino project directory my_arduino_project
and create my_arduino_project.ino
file. After this you create src
folder in this directory and copy the folder named common
from the library_source
folder. Your project directory should now have structure:
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Contains all the common utility classes and functions
| | ├─ defaults.h # default motion control parameters
| | ├─ foc_utils.cpp./h # utility functions of the FOC algorithm
| | ├─ hardware_utils.cpp./h # all the hardware specific implementations are in these files
| | ├─ pid.cpp./h # class implementing PID controller
| | ├─ lowpass_filter.cpp./h # class implementing Low pass filter
| | ├─ FOCMotor.cpp./h # common class for all implemented motors
| | └─ Sensor./h # common class for all implemented sensors
If you wish to use the BLDC motor with your setup you will have to copy the BLDCMotor.cpp/h
from the library_source
folder, and if you wish to use the stepper motor make sure to copy the StepperMotor.cpp/h
files and place them to the src
folder
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Common utility classes and functions
| | |
| | └─ BLDCMotor.cpp/h # BLDC motor handling class
And in your Arduino code in the my_arduino_project.ino
file make sure to add the the include:
#include "src/BLDCMotor.h"
For stepper motors the procedure is equivalent:
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Common utility classes and functions
| | |
| | └─ StepperMotor.cpp/h # Stepper motor handling class
And the include:
#include "src/StepperMotor.h"
If you wish to run your motor in the open loop mode these are all the files that you will need. See the arduino_foc_bldc_openloop
and arduino_foc_stepper_openloop
project example.
In order to support the different position sensors you will have to copy their *.cpp
and *.h
into your src
directory. All you need to do is copy the header files from the library_source
directory.
For example if you wish to use BLDC motor and encoder as a sensor, your arduino project will have structure:
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Common utility classes and functions
| | |
| | ├─ BLDCMotor.cpp/h # BLDC motor handling class
| | └─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
And your includes will be:
#include "src/BLDCMotor.h"
#include "src/Encoder.h"
See arduino_foc_bldc_encoder
project example or arduino_foc_stepper_encoder
for stepper equivalent.
If you wish to use Stepper motor and SPI magnetic sensor in your project, your folder structure will be:
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Common utility classes and functions
| | |
| | ├─ StepperMotor.cpp/h # Stepper motor handling class
| | └─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
And your includes will be:
#include "src/StepperMotor.h"
#include "src/MagneticSensorSPI.h"
See arduino_foc_stepper_magnetic_spi
project example or arduino_foc_bldc_magnetic_spi
for BLDC motor equivalent.
For example if you wish to use magnetic sensor with SPI communication, your arduino project will have structure:
├─── my_arduino_project
| ├─ my_arduino_project.ino
| └─── src
| | ├─── common # Common utility classes and functions
| | |
| | ├─ BLDCMotor.cpp/h # BLDC motor handling class
| | ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
| | └─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors
And your includes will be:
#include "src/BLDCMotor.h"
#include "src/MagneticSensorAnalog.h"
#include "src/Encoder.h"
Find out more information about the Arduino SimpleFOClibrary and SimpleFOCproject in docs website
Branch | Description | Status |
---|---|---|
master | Stable and tested library version | |
dev | Development library version | |
minimal | Minimal Arduino example with integrated library |