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
The arduino library code is organized into the standard [Arduino library structure](https://github.com/arduino/Arduino/wiki/Library-Manager-FAQ).
15
-
The library contains main BLDC motor class `BLDCMotor` and three sensor classes `Encoder`, `MagneticSensorSPI` and `MagneticSensorI2C` implementing the `Sensor` interface. Furthermore it has `FOCutils` file with all the necessary utility functions and `defaults.h` with all the default configuration variables.
16
-
15
+
The library contains FOC implementation for two types of BLDC motors, standard three phase BLDC motor in the class `BLDCMotor` and 2 phase stepper motors `StepperMotor`. The library implements nu;erous position sensors and they are all placed in the `senors` directory as well as drivers which are in the `drivers` directory. Finally all the utility functions and classes are placed in the `common` folder.
17
16
## Arduino library source structure
18
17
```sh
19
18
| src
20
-
| ├─ SimpleFOC.h # SimpleFOC library include file
21
-
||
22
-
| ├─ BLDCMotor.cpp/h # BLDCMotor class implementing all the FOC operations
23
-
│ │
24
-
│ ├─ Sensor.h # Abstract Sensor class that all the sensors implement
25
-
│ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
26
-
│ ├─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
27
-
│ ├─ MagneticSensorI2C.cpp/h # class implementing I2C communication for Magnetic sensors
28
-
│ ├─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors
29
-
│ ├─ HallSensor.cpp/h # class implementing Hall sensor
30
-
||
31
-
| ├─ FOCutils.cpp/h # Utility functions
19
+
| ├─ SimpleFOC.h # Main include file
20
+
||
21
+
| ├─ BLDCMotor.cpp/h # BLDC motor handling class
22
+
| ├─ StepperMotor.cpp/h # Stepper motor handling class
32
23
||
33
-
└─ defaults.h # Default configuration values
24
+
│ ├─── common # Contains all the common utility classes and functions
25
+
| ├─── drivers # PWM setting and driver handling specific code
26
+
| ├─── sensors # Position sensor specific code
34
27
```
35
28
36
29
<blockquoteclass="info">For more info visit <ahref="http://source.simplefoc.com/"target="_blank"> full source code documentation <iclass="fa fa-external-link fa-sm"></i></a></blockquote>
- Communication interface with user in form of motor commands: `command()`
34
+
- FOC algorithm implementation
35
+
- Motion control implementation
36
+
37
+
### `StepperMotor.cpp/h`
38
+
BLDCMotor class implementation
39
+
- FOC algorithm implementation
40
+
- Motion control implementation
41
+
45
42
46
43
<blockquoteclass="info"><ahref="foc_implementation"><iclass="fa fa-copy"></i> FOC implementation details</a> - Documentation of the procedures and detailed explanations of the code implementing FOC algorithm
47
44
</blockquote>
@@ -51,9 +48,89 @@ BLDCMotor class implementation
51
48
<a href="commands_source"><i class="fa fa-copy"></i> Motor commands implementation </a> - Documentation of the motor commands functionality
52
49
</blockquote>
53
50
51
+
## Drivers
52
+
All the drivers that are supported in this library are placed in the drivers directory.
53
+
```sh
54
+
| ├─── drivers
55
+
|| ├─ BLDCDriver3PWM.cpp/h # Implementation of generic 3PWM bldc driver
56
+
|| ├─ BLDCDriver6PWM.cpp/h # Implementation of generic 6PWM bldc driver
57
+
|| ├─ StepperDriver2PWM.cpp/h # Implementation of generic 2PWM stepper driver
58
+
|| ├─ StepperDriver4PWM.cpp/h # Implementation of generic 4PWM stepper driver
59
+
|||
60
+
|| ├─ hardware_api.h # common mcu specific api handling pwm setting and configuration
61
+
|||
62
+
|| ├─── hardware_specific # mcu specific hadrware_api.h implementations
And all the stepper drivers implement the `StepperDriver` abstract class.
97
+
```cpp
98
+
classStepperDriver{
99
+
public:
100
+
101
+
/** Initialise hardware */
102
+
virtual int init();
103
+
/** Enable hardware */
104
+
virtual void enable();
105
+
/** Disable hardware */
106
+
virtual void disable();
107
+
108
+
long pwm_frequency; //!< pwm frequency value in hertz
109
+
float voltage_power_supply; //!< power supply voltage
110
+
float voltage_limit; //!< limiting voltage set to the motor
111
+
112
+
/**
113
+
* Set phase voltages to the harware
114
+
*
115
+
* @param Ua phase A voltage
116
+
* @param Ub phase B voltage
117
+
*/
118
+
virtual void setPwm(float Ua, float Ub);
119
+
};
120
+
```
121
+
122
+
Furthermore all the supported MCU architectures with the simplefoc library have to implement the header file `hardware_api.h`. The off-the-shelf supported architectures will have implementation of the `hardware_api.h` placed in the `hardware_specific` folder. If you wish to implement a new MCU please do create a new instance of the `my_new_mcu.cpp` and implement all the functions from the `hardware_api.h`, or at least the ones that you need.
123
+
## Sensors
54
124
55
-
### `Sensor.h`
56
-
Abstract sensor class that every sensor needs to implement in order to be connectable to the motor (`BLDCMotor` class).
125
+
```sh
126
+
| ├─── sensors
127
+
| │ ├─ Encoder.cpp/h # Encoder class implementing the Quadrature encoder operations
128
+
| │ ├─ MagneticSensorSPI.cpp/h # class implementing SPI communication for Magnetic sensors
129
+
| │ ├─ MagneticSensorI2C.cpp/h # class implementing I2C communication for Magnetic sensors
130
+
| │ ├─ MagneticSensorAnalog.cpp/h # class implementing Analog output for Magnetic sensors
131
+
└─ HallSensor.cpp/h # class implementing Hall sensor
132
+
```
133
+
All position sensor classes implemented in this library are placed in this directory, and all of them will be implementing abstract sensor class `Sensor`. Every sensor needs to implement the `Sensor` class in order to be linkable to the motor (`BLDCMotor` and `StepperMotor` class).
57
134
If you want to implement your own version of the sensor, jut extend this class and implement the virtual functions and you will be able to run the FOC algorithm with it.
58
135
You will be abele to link motor and the sensor by doing `motor.linkSensor(your sensor)`
59
136
```cpp
@@ -81,75 +158,24 @@ public:
81
158
}
82
159
```
83
160
84
-
### `Encoder.cpp/h`
85
-
Quadrature Encoder class implementation
86
-
- Extends `Sensor` class
87
-
- Encoder interrupt functions and configuration: `enableInterrupt()`, `handleA()`, `handleB()`, `handleIndex()`...
88
-
- Calculates motor angle and velocity ( using the [Mixed Time Frequency Method](https://github.com/askuric/Arduino-Mixed-Time-Frequency-Method)).
89
-
- Support any type of optical and magnetic encoder.
90
-
91
-
### `MagneticSensorSPI.cpp/h`
92
-
Absolute Magnetic sensor(encoder) class implementation
93
-
- Extends `Sensor` class
94
-
- SPI communication
95
-
- Calculates motor angle and velocity
96
-
- Supports magnetic position sensors such as AS5048A, AS5047 and similar.
97
-
98
-
### `MagneticSensorI2C.cpp/h`
99
-
Absolute Magnetic sensor(encoder) class implementation
100
-
- Extends `Sensor` class
101
-
- I2C communication
102
-
- Calculates motor angle and velocity
103
-
- Supports magnetic position sensors such as AS5048B, AS5600 and similar
104
-
105
-
### `MagneticSensorAnalog.cpp/h`
106
-
Absolute Magnetic sensor(encoder) class implementation
107
-
- Extends `Sensor` class
108
-
- Analog value reading
109
-
- Calculates motor angle and velocity
110
-
- Supports magnetic position sensors such as AS5047, AS5600 and similar
111
-
112
-
### `HallSensor.cpp/h`
113
-
Hall sensor class implementation
114
-
- Extends `Sensor` class
115
-
- Hall sensor interrupt functions and configuration: `enableInterrupt()`, `handleA()`, `handleB()`, `handleC()`...
116
-
- Calculates motor angle and velocity.
117
-
- Support any type of hall sensor - even magnetic sensor AS5047 (UVW interface).
118
-
119
-
120
-
### `FOCutils.cpp/h`
121
-
This is implementation of all the necessary hardware specific and FOC utility functions.
122
-
```cpp
123
-
// High PWM frequency setting function
124
-
// - hardware specific
125
-
// pinA,pinB,pinC hardware pin numbers
126
-
void _setPwmFrequency(int pinA, int pinB, int pinC);
127
-
128
-
// Function implementing delay() function in milliseconds
129
-
// - blocking function
130
-
// - hardware specific
131
-
void _delay(unsigned long ms);
132
-
133
-
//Function implementing timestamp getting function in microseconds
134
-
// hardware specific
135
-
unsigned long _micros();
136
-
137
-
//Function setting the duty cycle to the pwm pin (ex. analogWrite())
138
-
// hardware specific
139
-
// dc_a, dc_b, dc_c - duty cycle [0, 1]
140
-
// pinA,pinB,pinC - hardware pin number
141
-
void _writeDutyCycle(float dc_a, float dc_b, float dc_c, int pinA, int pinB, int pinC );
142
-
143
-
// Function approximating the sine calculation by using fixed size array
144
-
// - execution time ~40us (Arduino UNO)
145
-
float _sin(float a);
146
-
// Function approximating cosine calculation by using fixed size array
147
-
// - execution time ~50us (Arduino UNO)
148
-
float _cos(float a);
161
+
## Common
162
+
```sh
163
+
│ ├─── common # Contains all the common utility classes and functions
164
+
| | |
165
+
| | ├─ defaults.h # default motion control parameters
166
+
| | ├─ foc_utils.cpp./h # utility functions of the FOC algorithm
167
+
| | ├─ time_utils.cpp/h # utility functions for dealing with time measurements and delays
168
+
| | ├─ pid.cpp./h # class implementing PID controller
169
+
| | ├─ lowpass_filter.cpp./h # class implementing Low pass filter
170
+
| | |
171
+
| | ├─── base_classes
172
+
| | | ├─ FOCMotor.cpp./h # common class for all implemented motors
173
+
| | | ├─ BLDCDriver.h # common class for all BLDC drivers
174
+
| | | ├─ StepperDriver.h # common class for all Stepper drivers
175
+
| | | └─ Sensor./h # common class for all implemented sensors
176
+
| |
149
177
```
150
-
151
-
152
-
### `defaults.h`
178
+
The common directory contains all the definitions and common utility functions for the <spanclass="simple">Simple<spanclass="foc">FOC</span>library</span>. It contains the definitions of the abstract classes for motors, sensors and drivers in the `base_classes` directory. It has two libraries of utility functions for time management `time_utils.cpp/h` and FOC helpers `foc_utils.cpp/h`. Finally it has definition and implementation of the two signal processing classes: pid controller `pid.cpp/h` and low pass filter `lowpass_filter.cpp/h`. It also contains the default configuration parameters of the library in the `defaults.h` header file.
153
179
Header file containing all the default configuration variables
154
180
```cpp
155
181
// default configuration values
@@ -172,18 +198,6 @@ Header file containing all the default configuration variables
172
198
#defineDEF_VEL_FILTER_Tf 0.005 //!< default velocity filter time constant
0 commit comments