Skip to content

Commit 4395c22

Browse files
committed
Merge remote-tracking branch 'simplefoc/dev' into dev
2 parents 9281dce + 2de948c commit 4395c22

File tree

42 files changed

+965
-654
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+965
-654
lines changed

README.md

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/simplefoc/arduino-foc/latest/dev)
1414
![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/simplefoc/arduino-foc/dev)
1515

16-
[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
16+
[![arduino-library-badge](https://ardubadge.simplefoc.com?lib=Simple%20FOC)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
17+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/askuric/library/Simple%20FOC.svg)](https://registry.platformio.org/libraries/askuric/Simple%20FOC)
1718
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1819
[![status](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d/status.svg)](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d)
1920

@@ -28,21 +29,27 @@ Therefore this is an attempt to:
2829
- For official driver boards see [<span class="simple">Simple<span class="foc">FOC</span>Boards</span>](https://docs.simplefoc.com/boards)
2930
- Many many more boards developed by the community members, see [<span class="simple">Simple<span class="foc">FOC</span>Community</span>](https://community.simplefoc.com/)
3031

31-
> NEW RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.3
32-
> - Teensy4
33-
> - support for low-side current sensing [#392](https://github.com/simplefoc/Arduino-FOC/pull/392)
34-
> - support for center aligned 6pwm and 3pwm (optional) [#392](https://github.com/simplefoc/Arduino-FOC/pull/392)
35-
> - stm32
36-
> - support for center aligned pwm (even across multiple timers and motors/drivers) [#374](https://github.com/simplefoc/Arduino-FOC/pull/374), [#388](https://github.com/simplefoc/Arduino-FOC/pull/388)
37-
> - support for DMA based low-side current sensing: [#383](https://github.com/simplefoc/Arduino-FOC/pull/383),[#378](https://github.com/simplefoc/Arduino-FOC/pull/378)
38-
> - support for f7 architecture [#388](https://github.com/simplefoc/Arduino-FOC/pull/388),[#394](https://github.com/simplefoc/Arduino-FOC/pull/394)
39-
> - KV rating calculation fix [#347](https://github.com/simplefoc/Arduino-FOC/pull/347)
40-
> - Much more performant Space Vector PWM calculation [#340](https://github.com/simplefoc/Arduino-FOC/pull/340)
41-
> - And much more:
42-
> - See the complete list of bugfixes and new features of v2.3.3 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/10?closed=1)
43-
44-
45-
## Arduino *SimpleFOClibrary* v2.3.3
32+
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.4
33+
> - ESP32 MCUs extended support [#414](https://github.com/simplefoc/Arduino-FOC/pull/414)
34+
> - Transition to the arduino-esp32 version v3.x (ESP-IDF v5.x) [#387](https://github.com/espressif/arduino-esp32/releases)
35+
> - New support for MCPWM driver
36+
> - New support for LEDC drivers - center-aligned PWM and 6PWM available
37+
> - Rewritten and simplified the fast ADC driver code (`adcRead`) - for low-side and inline current sensing.
38+
> - Stepper motors current sensing support [#421](https://github.com/simplefoc/Arduino-FOC/pull/421)
39+
> - Support for current sensing (low-side and inline) - [see in docs](https://docs.simplefoc.com/current_sense)
40+
> - Support for true FOC control - `foc_current` torque control - [see in docs](https://docs.simplefoc.com/motion_control)
41+
> - New current sense alignment procedure [#422](https://github.com/simplefoc/Arduino-FOC/pull/422) - [see in docs](https://docs.simplefoc.com/current_sense_align)
42+
> - Support for steppers
43+
> - Much more robust and reliable
44+
> - More verbose and informative
45+
> - Support for HallSensors without interrupts [#424](https://docs.simplefoc.com/https://github.com/simplefoc/Arduino-FOC/pull/424) - [see in docs](hall_sensors)
46+
> - Docs
47+
> - A short guide to debugging of common issues
48+
> - A short guide to the units in the library - [see in docs](https://docs.simplefoc.com/library_units)
49+
> - See the complete list of bugfixes and new features of v2.3.4 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/11)
50+
51+
52+
## Arduino *SimpleFOClibrary* v2.3.4
4653

4754
<p align="">
4855
<a href="https://youtu.be/Y5kLeqTc6Zk">
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
*
3+
* SimpleFOCMini motor control example
4+
*
5+
* For Arduino UNO or the other boards with the UNO headers
6+
* the most convenient way to use the board is to stack it to the pins:
7+
* - 12 - ENABLE
8+
* - 11 - IN1
9+
* - 10 - IN2
10+
* - 9 - IN3
11+
*
12+
*/
13+
#include <SimpleFOC.h>
14+
15+
16+
// BLDC motor & driver instance
17+
BLDCMotor motor = BLDCMotor(11);
18+
// BLDCDriver3PWM driver = BLDCDriver3PWM(11, 10, 9, 8); // mini v1.0
19+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 12); // mini v1.1
20+
21+
// instantiate the commander
22+
Commander command = Commander(Serial);
23+
void doMotor(char* cmd) { command.motor(&motor, cmd); }
24+
25+
void setup() {
26+
// use monitoring with serial
27+
Serial.begin(115200);
28+
// enable more verbose output for debugging
29+
// comment out if not needed
30+
SimpleFOCDebug::enable(&Serial);
31+
32+
// if SimpleFOCMini is stacked in arduino headers
33+
// on pins 12,11,10,9,8
34+
// pin 12 is used as ground
35+
pinMode(12,OUTPUT);
36+
pinMode(12,LOW);
37+
38+
// driver config
39+
// power supply voltage [V]
40+
driver.voltage_power_supply = 12;
41+
driver.init();
42+
// link the motor and the driver
43+
motor.linkDriver(&driver);
44+
45+
// aligning voltage [V]
46+
motor.voltage_sensor_align = 3;
47+
48+
// set motion control loop to be used
49+
motor.controller = MotionControlType::velocity_openloop;
50+
51+
// default voltage_power_supply
52+
motor.voltage_limit = 2; // Volts
53+
54+
// comment out if not needed
55+
motor.useMonitoring(Serial);
56+
57+
// initialize motor
58+
motor.init();
59+
// align encoder and start FOC
60+
motor.initFOC();
61+
62+
// add target command M
63+
command.add('M', doMotor, "motor");
64+
65+
Serial.println(F("Motor ready."));
66+
Serial.println(F("Set the target velocity using serial terminal:"));
67+
68+
motor.target = 1; //initial target velocity 1 rad/s
69+
Serial.println("Target velocity: 1 rad/s");
70+
Serial.println("Voltage limit 2V");
71+
_delay(1000);
72+
}
73+
74+
void loop() {
75+
// main FOC algorithm function
76+
// the faster you run this function the better
77+
// Arduino UNO loop ~1kHz
78+
// Bluepill loop ~10kHz
79+
motor.loopFOC();
80+
81+
// Motion control function
82+
// velocity, position or voltage (defined in motor.controller)
83+
// this function can be run at much lower frequency than loopFOC() function
84+
// You can also use motor.move() and set the motor.target in the code
85+
motor.move();
86+
87+
// function intended to be used with serial plotter to monitor motor variables
88+
// significantly slowing the execution down!!!!
89+
// motor.monitor();
90+
91+
// user communication
92+
command.run();
93+
}

examples/hardware_specific_examples/SimpleFOCShield/version_v3/single_full_control_example/single_full_control_example.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void doB(){encoder.handleB();}
1313

1414
// inline current sensor instance
1515
// ACS712-05B has the resolution of 0.185mV per Amp
16-
InlineCurrentSense current_sense = InlineCurrentSense(1.0f, 0.185f, A0, A2);
16+
InlineCurrentSense current_sense = InlineCurrentSense(185.0f, A0, A2);
1717

1818
// commander communication instance
1919
Commander command = Commander(Serial);

examples/motion_control/open_loop_motor_control/open_loop_position_example/open_loop_position_example.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ void setup() {
3636
// as a protection measure for the low-resistance motors
3737
// this value is fixed on startup
3838
driver.voltage_limit = 6;
39-
driver.init();
39+
if(!driver.init()){
40+
Serial.println("Driver init failed!");
41+
return;
42+
}
4043
// link the motor and the driver
4144
motor.linkDriver(&driver);
4245

@@ -52,7 +55,10 @@ void setup() {
5255
motor.controller = MotionControlType::angle_openloop;
5356

5457
// init motor hardware
55-
motor.init();
58+
if(!motor.init()){
59+
Serial.println("Motor init failed!");
60+
return;
61+
}
5662

5763
// add target command T
5864
command.add('T', doTarget, "target angle");

examples/motion_control/open_loop_motor_control/open_loop_velocity_example/open_loop_velocity_example.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ void setup() {
3636
// as a protection measure for the low-resistance motors
3737
// this value is fixed on startup
3838
driver.voltage_limit = 6;
39-
driver.init();
39+
if(!driver.init()){
40+
Serial.println("Driver init failed!");
41+
return;
42+
}
4043
// link the motor and the driver
4144
motor.linkDriver(&driver);
4245

@@ -50,7 +53,10 @@ void setup() {
5053
motor.controller = MotionControlType::velocity_openloop;
5154

5255
// init motor hardware
53-
motor.init();
56+
if(!motor.init()){
57+
Serial.println("Motor init failed!");
58+
return;
59+
}
5460

5561
// add target command T
5662
command.add('T', doTarget, "target velocity");

examples/utils/current_sense_test/inline_current_sense_test/inline_current_sense_test.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ void setup() {
1919
SimpleFOCDebug::enable(&Serial);
2020

2121
// initialise the current sensing
22-
current_sense.init();
22+
if(!current_sense.init()){
23+
Serial.println("Current sense init failed.");
24+
return;
25+
}
2326

2427
// for SimpleFOCShield v2.01/v2.0.2
2528
current_sense.gain_b *= -1;

examples/utils/driver_standalone_test/bldc_driver_3pwm_standalone/bldc_driver_3pwm_standalone.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ void setup() {
2323
driver.voltage_limit = 12;
2424

2525
// driver init
26-
driver.init();
26+
if (!driver.init()){
27+
Serial.println("Driver init failed!");
28+
return;
29+
}
2730

2831
// enable driver
2932
driver.enable();
30-
33+
Serial.println("Driver ready!");
3134
_delay(1000);
3235
}
3336

examples/utils/driver_standalone_test/bldc_driver_6pwm_standalone/bldc_driver_6pwm_standalone.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ void setup() {
2424
driver.dead_zone = 0.05f;
2525

2626
// driver init
27-
driver.init();
27+
if (!driver.init()){
28+
Serial.println("Driver init failed!");
29+
return;
30+
}
2831

2932
// enable driver
3033
driver.enable();
31-
34+
Serial.println("Driver ready!");
3235
_delay(1000);
3336
}
3437

examples/utils/driver_standalone_test/stepper_driver_2pwm_standalone/stepper_driver_2pwm_standalone.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ void setup() {
2929
driver.voltage_limit = 12;
3030

3131
// driver init
32-
driver.init();
32+
if (!driver.init()){
33+
Serial.println("Driver init failed!");
34+
return;
35+
}
3336

3437
// enable driver
3538
driver.enable();
36-
39+
Serial.println("Driver ready!");
3740
_delay(1000);
3841
}
3942

examples/utils/driver_standalone_test/stepper_driver_4pwm_standalone/stepper_driver_4pwm_standalone.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ void setup() {
2424
driver.voltage_limit = 12;
2525

2626
// driver init
27-
driver.init();
27+
if (!driver.init()){
28+
Serial.println("Driver init failed!");
29+
return;
30+
}
2831

2932
// enable driver
3033
driver.enable();
31-
34+
Serial.println("Driver ready!");
3235
_delay(1000);
3336
}
3437

examples/utils/sensor_test/hall_sensors/hall_sensor_example/hall_sensor_example.ino

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313
// - pp - pole pairs
1414
HallSensor sensor = HallSensor(2, 3, 4, 14);
1515

16-
// Interrupt routine intialisation
17-
// channel A and B callbacks
18-
void doA(){sensor.handleA();}
19-
void doB(){sensor.handleB();}
20-
void doC(){sensor.handleC();}
21-
22-
2316
void setup() {
2417
// monitoring port
2518
Serial.begin(115200);
@@ -29,8 +22,6 @@ void setup() {
2922

3023
// initialise encoder hardware
3124
sensor.init();
32-
// hardware interrupt enable
33-
sensor.enableInterrupts(doA, doB, doC);
3425

3526
Serial.println("Sensor ready");
3627
_delay(1000);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Hall sensor example code
3+
*
4+
* This is a code intended to test the hall sensors connections and to demonstrate the hall sensor setup.
5+
*
6+
*/
7+
8+
#include <SimpleFOC.h>
9+
10+
// Hall sensor instance
11+
// HallSensor(int hallA, int hallB , int cpr, int index)
12+
// - hallA, hallB, hallC - HallSensor A, B and C pins
13+
// - pp - pole pairs
14+
HallSensor sensor = HallSensor(2, 3, 4, 14);
15+
16+
// Interrupt routine intialisation
17+
// channel A and B callbacks
18+
void doA(){sensor.handleA();}
19+
void doB(){sensor.handleB();}
20+
void doC(){sensor.handleC();}
21+
22+
23+
void setup() {
24+
// monitoring port
25+
Serial.begin(115200);
26+
27+
// check if you need internal pullups
28+
sensor.pullup = Pullup::USE_EXTERN;
29+
30+
// initialise encoder hardware
31+
sensor.init();
32+
// hardware interrupt enable
33+
sensor.enableInterrupts(doA, doB, doC);
34+
35+
Serial.println("Sensor ready");
36+
_delay(1000);
37+
}
38+
39+
void loop() {
40+
// iterative function updating the sensor internal variables
41+
// it is usually called in motor.loopFOC()
42+
sensor.update();
43+
// display the angle and the angular velocity to the terminal
44+
Serial.print(sensor.getAngle());
45+
Serial.print("\t");
46+
Serial.println(sensor.getVelocity());
47+
delay(100);
48+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Simple FOC
2-
version=2.3.3
2+
version=2.3.4
33
author=Simplefoc <[email protected]>
44
maintainer=Simplefoc <[email protected]>
55
sentence=A library demistifying FOC for BLDC motors

src/BLDCMotor.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ void BLDCMotor::linkDriver(BLDCDriver* _driver) {
6363
}
6464

6565
// init hardware pins
66-
void BLDCMotor::init() {
66+
int BLDCMotor::init() {
6767
if (!driver || !driver->initialized) {
6868
motor_status = FOCMotorStatus::motor_init_failed;
6969
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
70-
return;
70+
return 0;
7171
}
7272
motor_status = FOCMotorStatus::motor_initializing;
7373
SIMPLEFOC_DEBUG("MOT: Init");
@@ -105,6 +105,7 @@ void BLDCMotor::init() {
105105
enable();
106106
_delay(500);
107107
motor_status = FOCMotorStatus::motor_uncalibrated;
108+
return 1;
108109
}
109110

110111

@@ -202,7 +203,7 @@ int BLDCMotor::alignCurrentSense() {
202203
SIMPLEFOC_DEBUG("MOT: Align current sense.");
203204

204205
// align current sense and the driver
205-
exit_flag = current_sense->driverAlign(voltage_sensor_align);
206+
exit_flag = current_sense->driverAlign(voltage_sensor_align, modulation_centered);
206207
if(!exit_flag){
207208
// error in current sense - phase either not measured or bad connection
208209
SIMPLEFOC_DEBUG("MOT: Align error!");

0 commit comments

Comments
 (0)