You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
7
+
This is the branch of the [*SimpleFOClibrary*](https://github.com/askuric/Arduino-FOC)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.
8
8
9
9
### Repository structure
10
+
Library source code structure
10
11
```shell
11
12
├─── library_source
12
13
||
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
14
+
| ├─── common # Contains all the common utility classes and functions
15
+
|||
16
+
|| ├─ defaults.h # default motion control parameters
17
+
|||
18
+
|| ├─ foc_utils.cpp./h # utility functions of the FOC algorithm
19
+
|| ├─ hardware_utils.cpp./h # all the hardware specific implementations are in these files
20
+
|| ├─ pid.cpp./h # class implementing PID controller
21
+
|| ├─ lowpass_filter.cpp./h # class implementing Low pass filter
22
+
|||
23
+
|| ├─ FOCMotor.cpp./h # common class for all implemented motors
24
+
|| └─ Sensor./h # common class for all implemented sensors
25
+
||
26
+
| ├─ BLDCMotor.cpp/h # BLDC motor handling class
27
+
| ├─ StepperMotor.cpp/h # Stepper motor handling class
17
28
│ │
18
29
│ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
19
30
│ ├─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
20
31
│ ├─ MagneticSensorI2C.cpp/h # class implementing I2C communication for Magnetic sensors
21
32
│ ├─ 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
33
+
└─ HallSensor.cpp/h # class implementing Hall sensor
34
+
```
35
+
36
+
Minimal project examples provided for quick start:
37
+
```shell
38
+
├─── minimal_project_examples # Project examples
39
+
│ ├─ arduino_foc_bldc_openloop # BLDC motor + Open loop control
40
+
│ ├─ arduino_foc_bldc_encoder # BLDC motor + Encoder
41
+
│ ├─ arduino_foc_bldc_hall # BLDC motor + Hall sensors
42
+
│ ├─ arduino_foc_bldc_magnetic_i2c # BLDC motor + I2C magnetic sensor
43
+
│ ├─ arduino_foc_bldc_magnetic_spi # BLDC motor + SPI magnetic sensor
44
+
│ |
45
+
│ ├─ arduino_foc_stepper_openloop # Stepper motor + Open loop control
46
+
│ ├─ arduino_foc_stepper_encoder # Stepper motor + Encoder
47
+
└─ arduino_foc_stepper_magnetic_i2c # Stepper motor + I2C magnetic sensor
30
48
```
31
49
50
+
51
+
32
52
# Creating your own minimal project
33
-
First you need to download this repository to your computer.
34
53
54
+
Creating your own minimal project version is very simple and is done in four steps:
55
+
- Step 0: Download minimal branch contents to your PC
56
+
- Step 1: Create your the arduino project
57
+
- Step 2: Add motor specific code
58
+
- Step 3: Add sensor specific code
59
+
60
+
## Step 0. Download the code
35
61
#### Github website download
36
62
- Make sure you are in [minimal branch](https://github.com/askuric/Arduino-FOC/tree/minimal)
37
63
- Download the code by clicking on the `Clone or Download > Download ZIP`.
@@ -48,100 +74,119 @@ After this step you will be able to open the example projects directly with Ardu
48
74
49
75
> **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
76
51
-
## BLDC motor support code
77
+
## Step 1. Creating the Arduino project
52
78
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.
79
+
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:
56
80
57
81
```shell
58
82
├─── my_arduino_project
59
83
| ├─ 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
84
+
| └─── src
85
+
|| ├─── common # Contains all the common utility classes and functions
86
+
|| ├─ defaults.h # default motion control parameters
87
+
|| ├─ foc_utils.cpp./h # utility functions of the FOC algorithm
88
+
|| ├─ hardware_utils.cpp./h # all the hardware specific implementations are in these files
89
+
|| ├─ pid.cpp./h # class implementing PID controller
90
+
|| ├─ lowpass_filter.cpp./h # class implementing Low pass filter
91
+
|| ├─ FOCMotor.cpp./h # common class for all implemented motors
92
+
|| └─ Sensor./h # common class for all implemented sensors
65
93
```
66
94
67
-
And in your arduino code you need to add the include:
95
+
## Step 2. Add motor specific code
96
+
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
97
+
```shell
98
+
├─── my_arduino_project
99
+
| ├─ my_arduino_project.ino
100
+
| └─── src
101
+
|| ├─── common # Common utility classes and functions
102
+
|||
103
+
|| └─ BLDCMotor.cpp/h # BLDC motor handling class
104
+
```
105
+
And in your Arduino code in the `my_arduino_project.ino` file make sure to add the the include:
68
106
```cpp
69
-
#include"BLDCMotor.h"
107
+
#include"src/BLDCMotor.h"
70
108
```
109
+
For stepper motors the procedure is equivalent:
71
110
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.
111
+
```shell
112
+
├─── my_arduino_project
113
+
| ├─ my_arduino_project.ino
114
+
| └─── src
115
+
|| ├─── common # Common utility classes and functions
116
+
|||
117
+
|| └─ StepperMotor.cpp/h # Stepper motor handling class
118
+
```
119
+
And the include:
120
+
```cpp
121
+
#include"src/StepperMotor.h"
122
+
```
123
+
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.
73
124
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.
125
+
## Step 3. Add sensor specific code
126
+
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.
76
127
77
128
78
129
### Example: Encoder sensor
79
-
For example if you wish to use encoder, your arduino project will have structure:
80
-
130
+
For example if you wish to use BLDC motor and encoder as a sensor, your arduino project will have structure:
81
131
```shell
82
132
├─── my_arduino_project
83
133
| ├─ 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
134
+
| └─── src
135
+
|| ├─── common # Common utility classes and functions
136
+
|||
137
+
|| ├─ BLDCMotor.cpp/h # BLDC motor handling class
138
+
|| └─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
91
139
```
92
140
And your includes will be:
93
141
```cpp
94
-
#include"BLDCMotor.h"
95
-
#include"Encoder.h"
142
+
#include"src/BLDCMotor.h"
143
+
#include"src/Encoder.h"
96
144
```
97
-
See `arduino_foc_minimal_encoder.ino`.
145
+
See `arduino_foc_bldc_encoder` project example or `arduino_foc_stepper_encoder` for stepper equivalent.
98
146
99
147
### Example: SPI Magnetic sensor
100
-
If you wish to use SPI magnetic sensor with your project, your folder structure will be:
148
+
If you wish to use Stepper motor and SPI magnetic sensor in your project, your folder structure will be:
101
149
102
150
```shell
103
151
├─── my_arduino_project
104
152
| ├─ 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
153
+
| └─── src
154
+
|| ├─── common # Common utility classes and functions
155
+
|||
156
+
|| ├─ StepperMotor.cpp/h # Stepper motor handling class
157
+
|| └─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
112
158
```
113
159
And your includes will be:
114
160
```cpp
115
-
#include"BLDCMotor.h"
116
-
#include"MagneticSensorSPI.h"
161
+
#include"src/StepperMotor.h"
162
+
#include"src/MagneticSensorSPI.h"
117
163
```
118
-
See `arduino_foc_minimal_magnetic_spi.ino`.
164
+
See `arduino_foc_stepper_magnetic_spi` project example or `arduino_foc_bldc_magnetic_spi` for BLDC motor equivalent.
119
165
120
166
121
-
### Example: Analog magnetic sensor and encoder
167
+
### Example: Multiple sensors: analog magnetic sensor and encoder
122
168
For example if you wish to use magnetic sensor with SPI communication, your arduino project will have structure:
123
169
124
170
```shell
125
171
├─── my_arduino_project
126
172
| ├─ 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
173
+
| └─── src
174
+
|| ├─── common # Common utility classes and functions
175
+
|||
176
+
|| ├─ BLDCMotor.cpp/h # BLDC motor handling class
177
+
|| ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
178
+
|| └─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors
135
179
```
136
180
And your includes will be:
137
181
```cpp
138
-
#include"BLDCMotor.h"
139
-
#include"MagneticSensorAnalog.h"
140
-
#include"Encoder.h"
182
+
#include"src/BLDCMotor.h"
183
+
#include"src/MagneticSensorAnalog.h"
184
+
#include"src/Encoder.h"
141
185
```
142
186
187
+
143
188
## Documentation
144
-
Find out more information about the Arduino *SimpleFOCproject* in [docs website](https://docs.simplefoc.com/)
189
+
Find out more information about the Arduino *Simple**FOC**library* and *Simple**FOC**project* in [docs website](https://docs.simplefoc.com/)
0 commit comments