Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
c28ad9d
fix for MagneticSensorI2C uses incorrect bit mask calculation #402402
runger1101001 Jun 10, 2024
87ea185
Merge branch 'simplefoc:dev' into dev
runger1101001 Jun 22, 2024
9281dce
Merge branch 'dev' of https://github.com/simplefoc/Arduino-FOC into dev
runger1101001 Jun 23, 2024
4395c22
Merge remote-tracking branch 'simplefoc/dev' into dev
runger1101001 Jul 21, 2024
1d1c5dd
HAL / LL only PWM driver
runger1101001 Aug 24, 2024
5569f73
update l4 current sense to new API
runger1101001 Aug 30, 2024
3d26880
change target to include all the mbed STM32H7s
runger1101001 Aug 30, 2024
afa8e3d
fix STM32F1 current sense
runger1101001 Aug 30, 2024
8102189
fix B-G431-ESC1 current sense driver
runger1101001 Aug 30, 2024
cd79e01
now working on Portenta H7
runger1101001 Aug 30, 2024
d688fcc
fix current sense for stm32f7 MCUs
runger1101001 Aug 30, 2024
e535bba
fix for software 6-PWM low side polarity
runger1101001 Aug 31, 2024
4d8fa4a
add comments for triggers
runger1101001 Oct 3, 2024
72aa902
working on rp2350 support
runger1101001 Oct 3, 2024
add1f42
Merge pull request #435 from runger1101001/rp2350_support
runger1101001 Oct 6, 2024
58ec978
Add motor characterisation
mcells Oct 9, 2024
65eff47
change uint to unsigned int for unit tests
mcells Oct 9, 2024
6ba2cf2
Add characterisation example
mcells Oct 10, 2024
6473a17
add ability to reserve timers so they don't get used for motors
runger1101001 Nov 7, 2024
f6362e7
small fixes
runger1101001 Nov 7, 2024
c507b71
fix for ESP32 C6 with >1 motors
runger1101001 Nov 7, 2024
de755f4
Merge pull request #436 from mcells/feat-inductance-measure
runger1101001 Nov 7, 2024
283e513
Merge remote-tracking branch 'simplefoc/dev' into dev
runger1101001 Nov 7, 2024
e3140fc
update readme with changes for 2.3.5 release
runger1101001 Nov 7, 2024
20e4481
bump library version for release
runger1101001 Nov 7, 2024
1a267af
Update open_loop_velocity_6pwm.ino
askuric Feb 3, 2025
e11ab31
Update open_loop_position_example.ino
askuric Feb 3, 2025
83c341b
Update open_loop_velocity_6pwm.ino
askuric Feb 3, 2025
db09787
Merge branch 'stm32_hal_pwm' into dev
runger1101001 Feb 18, 2025
1f0be50
#451 change DriverType "Unknown" to "UnknownDriver"
runger1101001 Feb 18, 2025
b434d80
fix ESP32 example compilation
runger1101001 Feb 18, 2025
c5bfd51
fix compilation for ESP32S3 and DoIt DevKit
runger1101001 Feb 18, 2025
820ae07
remove dual I2C bus example from ESP32 C3 compile
runger1101001 Feb 18, 2025
8b288a9
exclude inductance/resistance example from UNO - too big
runger1101001 Feb 18, 2025
5981f8b
Merge pull request #442 from runger1101001/dev
runger1101001 Feb 18, 2025
f60c953
Merge pull request #449 from simplefoc/current_calculation_typo_in_co…
runger1101001 Feb 18, 2025
1c25100
Merge pull request #452 from simplefoc/master
runger1101001 Feb 22, 2025
4ef3738
added the trgo info to the ADC
askuric Mar 12, 2025
d91a96f
show error if not using ADC pins
askuric Mar 12, 2025
9b1de23
moved the hybrid stepper to main + current sense support
askuric Mar 12, 2025
ccb3b48
allow stm32 to have any current sense pin as _NC
askuric Mar 12, 2025
dc1db48
typo in f1
askuric Mar 12, 2025
7c80c9a
Merge pull request #457 from simplefoc/feat_hybrid_stepper_to_main
runger1101001 Mar 12, 2025
8268acf
Fix `Pin is not configured as analog channel` error
jeremiahrose Mar 13, 2025
360121d
typo if a channel not used
askuric Mar 13, 2025
a2bd1ea
roll-back
askuric Mar 13, 2025
5dffc7b
f7 typo
askuric Mar 13, 2025
b824026
inital support for h7 low-side current sensing - compiless
askuric Mar 13, 2025
412c47a
use default dir only if sensor not connected
askuric Mar 14, 2025
1e1ace5
Merge pull request #458 from jeremiahrose/patch-1
runger1101001 Mar 14, 2025
d4a978b
Merge branch 'feat_h7_current_sensing' into feat_default_dir_only_no_…
askuric Mar 18, 2025
5f9c23b
inital testing for h7
askuric Mar 18, 2025
f182385
target_h7 to stm32h7
askuric Mar 18, 2025
b7c6638
add the compile for portenta and giga
askuric Mar 19, 2025
9e81c2c
issues with compile CI
askuric Mar 19, 2025
d6b83cb
remove giga from CI
askuric Mar 19, 2025
74face7
a rewrite for portenta + bugfixes
askuric Mar 19, 2025
36e078c
inital update of the cs for stm32
askuric Mar 21, 2025
3e1870b
rank calculation problem
askuric Mar 21, 2025
fa19507
Merge remote-tracking branch 'origin/dev' into dev
askuric Mar 21, 2025
3383d57
Merge branch 'dev' into 317-feature-foc_current-mode-and-current-feed…
askuric Mar 21, 2025
49e34e8
automatic adc selsction
askuric Mar 21, 2025
9bb6cfb
remove some debugging
askuric Mar 21, 2025
7cb5a17
Merge branch '317-feature-foc_current-mode-and-current-feed-forward' …
askuric Mar 21, 2025
2857d3e
h7 update for auto-search
askuric Mar 21, 2025
d8fac13
f1 update
askuric Mar 21, 2025
b9b9cf3
restructuring for f1
askuric Mar 21, 2025
162322f
giMerge branch '317-feature-foc_current-mode-and-current-feed-forward…
askuric Mar 21, 2025
302719c
tested h7 low-side, added repetition counterhandling
askuric Apr 29, 2025
5c5e309
add support for timer 8
May 7, 2025
cad1bc5
Merge pull request #468 from jeroenzwan/master
runger1101001 May 7, 2025
c8002cc
Merge pull request #459 from simplefoc/feat_default_dir_only_no_sensor
runger1101001 May 7, 2025
bf02fdd
Merge remote-tracking branch 'origin/dev' into feat_h7_current_sensing
askuric May 14, 2025
0bb487a
Merge pull request #460 from simplefoc/feat_h7_current_sensing
runger1101001 May 16, 2025
49cfd38
[BUG] esp32 ledc skips first channel index #471
runger1101001 May 21, 2025
311dfe7
bugfix for low-side sync
askuric May 28, 2025
8ab5336
refactored the injected channel config
askuric Jun 3, 2025
4680216
Add MT6701_I2C to MagneticSensorI2CConfig_s
adamgerhant Jun 17, 2025
30bff68
Disable allow power down when creating pwm timer
adamgerhant Jun 17, 2025
a03b493
Merge branch 'dev' into master
runger1101001 Jun 17, 2025
e235d70
Merge pull request #474 from adamgerhant/master
runger1101001 Jun 17, 2025
a40e148
Merge pull request #478 from simplefoc/fix_lowside_sync_lost
runger1101001 Jul 16, 2025
79903fe
newly written and simplified support for lowside on samd21
askuric Jul 24, 2025
23ed42c
some simplifications
askuric Jul 24, 2025
8ebbd19
indo update
askuric Jul 25, 2025
9dbd91a
Merge branch 'dev' of github.com:runger1101001/Arduino-FOC into dev
runger1101001 Jul 27, 2025
0205da7
Merge pull request #479 from simplefoc/feat_lowside_samd21
runger1101001 Jul 27, 2025
27091b1
Merge remote-tracking branch 'simplefoc/dev' into dev
runger1101001 Jul 27, 2025
a1d5b86
Merge pull request #480 from runger1101001/dev
runger1101001 Jul 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/arduino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- arduino-boards-fqbn: arduino:avr:uno # arudino uno - compiling almost all examples
sketch-names: '**.ino'
required-libraries: PciManager
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
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

- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
sketch-names: single_full_control_example.ino
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/arduino_mbed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: MDED
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
project-type: library
build:
name: Test compiling
runs-on: ubuntu-latest

strategy:
matrix:
arduino-boards-fqbn:
#- arduino:mbed:giga # arudino giga
- arduino:mbed:nanorp2040connect # arduino nano rp2040 connect
- arduino:mbed:nano33ble # arduino nano 33 ble
- arduino:mbed:envie_m7 # arduino portenta

include:
- arduino-boards-fqbn: arduino:mbed:nanorp2040connect
sketch-names: open_loop_position_example.ino

- arduino-boards-fqbn: arduino:mbed:nano33ble
sketch-names: open_loop_position_example.ino

- arduino-boards-fqbn: arduino:mbed:envie_m7
sketch-names: open_loop_position_example.ino

# - arduino-boards-fqbn: arduino:mbed:giga
# sketch-names: single_full_control_example.ino


# Do not cancel all jobs / architectures if one job fails
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@master
- name: Compile all examples
uses: ArminJo/arduino-test-compile@master
with:
arduino-board-fqbn: ${{ matrix.arduino-boards-fqbn }}
required-libraries: ${{ matrix.required-libraries }}
platform-url: ${{ matrix.platform-url }}
sketch-names: ${{ matrix.sketch-names }}
sketches-exclude: ${{ matrix.sketches-exclude }}
build-properties: ${{ toJson(matrix.build-properties) }}
2 changes: 1 addition & 1 deletion .github/workflows/esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

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

- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
Expand Down
42 changes: 23 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
[![RP2040 build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/rpi.yml)
[![SAMD build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/samd.yml)
[![Teensy build](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml/badge.svg)](https://github.com/simplefoc/Arduino-FOC/actions/workflows/teensy.yml)
[![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)

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

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

> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.4
> - ESP32 MCUs extended support [#414](https://github.com/simplefoc/Arduino-FOC/pull/414)
> - Transition to the arduino-esp32 version v3.x (ESP-IDF v5.x) [#387](https://github.com/espressif/arduino-esp32/releases)
> - New support for MCPWM driver
> - New support for LEDC drivers - center-aligned PWM and 6PWM available
> - Rewritten and simplified the fast ADC driver code (`adcRead`) - for low-side and inline current sensing.
> - Stepper motors current sensing support [#421](https://github.com/simplefoc/Arduino-FOC/pull/421)
> - Support for current sensing (low-side and inline) - [see in docs](https://docs.simplefoc.com/current_sense)
> - Support for true FOC control - `foc_current` torque control - [see in docs](https://docs.simplefoc.com/motion_control)
> - New current sense alignment procedure [#422](https://github.com/simplefoc/Arduino-FOC/pull/422) - [see in docs](https://docs.simplefoc.com/current_sense_align)
> - Support for steppers
> - Much more robust and reliable
> - More verbose and informative
> - Support for HallSensors without interrupts [#424](https://docs.simplefoc.com/https://github.com/simplefoc/Arduino-FOC/pull/424) - [see in docs](hall_sensors)
> NEXT RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.5
>
> - ESP32 bugfix
> - after the low-level API changes in the Arduino-ESP32 core [PR447](https://github.com/simplefoc/Arduino-FOC/pull/447)
> - Pin is not configured [PR458](https://github.com/simplefoc/Arduino-FOC/pull/458)
> - C6 MCPWM bugfix [PR440](https://github.com/simplefoc/Arduino-FOC/pull/440)
> - New fuctionality
> - HybridStepperMotor added to the main library [PR457](https://github.com/simplefoc/Arduino-FOC/pull/457) - [see in docs](https://docs.simplefoc.com/steppermotor)
> - 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)
> - SAMD21 support for low-side current sensing [PR479](https://github.com/simplefoc/Arduino-FOC/pull/479)
> - RP2350 support [PR435](https://github.com/simplefoc/Arduino-FOC/pull/435) [PR468](https://github.com/simplefoc/Arduino-FOC/pull/468)
> - STM32
> - New driver code [PR442](https://github.com/simplefoc/Arduino-FOC/pull/442)
> - Low-side current sensing support for H7 family [PR460](https://github.com/simplefoc/Arduino-FOC/pull/460)
> - Docs
> - A short guide to debugging of common issues
> - A short guide to the units in the library - [see in docs](https://docs.simplefoc.com/library_units)
> - See the complete list of bugfixes and new features of v2.3.4 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/11)
> - Hybrid stepper motor example [see in docs](https://docs.simplefoc.com/stepper_control_shield)
> - Sensorless FOC example [see in docs](https://docs.simplefoc.com/sensorless_foc_nucleo_example)
> - A short guide to synchronous loop - [see in docs](https://docs.simplefoc.com/real_time_loop)
> - See the complete list of bugfixes and new features of v2.3.5 [fixes and PRs](https://github.com/simplefoc/Arduino-FOC/milestone/12)


## Arduino *SimpleFOClibrary* v2.3.4


## Arduino *SimpleFOClibrary* v2.3.5

<p align="">
<a href="https://youtu.be/Y5kLeqTc6Zk">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void setup() {
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// currnet = resistance*voltage, so try to be well under 1Amp
// currnet = voltage/resistance, so try to be well under 1Amp
motor.voltage_limit = 3; // [V]

// open loop control config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void setup() {
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// currnet = resistance*voltage, so try to be well under 1Amp
// currnet = voltage/resistance, so try to be well under 1Amp
motor.voltage_limit = 3; // [V]

// open loop control config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void setup() {
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// currnet = resistance*voltage, so try to be well under 1Amp
// currnet = voltage/resistance, so try to be well under 1Amp
motor.voltage_limit = 3; // [V]
// limit/set the velocity of the transition in between
// target angles
Expand Down Expand Up @@ -78,4 +78,4 @@ void loop() {

// user communication
command.run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
*
* Motor characterisation example sketch.
*
*/
#include <SimpleFOC.h>


// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);

// encoder instance
Encoder encoder = Encoder(2, 3, 500);
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}

// current sensor
InlineCurrentSense current_sense = InlineCurrentSense(0.01f, 50.0f, A0, A2);

// characterisation voltage set point variable
float characteriseVolts = 0.0f;

// instantiate the commander
Commander command = Commander(Serial);
void onMotor(char* cmd){command.motor(&motor,cmd);}
void characterise(char* cmd) {
command.scalar(&characteriseVolts, cmd);
motor.characteriseMotor(characteriseVolts);
}

void setup() {

// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);

// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);

// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link driver
motor.linkDriver(&driver);
// link current sense and the driver
current_sense.linkDriver(&driver);

// current sense init hardware
current_sense.init();
// link the current sense to the motor
motor.linkCurrentSense(&current_sense);

// set torque mode:
// TorqueControlType::dc_current
// TorqueControlType::voltage
// TorqueControlType::foc_current
motor.torque_controller = TorqueControlType::foc_current;
// set motion control loop to be used
motor.controller = MotionControlType::torque;

// foc current control parameters (Arduino UNO/Mega)
motor.PID_current_q.P = 5;
motor.PID_current_q.I= 300;
motor.PID_current_d.P= 5;
motor.PID_current_d.I = 300;
motor.LPF_current_q.Tf = 0.01f;
motor.LPF_current_d.Tf = 0.01f;
// foc current control parameters (stm/esp/due/teensy)
// motor.PID_current_q.P = 5;
// motor.PID_current_q.I= 1000;
// motor.PID_current_d.P= 5;
// motor.PID_current_d.I = 1000;
// motor.LPF_current_q.Tf = 0.002f; // 1ms default
// motor.LPF_current_d.Tf = 0.002f; // 1ms default

// comment out if not needed
motor.useMonitoring(Serial);

// initialize motor
motor.init();
// align sensor and start FOC
motor.initFOC();

// add commands M & L
command.add('M',&onMotor,"Control motor");
command.add('L', characterise, "Characterise motor L & R with the given voltage");

motor.disable();

Serial.println(F("Motor disabled and ready."));
Serial.println(F("Control the motor and measure the inductance using the terminal. Type \"?\" for available commands:"));
_delay(1000);
}

void loop() {

// main FOC algorithm function
// the faster you run this function the better
// Arduino UNO loop ~1kHz
// Bluepill loop ~10kHz
motor.loopFOC();

// Motion control function
// velocity, position or torque (defined in motor.controller)
// this function can be run at much lower frequency than loopFOC() function
// You can also use motor.move() and set the motor.target in the code
motor.move();

// user communication
command.run();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <SimpleFOC.h>
#include <Wire.h>

/** 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
* This example shows how a second i2c bus can be used to communicate with a second sensor.
Expand All @@ -7,6 +8,8 @@
MagneticSensorI2C sensor0 = MagneticSensorI2C(AS5600_I2C);
MagneticSensorI2C sensor1 = MagneticSensorI2C(AS5600_I2C);

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

void setup() {

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Simple FOC
version=2.3.4
version=2.3.5
author=Simplefoc <[email protected]>
maintainer=Simplefoc <[email protected]>
sentence=A library demistifying FOC for BLDC motors
Expand Down
15 changes: 8 additions & 7 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ int BLDCMotor::init() {
P_angle.limit = velocity_limit;

// if using open loop control, set a CW as the default direction if not already set
if ((controller==MotionControlType::angle_openloop
||controller==MotionControlType::velocity_openloop)
&& (sensor_direction == Direction::UNKNOWN)) {
sensor_direction = Direction::CW;
// only if no sensor is used
if(!sensor){
if ((controller==MotionControlType::angle_openloop
||controller==MotionControlType::velocity_openloop)
&& (sensor_direction == Direction::UNKNOWN)) {
sensor_direction = Direction::CW;
}
}

_delay(500);
Expand Down Expand Up @@ -290,9 +293,7 @@ int BLDCMotor::alignSensor() {
zero_electric_angle = electricalAngle();
//zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->getAngle(), pole_pairs));
_delay(20);
if(monitor_port){
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
}
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
// stop everything
setPhaseVoltage(0, 0, 0);
_delay(200);
Expand Down
10 changes: 10 additions & 0 deletions src/BLDCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ class BLDCMotor: public FOCMotor
*/
void setPhaseVoltage(float Uq, float Ud, float angle_el) override;

/**
* Measure resistance and inductance of a BLDCMotor and print results to debug.
* If a sensor is available, an estimate of zero electric angle will be reported too.
* @param voltage The voltage applied to the motor
* @returns 0 for success, >0 for failure
*/
int characteriseMotor(float voltage){
return FOCMotor::characteriseMotor(voltage, 1.5f);
}

private:
// FOC methods

Expand Down
Loading