Skip to content

Commit c99dd26

Browse files
committed
Merge branch 'dev' of https://github.com/simplefoc/Arduino-FOC.git into dev
2 parents 7902e62 + ed90016 commit c99dd26

File tree

7 files changed

+44
-33
lines changed

7 files changed

+44
-33
lines changed

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,32 @@ Therefore this is an attempt to:
1616
- ***NEW*** 📢: *Medium-power* BLDC driver (<30Amps): [Arduino <span class="simple">Simple<b>FOC</b>PowerShield</span> ](https://github.com/simplefoc/Arduino-SimpleFOC-PowerShield).
1717
- See also [@byDagor](https://github.com/byDagor)'s *fully-integrated* ESP32 based board: [Dagor Brushless Controller](https://github.com/byDagor/Dagor-Brushless-Controller)
1818

19-
##### <b> Release notes:</b> <i>Simple<b>FOC</b>library</i> v2.2
20-
> - Sensor floating point error bugfux #83
21-
> - Support for portenta h7 board
22-
> - Support for arduino leonardo #108
23-
> - Support for esp8266
24-
> - Low side current sensing support for esp32
25-
> - Restructured the generic code and simplified adding new mcus
26-
> - Awesome :smiley: Low side current sening support for B_G431B_ESC1 by [@sDessens](https://github.com/sDessens): PR #73
19+
20+
<blockquote class="info">
21+
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.2 - <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.2">see release</a></p>
22+
<ul>
23+
<li>Sensor floating point error bugfix (initial solution) #83, #37</li>
24+
<li>Sensor class restructuring - <b>slight API change</b> - <a href="https://docs.simplefoc.com/sensors">docs</a></li>
25+
<li>Restructured the generic code and simplified adding new mcus: <b>IMPORTANT: an additional compiler flag needed for PlatformIO</b> see <a href="https://github.com/simplefoc/Arduino-FOC/issues/99">issue</a> and <a href="https://docs.simplefoc.com/library_platformio">PlatformIO docs</a></li>
26+
<li>Removed initial jump #110, #111</li>
27+
<li>Double to float transformation of the code - performance increase by <a href="https://github.com/sDessens">@sDessens</a> (#100), <a href="https://github.com/KaSroka">@KaSroka</a> (#100) </li>
28+
<li> <a href="https://docs.simplefoc.com/docs_chinese"><b>Docs webiste translated to Chinese!</b></a> 🎉: Awesome work 😃 by <a href="https://github.com/MINQING1101">@MINQING1101</a>, <a href="https://github.com/Deng-ge-open-source">@Deng-ge-open-source</a> and <a href="https://github.com/mingggggggg">@mingggggggg</a></li>
29+
<li>New MCU support - <a href="https://docs.simplefoc.com/microcontrollers">docs</a>
30+
<ul>
31+
<li>Support for arduino leonardo #108 </li>
32+
<li>Initial support for portenta h7 board in collaboration with <img src="https://docs.simplefoc.com/extras/Images/arduino.png" height="15px"><a href="https://www.arduino.cc/">Arduino</a></li>
33+
<li>Initial support for esp8266</li>
34+
</ul>
35+
</li>
36+
<li>Low side current sensing initial support - <a href="https://docs.simplefoc.com/current_sense">docs</a>
37+
<ul>
38+
<li>Initial support for stm32 B_G431B_ESC1 by <a href="https://github.com/sDessens">@sDessens</a>: PR #73</li>
39+
<li>Initial support for samd21 by <a href="https://github.com/maxlem">@maxlem</a>: PR #79</li>
40+
<li>Initial support for esp32 by <a href="https://github.com/maxlem">@byDagor</a></li>
41+
</ul>
42+
</li>
43+
</ul>
44+
</blockquote>
2745

2846
## Arduino *SimpleFOClibrary* v2.1
2947

examples/hardware_specific_examples/B_G431B_ESC1/B_G431B_ESC1.ino

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Motor instance
88
BLDCMotor motor = BLDCMotor(11);
99
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);
10-
InlineCurrentSense currentSense = InlineCurrentSense(0.003, -64.0/7.0, OP1_OUT, OP2_OUT, OP3_OUT);
10+
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, OP1_OUT, OP2_OUT, OP3_OUT);
1111

1212

1313
// encoder instance
@@ -43,6 +43,8 @@ void setup() {
4343

4444
// current sensing
4545
currentSense.init();
46+
// no need for aligning
47+
currentSense.skip_align = true;
4648
motor.linkCurrentSense(&currentSense);
4749

4850
// aligning voltage [V]
@@ -97,15 +99,8 @@ float target_angle = 0;
9799

98100
void loop() {
99101
// main FOC algorithm function
100-
// the faster you run this function the better
101-
// Arduino UNO loop ~1kHz
102-
// Bluepill loop ~10kHz
103-
motor.loopFOC();
104102

105103
// Motion control function
106-
// velocity, position or voltage (defined in motor.controller)
107-
// this function can be run at much lower frequency than loopFOC() function
108-
// You can also use motor.move() and set the motor.target in the code
109104
motor.move(target_angle);
110105

111106
// function intended to be used with serial plotter to monitor motor variables

src/common/base_classes/Sensor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ enum Pullup{
2828
* Encoders, Magnetic Encoders and Hall Sensor implementations. This base class extracts the
2929
* most basic common features so that a FOC driver can obtain the data it needs for operation.
3030
*
31-
* To implement your own sensors, create a sub-class of this class, and implement the getAngle()
32-
* method. getAngle() returns a float value, in radians, representing the current shaft angle in the
31+
* To implement your own sensors, create a sub-class of this class, and implement the getSensorAngle()
32+
* method. getSensorAngle() returns a float value, in radians, representing the current shaft angle in the
3333
* range 0 to 2*PI (one full turn).
3434
*
3535
* To function correctly, the sensor class update() method has to be called sufficiently quickly. Normally,

src/common/pid.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ float PIDController::operator() (float error){
2828
float proportional = P * error;
2929
// Tustin transform of the integral part
3030
// u_ik = u_ik_1 + I*Ts/2*(ek + ek_1)
31-
// method uses the antiwindup Foxboro method : https://core.ac.uk/download/pdf/289952713.pdf
3231
float integral = integral_prev + I*Ts*0.5f*(error + error_prev);
3332
// antiwindup - limit the output
3433
integral = _constrain(integral, -limit, limit);

src/current_sense/LowsideCurrentSense.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ int LowsideCurrentSense::driverSync(BLDCDriver *driver){
7575
// 3 - success but gains inverted
7676
// 4 - success but pins reconfigured and gains inverted
7777
int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
78-
//gain_a *= -1;
79-
//gain_b *= -1;
80-
//gain_c *= -1;
81-
82-
/*
78+
8379
int exit_flag = 1;
8480
if(skip_align) return exit_flag;
8581

@@ -90,9 +86,9 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
9086
// read the current 100 times ( arbitrary number )
9187
for (int i = 0; i < 100; i++) {
9288
PhaseCurrent_s c1 = getPhaseCurrents();
93-
c.a = c.a*0.6 + 0.4f*c1.a;
94-
c.b = c.b*0.6 + 0.4f*c1.b;
95-
c.c = c.c*0.6 + 0.4f*c1.c;
89+
c.a = c.a*0.6f + 0.4f*c1.a;
90+
c.b = c.b*0.6f + 0.4f*c1.b;
91+
c.c = c.c*0.6f + 0.4f*c1.c;
9692
_delay(3);
9793
}
9894
driver->setPwm(0, 0, 0);
@@ -165,7 +161,7 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
165161
// read the adc voltage 500 times ( arbitrary number )
166162
for (int i = 0; i < 50; i++) {
167163
PhaseCurrent_s c1 = getPhaseCurrents();
168-
c.c = (c.c+c1.c)/50.0;
164+
c.c = (c.c+c1.c)/50.0f;
169165
}
170166
driver->setPwm(0, 0, 0);
171167
gain_c *= _sign(c.c);
@@ -180,6 +176,4 @@ int LowsideCurrentSense::driverAlign(BLDCDriver *driver, float voltage){
180176
// 4 - success but pins reconfigured and gains inverted
181177

182178
return exit_flag;
183-
*/
184-
return 1;
185179
}

src/current_sense/hardware_api.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,4 @@ float _readADCVoltageLowSide(const int pinA);
4343
*/
4444
void _driverSyncLowSide();
4545

46-
47-
void _startADC3PinConversionLowSide();
48-
4946
#endif

src/current_sense/hardware_specific/stm32g4_mcu.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ float _readADCVoltageInline(const int pin){
3434

3535
return raw_adc * _ADC_CONV;
3636
}
37+
// do the same for low side sensing
38+
float _readADCVoltageLowSide(const int pin){
39+
return _readADCVoltageInline(pin);
40+
}
3741

3842
void _configureOPAMP(OPAMP_HandleTypeDef *hopamp, OPAMP_TypeDef *OPAMPx_Def){
3943
// could this be replaced with LL_OPAMP calls??
@@ -108,6 +112,10 @@ void _configureADCInline(const int pinA,const int pinB,const int pinC){
108112
Error_Handler();
109113
}
110114
}
115+
// do the same for low side
116+
void _configureADCLowSide(const int pinA,const int pinB,const int pinC){
117+
_configureADCInline(pinA, pinB, pinC);
118+
}
111119

112120
extern "C" {
113121
void DMA1_Channel1_IRQHandler(void) {

0 commit comments

Comments
 (0)