Skip to content

Commit 6c02b34

Browse files
committed
FEAT restrucutred hardware specific funcitons to separate files
1 parent 0d9156e commit 6c02b34

17 files changed

+285
-122
lines changed

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=Simple FOC
2-
version=1.6.1
3-
author=Antun Skuric <[email protected]>
4-
maintainer=Antun Skuric <[email protected]>
2+
version=1.7.0
3+
author=Simplefoc <[email protected]>
4+
maintainer=Simplefoc <[email protected]>
55
sentence=A library demistifying FOC for BLDC motors
66
paragraph=Simple library intended for hobby comunity to run the BLDC and Stepper motor using FOC algorithm. It is intended to support as many BLDC/Stepper motor+sensor+driver combinations as possible and in the same time maintain simplicity of usage. Library supports Arudino devices such as Arduino UNO, MEGA, NANO and similar, stm32 boards such as Nucleo and Bluepill, ESP32 and Teensy boards.
77
category=Device Control

src/BLDCMotor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#define BLDCMotor_h
88

99
#include "Arduino.h"
10-
#include "common/FOCMotor.h"
10+
#include "common/interfaces/FOCMotor.h"
11+
#include "common/interfaces/Sensor.h"
1112
#include "common/foc_utils.h"
1213
#include "common/hardware_utils.h"
13-
#include "common/Sensor.h"
1414
#include "common/defaults.h"
1515

1616
/**

src/Encoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "Arduino.h"
55
#include "common/foc_utils.h"
66
#include "common/hardware_utils.h"
7-
#include "common/Sensor.h"
7+
#include "common/interfaces/Sensor.h"
88

99

1010
/**

src/HallSensor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define HALL_SENSOR_LIB_H
33

44
#include "Arduino.h"
5+
#include "common/interfaces/Sensor.h"
56
#include "common/foc_utils.h"
67
#include "common/hardware_utils.h"
7-
#include "common/Sensor.h"
88

99

1010
class HallSensor: public Sensor{

src/MagneticSensorAnalog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#define MAGNETICSENSORANALOG_LIB_H
33

44
#include "Arduino.h"
5+
#include "common/interfaces/Sensor.h"
56
#include "common/foc_utils.h"
67
#include "common/hardware_utils.h"
7-
#include "common/Sensor.h"
88

99
/**
1010
* This sensor has been tested with AS5600 running in 'analog mode'. This is where output pin of AS6000 is connected to an analog pin on your microcontroller.

src/MagneticSensorI2C.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#include "Arduino.h"
55
#include <Wire.h>
6+
#include "common/interfaces/Sensor.h"
67
#include "common/foc_utils.h"
78
#include "common/hardware_utils.h"
8-
#include "common/Sensor.h"
99

1010
struct MagneticSensorI2CConfig_s {
1111
int chip_address;

src/MagneticSensorSPI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#include "Arduino.h"
55
#include <SPI.h>
6+
#include "common/interfaces/Sensor.h"
67
#include "common/foc_utils.h"
78
#include "common/hardware_utils.h"
8-
#include "common/Sensor.h"
99

1010
#define DEF_ANGLE_REGISTAR 0x3FFF
1111

src/StepperMotor.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ void StepperMotor::loopFOC() {
179179
// shaft angle
180180
shaft_angle = shaftAngle();
181181
// set the phase voltage - FOC heart function :)
182-
setPhaseVoltage(voltage_q, _electricalAngle(shaft_angle,pole_pairs));
182+
setPhaseVoltage(voltage_q, _electricalAngle(shaft_angle, pole_pairs));
183183
}
184184

185185
// Iterative function running outer loop of the FOC algorithm
@@ -241,10 +241,24 @@ void StepperMotor::setPhaseVoltage(float Uq, float angle_el) {
241241
// only necessary if using _sin and _cos - approximation functions
242242
angle_el = _normalizeAngle(angle_el + zero_electric_angle);
243243
// Inverse park transform
244-
Ualpha = -_sin(angle_el) * Uq; // -sin(angle) * Uq;
245-
Ubeta = _cos(angle_el) * Uq; // cos(angle) * Uq;
244+
Ualpha = -(_sin(angle_el)) * Uq; // -sin(angle) * Uq;
245+
Ubeta = (_cos(angle_el)) * Uq; // cos(angle) * Uq;
246+
// if (angle_el < _PI_2) {
247+
// Ualpha = 0;
248+
// Ubeta = Uq;
249+
// }else if (angle_el < _PI) {
250+
// Ualpha =- Uq;
251+
// Ubeta = 0;
252+
// }else if (angle_el < _3PI_2) {
253+
// Ualpha = 0;
254+
// Ubeta = -Uq;
255+
// }else{
256+
// Ualpha = Uq;
257+
// Ubeta = 0;
258+
// }
259+
246260
// set the voltages in hardware
247-
setPwm(Ualpha,Ubeta);
261+
setPwm(Ualpha, Ubeta);
248262
}
249263

250264

src/StepperMotor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
#define StepperMotor_h
88

99
#include "Arduino.h"
10-
#include "common/FOCMotor.h"
10+
#include "common/interfaces/FOCMotor.h"
11+
#include "common/interfaces/Sensor.h"
1112
#include "common/foc_utils.h"
1213
#include "common/hardware_utils.h"
13-
#include "common/Sensor.h"
1414
#include "common/defaults.h"
1515

1616
/**

src/common/hardware_utils.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
#ifndef HARDWARE_UTILS_H
22
#define HARDWARE_UTILS_H
33

4-
#include "Arduino.h"
54
#include "foc_utils.h"
65

7-
8-
#if defined(ESP_H) // if esp32 boards
9-
10-
#include "driver/mcpwm.h"
11-
#include "soc/mcpwm_reg.h"
12-
#include "soc/mcpwm_struct.h"
13-
14-
#endif
15-
166
/**
177
* High PWM frequency setting function
188
* - hardware specific

0 commit comments

Comments
 (0)