Skip to content

Commit

Permalink
Merge remote-tracking branch 'simplefoc/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
runger1101001 committed Jul 21, 2024
2 parents 9281dce + 2de948c commit 4395c22
Show file tree
Hide file tree
Showing 42 changed files with 965 additions and 654 deletions.
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
![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://www.ardu-badge.com/badge/Simple%20FOC.svg?)](https://www.ardu-badge.com/badge/Simple%20FOC.svg)
[![arduino-library-badge](https://ardubadge.simplefoc.com?lib=Simple%20FOC)](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 @@ -28,21 +29,27 @@ 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/)

> NEW RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.3
> - Teensy4
> - support for low-side current sensing [#392](https://github.com/simplefoc/Arduino-FOC/pull/392)
> - support for center aligned 6pwm and 3pwm (optional) [#392](https://github.com/simplefoc/Arduino-FOC/pull/392)
> - stm32
> - 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)
> - 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)
> - support for f7 architecture [#388](https://github.com/simplefoc/Arduino-FOC/pull/388),[#394](https://github.com/simplefoc/Arduino-FOC/pull/394)
> - KV rating calculation fix [#347](https://github.com/simplefoc/Arduino-FOC/pull/347)
> - Much more performant Space Vector PWM calculation [#340](https://github.com/simplefoc/Arduino-FOC/pull/340)
> - And much more:
> - 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)

## Arduino *SimpleFOClibrary* v2.3.3
> 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)
> - 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)

## Arduino *SimpleFOClibrary* v2.3.4

<p align="">
<a href="https://youtu.be/Y5kLeqTc6Zk">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
*
* SimpleFOCMini motor control example
*
* For Arduino UNO or the other boards with the UNO headers
* the most convenient way to use the board is to stack it to the pins:
* - 12 - ENABLE
* - 11 - IN1
* - 10 - IN2
* - 9 - IN3
*
*/
#include <SimpleFOC.h>


// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
// BLDCDriver3PWM driver = BLDCDriver3PWM(11, 10, 9, 8); // mini v1.0
BLDCDriver3PWM driver = BLDCDriver3PWM(9, 10, 11, 12); // mini v1.1

// instantiate the commander
Commander command = Commander(Serial);
void doMotor(char* cmd) { command.motor(&motor, cmd); }

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

// if SimpleFOCMini is stacked in arduino headers
// on pins 12,11,10,9,8
// pin 12 is used as ground
pinMode(12,OUTPUT);
pinMode(12,LOW);

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

// aligning voltage [V]
motor.voltage_sensor_align = 3;

// set motion control loop to be used
motor.controller = MotionControlType::velocity_openloop;

// default voltage_power_supply
motor.voltage_limit = 2; // Volts

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

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

// add target command M
command.add('M', doMotor, "motor");

Serial.println(F("Motor ready."));
Serial.println(F("Set the target velocity using serial terminal:"));

motor.target = 1; //initial target velocity 1 rad/s
Serial.println("Target velocity: 1 rad/s");
Serial.println("Voltage limit 2V");
_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 voltage (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();

// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!!
// motor.monitor();

// user communication
command.run();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void doB(){encoder.handleB();}

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

// commander communication instance
Commander command = Commander(Serial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void setup() {
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 6;
driver.init();
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);

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

// init motor hardware
motor.init();
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}

// add target command T
command.add('T', doTarget, "target angle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ void setup() {
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 6;
driver.init();
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);

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

// init motor hardware
motor.init();
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}

// add target command T
command.add('T', doTarget, "target velocity");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ void setup() {
SimpleFOCDebug::enable(&Serial);

// initialise the current sensing
current_sense.init();
if(!current_sense.init()){
Serial.println("Current sense init failed.");
return;
}

// for SimpleFOCShield v2.01/v2.0.2
current_sense.gain_b *= -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ void setup() {
driver.voltage_limit = 12;

// driver init
driver.init();
if (!driver.init()){
Serial.println("Driver init failed!");
return;
}

// enable driver
driver.enable();

Serial.println("Driver ready!");
_delay(1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ void setup() {
driver.dead_zone = 0.05f;

// driver init
driver.init();
if (!driver.init()){
Serial.println("Driver init failed!");
return;
}

// enable driver
driver.enable();

Serial.println("Driver ready!");
_delay(1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ void setup() {
driver.voltage_limit = 12;

// driver init
driver.init();
if (!driver.init()){
Serial.println("Driver init failed!");
return;
}

// enable driver
driver.enable();

Serial.println("Driver ready!");
_delay(1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ void setup() {
driver.voltage_limit = 12;

// driver init
driver.init();
if (!driver.init()){
Serial.println("Driver init failed!");
return;
}

// enable driver
driver.enable();

Serial.println("Driver ready!");
_delay(1000);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
// - pp - pole pairs
HallSensor sensor = HallSensor(2, 3, 4, 14);

// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}


void setup() {
// monitoring port
Serial.begin(115200);
Expand All @@ -29,8 +22,6 @@ void setup() {

// initialise encoder hardware
sensor.init();
// hardware interrupt enable
sensor.enableInterrupts(doA, doB, doC);

Serial.println("Sensor ready");
_delay(1000);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Hall sensor example code
*
* This is a code intended to test the hall sensors connections and to demonstrate the hall sensor setup.
*
*/

#include <SimpleFOC.h>

// Hall sensor instance
// HallSensor(int hallA, int hallB , int cpr, int index)
// - hallA, hallB, hallC - HallSensor A, B and C pins
// - pp - pole pairs
HallSensor sensor = HallSensor(2, 3, 4, 14);

// Interrupt routine intialisation
// channel A and B callbacks
void doA(){sensor.handleA();}
void doB(){sensor.handleB();}
void doC(){sensor.handleC();}


void setup() {
// monitoring port
Serial.begin(115200);

// check if you need internal pullups
sensor.pullup = Pullup::USE_EXTERN;

// initialise encoder hardware
sensor.init();
// hardware interrupt enable
sensor.enableInterrupts(doA, doB, doC);

Serial.println("Sensor ready");
_delay(1000);
}

void loop() {
// iterative function updating the sensor internal variables
// it is usually called in motor.loopFOC()
sensor.update();
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
delay(100);
}
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.3
version=2.3.4
author=Simplefoc <[email protected]>
maintainer=Simplefoc <[email protected]>
sentence=A library demistifying FOC for BLDC motors
Expand Down
7 changes: 4 additions & 3 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ void BLDCMotor::linkDriver(BLDCDriver* _driver) {
}

// init hardware pins
void BLDCMotor::init() {
int BLDCMotor::init() {
if (!driver || !driver->initialized) {
motor_status = FOCMotorStatus::motor_init_failed;
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
return;
return 0;
}
motor_status = FOCMotorStatus::motor_initializing;
SIMPLEFOC_DEBUG("MOT: Init");
Expand Down Expand Up @@ -105,6 +105,7 @@ void BLDCMotor::init() {
enable();
_delay(500);
motor_status = FOCMotorStatus::motor_uncalibrated;
return 1;
}


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

// align current sense and the driver
exit_flag = current_sense->driverAlign(voltage_sensor_align);
exit_flag = current_sense->driverAlign(voltage_sensor_align, modulation_centered);
if(!exit_flag){
// error in current sense - phase either not measured or bad connection
SIMPLEFOC_DEBUG("MOT: Align error!");
Expand Down
Loading

0 comments on commit 4395c22

Please sign in to comment.