|
4 | 4 | [](https://opensource.org/licenses/MIT)
|
5 | 5 | [](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
|
6 | 6 |
|
7 |
| -This is the minimal Arduino example of the [Simple FOC](https://github.com/askuric/Arduino-FOC) arduino library intended for mostly for easier experimentation and modification! |
| 7 | +This is the repository of the [*SimpleFOClibrary*](https://github.com/askuric/Arduino-FOC) intended to be used to crete the projects with minimal code possible which is specific for certain **motor+sensor+driver** combination. |
8 | 8 |
|
9 |
| -### Minimal repository structure |
| 9 | +### Repository structure |
10 | 10 | ```shell
|
11 |
| -├───arduino_foc_minimal_encoder # Arduino minimal code for running a motor with Encoder |
12 |
| -│ |
13 |
| -└───arduino_foc_minimal_magnetic # Arduino minimal code for running a motor with magnetic sensor |
| 11 | +├─── library_source |
| 12 | +| | |
| 13 | +| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operation |
| 14 | +| ├─ FOCutils.cpp/h # Utility functions |
| 15 | +| ├─ defaults.h # Default configuration values |
| 16 | +│ ├─ Sensor.h # Abstract Sensor class that all the sensors implement |
| 17 | +│ │ |
| 18 | +│ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations |
| 19 | +│ ├─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors |
| 20 | +│ ├─ MagneticSensorI2C.cpp/h # class implementing I2C communication for Magnetic sensors |
| 21 | +│ ├─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors |
| 22 | +│ └─ HallSensor.cpp/h # class implementing Hall sensor |
| 23 | +| |
| 24 | +└─── minimal_project_examples |
| 25 | + ├─ arduino_foc_minimal_openloop # Arduino minimal code for running a motor in the open loop |
| 26 | + ├─ arduino_foc_minimal_encoder # Arduino minimal code for running a motor with Encoder |
| 27 | + ├─ arduino_foc_minimal_hall # Arduino minimal code for running a motor with Hall sensors |
| 28 | + ├─ arduino_foc_minimal_magnetic_i2c # Arduino minimal code for running a motor with I2C magnetic sensor |
| 29 | + └─ arduino_foc_minimal_magnetic_spi # Arduino minimal code for running a motor with SPI magnetic sensor |
14 | 30 | ```
|
15 | 31 |
|
16 |
| -Each of the examples will give you the opportunity to change the PI velocity parameters `P` and `I`, Low pass filter time constant `Tf`, change the control loop in real time and check the average loop execution time, all from the serial terminal. |
17 |
| - |
18 |
| -List of commands: |
19 |
| -- **P**: velocity PI controller P gain |
20 |
| -- **I**: velocity PI controller I gain |
21 |
| -- **L**: velocity PI controller voltage limit |
22 |
| -- **R**: velocity PI controller voltage ramp |
23 |
| -- **F**: velocity Low pass filter time constant |
24 |
| -- **K**: angle P controller P gain |
25 |
| -- **N**: angle P controller velocity limit |
26 |
| -- **C**: control loop |
27 |
| - - **0**: voltage |
28 |
| - - **1**: velocity |
29 |
| - - **2**: angle |
30 |
| -- **V**: get motor variables |
31 |
| - - **0**: currently set voltage |
32 |
| - - **1**: current velocity |
33 |
| - - **2**: current angle |
34 |
| - - **3**: current target value |
35 |
| - |
36 |
| - |
37 |
| -Find more information about the **motor commands** in the [docs.simplefoc.com](https://docs.simplefoc.com/communication) |
38 |
| - |
39 |
| -### Installation |
40 |
| -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. |
41 |
| - > This code is completely independent and you can run it as any other Arduino Sketch without the need for any libraries. |
| 32 | +# Creating your own minimal project |
| 33 | +First you need to download this repository to your computer. |
42 | 34 |
|
43 | 35 | #### Github website download
|
44 | 36 | - Make sure you are in [minimal branch](https://github.com/askuric/Arduino-FOC/tree/minimal)
|
45 | 37 | - Download the code by clicking on the `Clone or Download > Download ZIP`.
|
46 |
| -- Unzip it and open the sketch in Arduino IDE. |
| 38 | +- Unzip it |
47 | 39 |
|
48 | 40 | #### Using terminal
|
49 | 41 | - Open the terminal:
|
50 | 42 | ```sh
|
51 | 43 | cd *to you desired directory*
|
52 | 44 | git clone -b minimal https://github.com/askuric/Arduino-FOC.git
|
53 | 45 | ```
|
54 |
| -- Then you just open it with the Arduino IDE and run it. |
| 46 | + |
| 47 | +After this step you will be able to open the example projects directly with Arduino IDE. This code is completely independent and you can run it as any other Arduino Sketch without the need for any libraries. |
| 48 | + |
| 49 | +> **BEWARE** In some cases this minimal version of the code will produce conflicts with the *Simple FOC* library if it is installed through Arduino library manager. So you might need to uninstall the library to run minimal projects. |
| 50 | +
|
| 51 | +## BLDC motor support code |
| 52 | + |
| 53 | +In the `library_source` folder you will find all *SimpleFOClibrary* source files. From those files you will choose just the ones you need for your own project. |
| 54 | + |
| 55 | +In each Arduino project using the *SimpleFOClibrary* you will need to copy these six files into your project directory. |
| 56 | + |
| 57 | +```shell |
| 58 | +├─── my_arduino_project |
| 59 | +| ├─ my_arduino_project.ino |
| 60 | +| | |
| 61 | +| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operation |
| 62 | +| ├─ FOCutils.cpp/h # Utility functions |
| 63 | +| ├─ defaults.h # Default configuration values |
| 64 | + └─ Sensor.h # Abstract Sensor class that all the sensors implement |
| 65 | +``` |
| 66 | + |
| 67 | +And in your arduino code you need to add the include: |
| 68 | +```cpp |
| 69 | +#include "BLDCMotor.h" |
| 70 | +``` |
| 71 | + |
| 72 | +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_minimal_openloop.ino` project example. |
| 73 | + |
| 74 | +## Sensor support |
| 75 | +In order to support the different position sensors you will have to add their `*.cpp` and `*.h` files into the directory. All you need to do is copy the header files from the `library_source` directory. |
| 76 | + |
| 77 | + |
| 78 | +### Example: Encoder sensor |
| 79 | +For example if you wish to use encoder, your arduino project will have structure: |
| 80 | + |
| 81 | +```shell |
| 82 | +├─── my_arduino_project |
| 83 | +| ├─ my_arduino_project.ino |
| 84 | +| | |
| 85 | +| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operation |
| 86 | +| ├─ FOCutils.cpp/h # Utility functions |
| 87 | +│ ├─ defaults.h # Default configuration values |
| 88 | +│ ├─ Sensor.h # Abstract Sensor class that all the sensors implement |
| 89 | +│ | |
| 90 | + └─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations |
| 91 | +``` |
| 92 | +And your includes will be: |
| 93 | +```cpp |
| 94 | +#include "BLDCMotor.h" |
| 95 | +#include "Encoder.h" |
| 96 | +``` |
| 97 | +See `arduino_foc_minimal_encoder.ino`. |
| 98 | + |
| 99 | +### Example: SPI Magnetic sensor |
| 100 | +If you wish to use SPI magnetic sensor with your project, your folder structure will be: |
| 101 | + |
| 102 | +```shell |
| 103 | +├─── my_arduino_project |
| 104 | +| ├─ my_arduino_project.ino |
| 105 | +| | |
| 106 | +| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operation |
| 107 | +| ├─ FOCutils.cpp/h # Utility functions |
| 108 | +│ ├─ defaults.h # Default configuration values |
| 109 | +│ ├─ Sensor.h # Abstract Sensor class that all the sensors implement |
| 110 | +│ | |
| 111 | + └─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors |
| 112 | +``` |
| 113 | +And your includes will be: |
| 114 | +```cpp |
| 115 | +#include "BLDCMotor.h" |
| 116 | +#include "MagneticSensorSPI.h" |
| 117 | +``` |
| 118 | +See `arduino_foc_minimal_magnetic_spi.ino`. |
| 119 | + |
| 120 | + |
| 121 | +### Example: Analog magnetic sensor and encoder |
| 122 | +For example if you wish to use magnetic sensor with SPI communication, your arduino project will have structure: |
| 123 | + |
| 124 | +```shell |
| 125 | +├─── my_arduino_project |
| 126 | +| ├─ my_arduino_project.ino |
| 127 | +| | |
| 128 | +| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operation |
| 129 | +| ├─ FOCutils.cpp/h # Utility functions |
| 130 | +│ ├─ defaults.h # Default configuration values |
| 131 | +│ ├─ Sensor.h # Abstract Sensor class that all the sensors implement |
| 132 | +│ | |
| 133 | +│ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations |
| 134 | + └─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors |
| 135 | +``` |
| 136 | +And your includes will be: |
| 137 | +```cpp |
| 138 | +#include "BLDCMotor.h" |
| 139 | +#include "MagneticSensorAnalog.h" |
| 140 | +#include "Encoder.h" |
| 141 | +``` |
55 | 142 |
|
56 | 143 | ## Documentation
|
57 |
| -Find out more information about the Arduino SimpleFOC project in [docs website](https://askuric.github.io/Arduino-FOC/) |
| 144 | +Find out more information about the Arduino *SimpleFOCproject* in [docs website](https://docs.simplefoc.com/) |
58 | 145 |
|
59 | 146 |
|
60 | 147 | ## Arduino FOC repo structure
|
61 | 148 | Branch | Description | Status
|
62 | 149 | ------------ | ------------- | ------------
|
63 |
| -[master](https://github.com/askuric/Arduino-FOC) | Stable and tested library version |  |
64 |
| -[dev](https://github.com/askuric/Arduino-FOC/tree/dev) | Development library version |  |
65 |
| -[minimal](https://github.com/askuric/Arduino-FOC/tree/minimal) | Minimal Arduino example with integrated library |  |
| 150 | +[master](https://github.com/simplefoc/Arduino-FOC) | Stable and tested library version |  |
| 151 | +[dev](https://github.com/simplefoc/Arduino-FOC/tree/dev) | Development library version |  |
| 152 | +[minimal](https://github.com/simplefoc/Arduino-FOC/tree/minimal) | Minimal Arduino example with integrated library |  |
0 commit comments