Skip to content

Commit ef9fe50

Browse files
authored
Merge branch 'dev' into autotuning
2 parents 26fbea0 + b5557db commit ef9fe50

File tree

105 files changed

+8306
-3444
lines changed

Some content is hidden

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

105 files changed

+8306
-3444
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Description
2+
3+
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any architectures/sensors/motors that the PR is targeting if appicable.
4+
5+
The best approach would be to create an issue and reference it in this pull request.
6+
Example:
7+
8+
Fixes # (issue)
9+
10+
## Type of change
11+
12+
Please delete options that are not relevant.
13+
14+
- [ ] Bug fix (non-breaking change which fixes an issue)
15+
- [ ] New feature (non-breaking change which adds functionality)
16+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
17+
- [ ] This change requires a documentation update
18+
19+
# How Has This Been Tested?
20+
21+
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
22+
23+
**Test Configuration/Setup**:
24+
* Hardware:
25+
* IDE: Arduino/Platformio
26+
* MCU package version (stm32duino/arduino-esp32/..)
27+
28+
# **IMPORTANT** when opening the pull request
29+
30+
* Your pull request MUST target the `dev` branch on this repository. By default you'll probably target `master`, make sure to change it.

.github/workflows/arduino.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ jobs:
2525
- arduino-boards-fqbn: arduino:avr:uno # arudino uno - compiling almost all examples
2626
sketch-names: '**.ino'
2727
required-libraries: PciManager
28-
sketches-exclude: teensy4_current_control_low_side, full_control_serial, angle_control, bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm, osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control,esp32_current_control_low_side, stm32_spi_alt_example, esp32_spi_alt_example, B_G431B_ESC1, odrive_example_spi, odrive_example_encoder, single_full_control_example, double_full_control_example, stm32_current_control_low_side, open_loop_velocity_6pwm
28+
sketches-exclude: align_current_sense, measure_inductance_and_resistance,
29+
teensy4_current_control_low_side, full_control_serial, angle_control,
30+
bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example,
31+
stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm,
32+
osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control,
33+
esp32_current_control_low_side, stm32_spi_alt_example, esp32_spi_alt_example,
34+
B_G431B_ESC1, odrive_example_spi, odrive_example_encoder, single_full_control_example,
35+
double_full_control_example, stm32_current_control_low_side, open_loop_velocity_6pwm,
36+
efr32_hall_sensor_velocity_6pwm, efr32_open_loop_velocity_6pwm, efr32_torque_velocity_6pwm
2937

3038
- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
3139
sketch-names: single_full_control_example.ino

.github/workflows/arduino_mbed.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: MDED
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: arduino/arduino-lint-action@v1
9+
with:
10+
library-manager: update
11+
project-type: library
12+
build:
13+
name: Test compiling
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
arduino-boards-fqbn:
19+
#- arduino:mbed:giga # arudino giga
20+
- arduino:mbed:nanorp2040connect # arduino nano rp2040 connect
21+
- arduino:mbed:nano33ble # arduino nano 33 ble
22+
- arduino:mbed:envie_m7 # arduino portenta
23+
24+
include:
25+
- arduino-boards-fqbn: arduino:mbed:nanorp2040connect
26+
sketch-names: open_loop_position_example.ino
27+
28+
- arduino-boards-fqbn: arduino:mbed:nano33ble
29+
sketch-names: open_loop_position_example.ino
30+
31+
- arduino-boards-fqbn: arduino:mbed:envie_m7
32+
sketch-names: open_loop_position_example.ino
33+
34+
# - arduino-boards-fqbn: arduino:mbed:giga
35+
# sketch-names: single_full_control_example.ino
36+
37+
38+
# Do not cancel all jobs / architectures if one job fails
39+
fail-fast: false
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@master
43+
- name: Compile all examples
44+
uses: ArminJo/arduino-test-compile@master
45+
with:
46+
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
47+
required-libraries: ${{ matrix.required-libraries }}
48+
platform-url: ${{ matrix.platform-url }}
49+
sketch-names: ${{ matrix.sketch-names }}
50+
sketches-exclude: ${{ matrix.sketches-exclude }}
51+
build-properties: ${{ toJson(matrix.build-properties) }}

.github/workflows/esp32.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333

3434
- arduino-boards-fqbn: esp32:esp32:esp32c3 # esp32c3
3535
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
36-
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino, stepper_driver_2pwm_standalone.ino, stepper_driver_4pwm_standalone.ino
36+
sketch-names: esp32_position_control.ino, stepper_driver_2pwm_standalone.ino, stepper_driver_4pwm_standalone.ino
3737

3838
- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
3939
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json

.github/workflows/silabs.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: SILABS
2+
on: [push, pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: arduino/arduino-lint-action@v1
9+
with:
10+
library-manager: update
11+
project-type: library
12+
build:
13+
name: Test compiling
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
arduino-boards-fqbn:
19+
- SiliconLabs:silabs:nano_matter # efr32 nano matter
20+
21+
include:
22+
23+
- arduino-boards-fqbn: SiliconLabs:silabs:nano_matter
24+
platform-url: https://siliconlabs.github.io/arduino/package_arduinosilabs_index.json
25+
sketch-names: efr32_hall_sensor_velocity_6pwm.ino, efr32_open_loop_velocity_6pwm.ino, efr32_torque_velocity_6pwm.ino
26+
27+
# Do not cancel all jobs / architectures if one job fails
28+
fail-fast: false
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@master
32+
- name: Compile all examples
33+
uses: ArminJo/arduino-test-compile@master
34+
with:
35+
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
36+
required-libraries: ${{ matrix.required-libraries }}
37+
platform-url: ${{ matrix.platform-url }}
38+
sketch-names: ${{ matrix.sketch-names }}
39+
sketches-exclude: ${{ matrix.sketches-exclude }}
40+
build-properties: ${{ toJson(matrix.build-properties) }}
41+

README.md

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
[![RP2040 build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml)
88
[![SAMD build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml)
99
[![Teensy build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml)
10+
[![MBED build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino_mbed.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/arduino_mbed.yml)
1011

1112
![GitHub release (latest by date)](https://img.shields.io/github/v/release/simplefoc/arduino-foc)
1213
![GitHub Release Date](https://img.shields.io/github/release-date/simplefoc/arduino-foc?color=blue)
1314
![GitHub commits since tagged version](https://img.shields.io/github/commits-since/simplefoc/arduino-foc/latest/dev)
1415
![GitHub commit activity (branch)](https://img.shields.io/github/commit-activity/m/simplefoc/arduino-foc/dev)
1516

16-
[![arduino-library-badge](https://ardubadge.simplefoc.com?lib=Simple%20FOC)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
17+
[![arduino-library-badge](https://www.ardu-badge.com/badge/Simple%20FOC.svg)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
1718
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/askuric/library/Simple%20FOC.svg)](https://registry.platformio.org/libraries/askuric/Simple%20FOC)
1819
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
1920
[![status](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d/status.svg)](https://joss.theoj.org/papers/4382445f249e064e9f0a7f6c1bb06b1d)
@@ -29,27 +30,22 @@ Therefore this is an attempt to:
2930
- For official driver boards see [<span class="simple">Simple<span class="foc">FOC</span>Boards</span>](https://docs.simplefoc.com/boards)
3031
- 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/)
3132

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
33+
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.6
34+
>
35+
> - STM32 bugfix
36+
> - BG341 low-side current sense sync was lost in v2.3.5 - fixed [#482](https://github.com/simplefoc/Arduino-FOC/pull/482)
37+
> - ESP32 bugfix
38+
> - Now compiles for all v3.x arduino-esp32 versions (v2.3.5 was compatible with v3.2.x)
39+
> - `adcRead` small refactor - no more magic numbers
40+
> - New fuctionality
41+
> - Add current and voltage feed forward terms to motor classes by @Copper280z in https://github.com/simplefoc/Arduino-FOC/pull/454
42+
> - Velocity Calculation rework by @Copper280z in https://github.com/simplefoc/Arduino-FOC/pull/45
43+
> - Examples
44+
> - `align_current_sense.ino` example added to the `examples/utls/current_sense_test` allowing to verify the alignment between the driver and the current sense phases
45+
46+
47+
48+
## Arduino *SimpleFOClibrary* v2.3.6
5349

5450
<p align="">
5551
<a href="https://youtu.be/Y5kLeqTc6Zk">
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* Silabs MG24 6PWM closed loop velocity control example with HALL sensor based rotor position
3+
*
4+
* HARDWARE CONFIGURATION:
5+
* CPU Board: Arduino Nano Matter
6+
* Motor Driver Board: BOOSTXL-DRV8305EVM
7+
* BLDC Motor: Newark DF45M024053-A2
8+
*/
9+
10+
#include <SimpleFOC.h>
11+
12+
#define HALL_SENSOR_IRQ 1
13+
#define ENABLE_MONITOR 0
14+
15+
static bool allow_run = false;
16+
17+
// BLDC motor instance
18+
BLDCMotor *motor;
19+
20+
// BLDC driver instance
21+
BLDCDriver6PWM *driver;
22+
23+
// Commander instance
24+
Commander *command;
25+
26+
// Hall sensor instance
27+
HallSensor *sensor;
28+
29+
// Interrupt routine initialization
30+
// channel A and B callbacks
31+
void doA() { sensor->handleA(); }
32+
void doB() { sensor->handleB(); }
33+
void doC() { sensor->handleC(); }
34+
35+
void doMotor(char* cmd) {
36+
if (!command) return;
37+
command->motor(motor, cmd);
38+
}
39+
40+
void setup() {
41+
// use monitoring with serial
42+
Serial.begin(115200);
43+
// enable more verbose output for debugging
44+
// comment out if not needed
45+
SimpleFOCDebug::enable(&Serial);
46+
47+
// Commander
48+
command = new Commander(Serial);
49+
if (!command) return;
50+
51+
// Driver
52+
driver = new BLDCDriver6PWM(6, 7, 8, 9, 10, 11, 12);
53+
if (!driver) return;
54+
55+
// Driver config
56+
// power supply voltage [V]
57+
driver->voltage_power_supply = 24;
58+
// pwm frequency to be used [Hz]
59+
driver->pwm_frequency = 20000; // 20 kHz
60+
// Max DC voltage allowed - default voltage_power_supply
61+
driver->voltage_limit = 12;
62+
// dead zone percentage of the duty cycle - default 0.02 - 2%
63+
// Can set value to 0 because the DRV8305 will provide the
64+
// required dead-time.
65+
driver->dead_zone = 0;
66+
67+
// init driver
68+
if (!driver->init()) {
69+
Serial.println("Driver init failed!");
70+
return;
71+
}
72+
driver->enable();
73+
74+
// HallSensor(int encA, int encB, int encC, int pp)
75+
// - encA, encB, encC - HallSensor A, B and C pins
76+
// - pp - pole pairs
77+
sensor = new HallSensor(5, 4, 13, 8);
78+
if (!sensor) return;
79+
80+
// initialize sensor sensor hardware
81+
sensor->init();
82+
83+
#if HALL_SENSOR_IRQ
84+
sensor->enableInterrupts(doA, doB, doC);
85+
#else
86+
// Note: There is a bug when initializing HallSensor in heap, attribute
87+
// `use_interrupt` gets value not `false` even `enableInterrupts` has not been
88+
// called. So we initialize this attribute value `false` after creating a
89+
// `HallSensor` instance.
90+
sensor->use_interrupt = false;
91+
#endif
92+
93+
// Motor
94+
motor = new BLDCMotor(8);
95+
if (!motor) return;
96+
97+
// link the motor and the driver
98+
motor->linkDriver(driver);
99+
100+
// link the motor to the sensor
101+
motor->linkSensor(sensor);
102+
103+
// Set below the motor's max 5600 RPM limit = 586 rad/s
104+
motor->velocity_limit = 530.0f;
105+
106+
// set motion control loop to be used
107+
motor->controller = MotionControlType::velocity;
108+
109+
// choose FOC modulation (optional) - SinePWM or SpaceVectorPWM
110+
motor->foc_modulation = FOCModulationType::SpaceVectorPWM;
111+
112+
// controller configuration
113+
// velocity PI controller parameters
114+
motor->PID_velocity.P = 0.05f;
115+
motor->PID_velocity.I = 1;
116+
117+
// velocity low pass filtering time constant
118+
motor->LPF_velocity.Tf = 0.01f;
119+
120+
#if ENABLE_MONITOR
121+
motor->useMonitoring(Serial);
122+
motor->monitor_variables = _MON_TARGET | _MON_VEL;
123+
#endif
124+
125+
// initialize motor
126+
if (!motor->init()) {
127+
Serial.println("Motor init failed!");
128+
return;
129+
}
130+
131+
// align sensor and start FOC
132+
if (!motor->initFOC()) {
133+
Serial.println("FOC init failed!");
134+
return;
135+
}
136+
137+
// add target command M
138+
command->add('M', doMotor, "motor");
139+
140+
Serial.println("Motor ready!");
141+
Serial.println("Set target velocity [rad/s]");
142+
143+
allow_run = true;
144+
_delay(1000);
145+
}
146+
147+
void loop() {
148+
if (!allow_run) return;
149+
150+
// main FOC algorithm function
151+
// the faster you run this function the better
152+
motor->loopFOC();
153+
154+
// Motion control function
155+
// velocity, position or voltage (defined in motor.controller)
156+
// this function can be run at much lower frequency than loopFOC() function
157+
// You can also use motor.move() and set the motor.target in the code
158+
motor->move();
159+
160+
#if ENABLE_MONITOR
161+
// function intended to be used with serial plotter to monitor motor variables
162+
// significantly slowing the execution down!!!!
163+
motor->monitor();
164+
#endif
165+
166+
// user communication
167+
command->run();
168+
}

0 commit comments

Comments
 (0)