Skip to content

Commit f5ac652

Browse files
authored
Merge pull request #481 from simplefoc/dev
Dev to master v2.3.5
2 parents fb0be07 + a1d5b86 commit f5ac652

File tree

74 files changed

+5035
-2818
lines changed

Some content is hidden

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

74 files changed

+5035
-2818
lines changed

.github/workflows/arduino.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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: measure_inductance_and_resistance, 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
2929

3030
- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
3131
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

README.md

Lines changed: 23 additions & 19 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,30 @@ 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)
33+
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.5
34+
>
35+
> - ESP32 bugfix
36+
> - after the low-level API changes in the Arduino-ESP32 core [PR447](https://github.com/simplefoc/Arduino-FOC/pull/447)
37+
> - Pin is not configured [PR458](https://github.com/simplefoc/Arduino-FOC/pull/458)
38+
> - C6 MCPWM bugfix [PR440](https://github.com/simplefoc/Arduino-FOC/pull/440)
39+
> - New fuctionality
40+
> - HybridStepperMotor added to the main library [PR457](https://github.com/simplefoc/Arduino-FOC/pull/457) - [see in docs](https://docs.simplefoc.com/steppermotor)
41+
> - Motor characterisation (phase resistance and inductance) [PR436](https://github.com/simplefoc/Arduino-FOC/pull/436) - [see in docs](https://docs.simplefoc.com/bldcmotor#how-can-i-measure-the-phase-resistance-and-inductance)
42+
> - SAMD21 support for low-side current sensing [PR479](https://github.com/simplefoc/Arduino-FOC/pull/479)
43+
> - RP2350 support [PR435](https://github.com/simplefoc/Arduino-FOC/pull/435) [PR468](https://github.com/simplefoc/Arduino-FOC/pull/468)
44+
> - STM32
45+
> - New driver code [PR442](https://github.com/simplefoc/Arduino-FOC/pull/442)
46+
> - Low-side current sensing support for H7 family [PR460](https://github.com/simplefoc/Arduino-FOC/pull/460)
4647
> - 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)
48+
> - Hybrid stepper motor example [see in docs](https://docs.simplefoc.com/stepper_control_shield)
49+
> - Sensorless FOC example [see in docs](https://docs.simplefoc.com/sensorless_foc_nucleo_example)
50+
> - A short guide to synchronous loop - [see in docs](https://docs.simplefoc.com/real_time_loop)
51+
> - See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12)
5052
5153

52-
## Arduino *SimpleFOClibrary* v2.3.4
54+
55+
56+
## Arduino *SimpleFOClibrary* v2.3.5
5357

5458
<p align="">
5559
<a href="https://youtu.be/Y5kLeqTc6Zk">

examples/hardware_specific_examples/Teensy/Teensy3/open_loop_velocity_6pwm/open_loop_velocity_6pwm.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void setup() {
3838
// limiting motor movements
3939
// limit the voltage to be set to the motor
4040
// start very low for high resistance motors
41-
// currnet = resistance*voltage, so try to be well under 1Amp
41+
// currnet = voltage/resistance, so try to be well under 1Amp
4242
motor.voltage_limit = 3; // [V]
4343

4444
// open loop control config

examples/hardware_specific_examples/Teensy/Teensy4/open_loop_velocity_6pwm/open_loop_velocity_6pwm.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void setup() {
5353
// limiting motor movements
5454
// limit the voltage to be set to the motor
5555
// start very low for high resistance motors
56-
// currnet = resistance*voltage, so try to be well under 1Amp
56+
// currnet = voltage/resistance, so try to be well under 1Amp
5757
motor.voltage_limit = 3; // [V]
5858

5959
// open loop control config

examples/motion_control/open_loop_motor_control/open_loop_position_example/open_loop_position_example.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void setup() {
4646
// limiting motor movements
4747
// limit the voltage to be set to the motor
4848
// start very low for high resistance motors
49-
// currnet = resistance*voltage, so try to be well under 1Amp
49+
// currnet = voltage/resistance, so try to be well under 1Amp
5050
motor.voltage_limit = 3; // [V]
5151
// limit/set the velocity of the transition in between
5252
// target angles
@@ -78,4 +78,4 @@ void loop() {
7878

7979
// user communication
8080
command.run();
81-
}
81+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
*
3+
* Motor characterisation example sketch.
4+
*
5+
*/
6+
#include <SimpleFOC.h>
7+
8+
9+
// BLDC motor & driver instance
10+
BLDCMotor motor = BLDCMotor(11);
11+
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
12+
13+
// encoder instance
14+
Encoder encoder = Encoder(2, 3, 500);
15+
// channel A and B callbacks
16+
void doA(){encoder.handleA();}
17+
void doB(){encoder.handleB();}
18+
19+
// current sensor
20+
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);
21+
22+
// characterisation voltage set point variable
23+
float characteriseVolts = 0.0f;
24+
25+
// instantiate the commander
26+
Commander command = Commander(Serial);
27+
void onMotor(char* cmd){command.motor(&motor,cmd);}
28+
void characterise(char* cmd) {
29+
command.scalar(&characteriseVolts, cmd);
30+
motor.characteriseMotor(characteriseVolts);
31+
}
32+
33+
void setup() {
34+
35+
// use monitoring with serial
36+
Serial.begin(115200);
37+
// enable more verbose output for debugging
38+
// comment out if not needed
39+
SimpleFOCDebug::enable(&Serial);
40+
41+
// initialize encoder sensor hardware
42+
encoder.init();
43+
encoder.enableInterrupts(doA, doB);
44+
// link the motor to the sensor
45+
motor.linkSensor(&encoder);
46+
47+
// driver config
48+
// power supply voltage [V]
49+
driver.voltage_power_supply = 12;
50+
driver.init();
51+
// link driver
52+
motor.linkDriver(&driver);
53+
// link current sense and the driver
54+
current_sense.linkDriver(&driver);
55+
56+
// current sense init hardware
57+
current_sense.init();
58+
// link the current sense to the motor
59+
motor.linkCurrentSense(&current_sense);
60+
61+
// set torque mode:
62+
// TorqueControlType::dc_current
63+
// TorqueControlType::voltage
64+
// TorqueControlType::foc_current
65+
motor.torque_controller = TorqueControlType::foc_current;
66+
// set motion control loop to be used
67+
motor.controller = MotionControlType::torque;
68+
69+
// foc current control parameters (Arduino UNO/Mega)
70+
motor.PID_current_q.P = 5;
71+
motor.PID_current_q.I= 300;
72+
motor.PID_current_d.P= 5;
73+
motor.PID_current_d.I = 300;
74+
motor.LPF_current_q.Tf = 0.01f;
75+
motor.LPF_current_d.Tf = 0.01f;
76+
// foc current control parameters (stm/esp/due/teensy)
77+
// motor.PID_current_q.P = 5;
78+
// motor.PID_current_q.I= 1000;
79+
// motor.PID_current_d.P= 5;
80+
// motor.PID_current_d.I = 1000;
81+
// motor.LPF_current_q.Tf = 0.002f; // 1ms default
82+
// motor.LPF_current_d.Tf = 0.002f; // 1ms default
83+
84+
// comment out if not needed
85+
motor.useMonitoring(Serial);
86+
87+
// initialize motor
88+
motor.init();
89+
// align sensor and start FOC
90+
motor.initFOC();
91+
92+
// add commands M & L
93+
command.add('M',&onMotor,"Control motor");
94+
command.add('L', characterise, "Characterise motor L & R with the given voltage");
95+
96+
motor.disable();
97+
98+
Serial.println(F("Motor disabled and ready."));
99+
Serial.println(F("Control the motor and measure the inductance using the terminal. Type \"?\" for available commands:"));
100+
_delay(1000);
101+
}
102+
103+
void loop() {
104+
105+
// main FOC algorithm function
106+
// the faster you run this function the better
107+
// Arduino UNO loop ~1kHz
108+
// Bluepill loop ~10kHz
109+
motor.loopFOC();
110+
111+
// Motion control function
112+
// velocity, position or torque (defined in motor.controller)
113+
// this function can be run at much lower frequency than loopFOC() function
114+
// You can also use motor.move() and set the motor.target in the code
115+
motor.move();
116+
117+
// user communication
118+
command.run();
119+
}

examples/utils/sensor_test/magnetic_sensors/magnetic_sensor_i2c/magnetic_sensor_i2c_dual_bus_examples/esp32_i2c_dual_bus_example/esp32_i2c_dual_bus_example.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <SimpleFOC.h>
2+
#include <Wire.h>
23

34
/** Annoyingly some i2c sensors (e.g. AS5600) have a fixed chip address. This means only one of these devices can be addressed on a single bus
45
* This example shows how a second i2c bus can be used to communicate with a second sensor.
@@ -7,6 +8,8 @@
78
MagneticSensorI2C sensor0 = MagneticSensorI2C(AS5600_I2C);
89
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);
910

11+
// example of esp32 defining 2nd bus, if not already defined
12+
//TwoWire Wire1(1);
1013

1114
void setup() {
1215

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.4
2+
version=2.3.5
33
author=Simplefoc <info@simplefoc.com>
44
maintainer=Simplefoc <info@simplefoc.com>
55
sentence=A library demistifying FOC for BLDC motors

0 commit comments

Comments
 (0)