Skip to content

Release v2.3.1 #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 79 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
c857bd8
make foc_utils functions WEAK
Mar 21, 2023
d752f29
seems the WEAK macro isn't declared on all archs
Mar 21, 2023
1010207
fix RP2040 ADCEngine stop - #259
Mar 21, 2023
3f57ef9
Merge pull request #263 from runger1101001/dev
runger1101001 Mar 21, 2023
e72db3f
Merge pull request #262 from runger1101001/sine_optimisations
runger1101001 Mar 22, 2023
fddf80c
add overflow check to STM32 HW dead-time calc
Mar 30, 2023
5e274ad
add check for dead-time overflow on STM32
Mar 30, 2023
4c8ea20
Merge pull request #265 from runger1101001/dev
runger1101001 Mar 30, 2023
df5f6de
inital implementation of the velocity feed forward
askuric Mar 31, 2023
b12be53
fix micros overflow error in Sensor.cpp
May 12, 2023
3bb05d0
Simplify HW-dependent define
May 12, 2023
9b68c8e
fix [BUG] RP2040 ADC Engine #264
May 12, 2023
95bb2c3
fix SAMD compile error
May 12, 2023
55debc4
change NOT_SET to float type
May 12, 2023
5e35fb8
Fix for issue #270
dekutree64 May 22, 2023
98a10e4
Reduced interrupt blocking time
dekutree64 May 22, 2023
b03f8a9
Forgot to remove function headers
dekutree64 May 22, 2023
99b3f9d
teensy 3 and 4 bugfix for 6pwm, forgotten PhaseState parameter
askuric May 25, 2023
510527a
Merge pull request #276 from dekutree64/dev
runger1101001 May 25, 2023
2fcc55d
Merge pull request #271 from runger1101001/dev
runger1101001 May 25, 2023
ae5accb
extend RP2040 PWM to support low speeds
runger1101001 May 30, 2023
3cee9cf
make isSentinel useable for other code
Jun 1, 2023
fa637de
RP2040 PWM driver now supports pre-scaler
Jun 1, 2023
ca541b7
Merge pull request #277 from runger1101001/dev
runger1101001 Jun 1, 2023
505248c
move default sample rate to header
Jun 18, 2023
5fc3128
fix KV initialization bug
Jun 24, 2023
33a381d
Merge pull request #280 from runger1101001/dev
runger1101001 Jun 24, 2023
1496e51
make Commander work with \r also
Jun 24, 2023
d57d32d
change sensor_direction from int to Direction
Jun 24, 2023
5231e5e
change init logic - remove params from initFOC
Jun 24, 2023
10c5b87
update example for new init logic
Jun 24, 2023
922ee50
Merge pull request #283 from runger1101001/dev
runger1101001 Jun 29, 2023
375c36f
change sine implementation to deku65i version
Jun 29, 2023
78fd21e
add currWireError to I2C sensor
padok Jul 1, 2023
aef77f9
Merge pull request #285 from runger1101001/dev
runger1101001 Jul 1, 2023
b2efa9c
fix addition error, thanks to nano for finding it!
Jul 2, 2023
4ed0be7
Merge pull request #288 from runger1101001/dev
runger1101001 Jul 2, 2023
dfa64dc
Readme - add dev branch pull request hint
padok Jul 3, 2023
4b37d87
Merge branch 'dev' of github.com:simplefoc/Arduino-FOC
Jul 3, 2023
071a98d
UNO R4 boards define PinStatus
Jul 5, 2023
83597c1
Initial PWM support for Renesas R4M1 MCUs (UNO R4)
Jul 5, 2023
ca129fd
add ESP32 output inversion support
mcells Jun 30, 2023
787cb15
software 6-PWM is working
Jul 6, 2023
57be301
hardware 6-PWM is working
Jul 6, 2023
8010c3d
clean up polarity
Jul 6, 2023
4351a6c
Renesas PWM phase state setting support
Jul 7, 2023
52885d1
Merge pull request #290 from mcells/esp32-pin-inversion
runger1101001 Jul 7, 2023
b8cd3b9
Merge pull request #286 from padok/master
runger1101001 Jul 7, 2023
b38ab40
Merge pull request #289 from runger1101001/dev
runger1101001 Jul 7, 2023
bb001e9
prepare README for next release
Jul 7, 2023
0595b9f
fix bug in new sine for 8 bit machines
Jul 11, 2023
c4b911d
Merge pull request #291 from runger1101001/dev
runger1101001 Jul 11, 2023
b3f2e96
initialize sensor direction open vs. closed loop
Jul 31, 2023
012608c
fix typo
Jul 31, 2023
451be63
Merge pull request #297 from runger1101001/dev
runger1101001 Jul 31, 2023
dbc28d4
nrf52 compile error fixed
Aug 20, 2023
a163d14
esp32 nano insists on 3 parameters for pulseIn
Aug 21, 2023
7d3dbd8
make compatible with Nano ESP32 platform
Aug 21, 2023
6efd126
use new version of header file
Aug 21, 2023
3dcb7e8
prevent compile errors when LEDC is forced
Aug 21, 2023
6372a50
add MEGAAVR to archs which define PinStatus
Aug 29, 2023
a5ecace
add compiler message which driver gets compiled
Aug 29, 2023
574ce63
Add ESP32 Phasestate with sw-deadtime
mcells Sep 2, 2023
04a8a88
Merge pull request #299 from runger1101001/dev
runger1101001 Sep 2, 2023
2252605
fix errors and warnings on SIMPLEFOC_DISABLE_DEBUG
Sep 2, 2023
4690e16
Merge pull request #303 from runger1101001/dev
runger1101001 Sep 2, 2023
5bbba0c
added comments for reverse direction #254
Sep 3, 2023
b54827b
ESP32: Use hw-deadtime by default
mcells Sep 7, 2023
5029fc7
Merge pull request #305 from mcells/esp32-phasestate
runger1101001 Sep 10, 2023
1ca4c76
Merge branch 'simplefoc:dev' into dev
runger1101001 Sep 10, 2023
7677c85
swap pow() function for _powtwo()
runger1101001 Sep 10, 2023
5ef4d9d
add some checks to current-sense init
runger1101001 Sep 12, 2023
132e7b0
mark param unused
runger1101001 Sep 12, 2023
c99cc6d
update README
Sep 17, 2023
fb88707
renesas small fixes
Sep 17, 2023
e543cd2
Merge branch 'dev' of github.com:runger1101001/Arduino-FOC into dev
Sep 17, 2023
74a8464
Merge pull request #304 from runger1101001/dev
runger1101001 Sep 21, 2023
0182f2f
update README for release
Sep 21, 2023
192ab76
Merge pull request #313 from runger1101001/dev
runger1101001 Sep 21, 2023
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
48 changes: 18 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,20 @@ Therefore this is an attempt to:
- *Medium-power* BLDC driver (<30Amps): [Arduino <span class="simple">Simple<b>FOC</b>PowerShield</span> ](https://github.com/simplefoc/Arduino-SimpleFOC-PowerShield).
- See also [@byDagor](https://github.com/byDagor)'s *fully-integrated* ESP32 based board: [Dagor Brushless Controller](https://github.com/byDagor/Dagor-Brushless-Controller)

> NEW RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.0
> - Arduino Mega 6pwm more timers supported
> - Arduino boards - frequency change support either 32kHz or 4kHz
> - Arduino Uno - synched timers in 3pwm and 6pwm mode [#71](https://github.com/simplefoc/Arduino-FOC/issues/71)
> - Teensy 3.x initial support for 6pwm
> - Teensy 4.x initial support for 6pwm
> - Example for v3.1 SimpleFOCShield
> - RP2040 compatibility for earlehillpower core [#234](https://github.com/simplefoc/Arduino-FOC/pull/234) [#236](https://github.com/simplefoc/Arduino-FOC/pull/236)
> - More flexible monitoring API
> - start, end and separator characters
> - decimal places (settable through commander)
> - Added machine readable verbose mode in `Commander` [#233](https://github.com/simplefoc/Arduino-FOC/pull/233)
> - *Simple**FOC**WebController* - Web based user interface for SimpleFOC by [@geekuillaume](https://github.com/geekuillaume) - [webcontroller.simplefoc.com](webcontroller.simplefoc.com)
> - bugfix - `MagneticSensorPWM` multiple occasions - [#258](https://github.com/simplefoc/Arduino-FOC/pull/258)
> - bugfix - current sense align - added offset exchange when exchanging pins
> - bugfix - trapezoid 150 fixed
> - bugfix - 4pwm on ESP8266 [#224](https://github.com/simplefoc/Arduino-FOC/pull/224)
> - Additional `InlineCurrentSense` and `LowsideCurrentSense` constructor using milliVolts per Amp [#253](https://github.com/simplefoc/Arduino-FOC/pull/253)
> - STM32L4xx current sense support by [@Triple6](https://github.com/Triple6) (discord) [#257](https://github.com/simplefoc/Arduino-FOC/pull/257)
> - phase disable in 6pwm mode
> - stm32 - software and hardware 6pwm
> - atmega328
> - atmega2560
> - Lag compensation using motor inductance [#246](https://github.com/simplefoc/Arduino-FOC/issues/246)
> - current control through voltage torque mode enhancement
> - extended `BLDCMotor` and `StepperMotor` constructors to receive the inductance paramerer
> - can also be set using `motor.phase_inductance` or through `Commander`
## Arduino *SimpleFOClibrary* v2.3
> NEW RELEASE 📢 : <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.3.1
> - Support for Arduino UNO R4 Minima (Renesas R7FA4M1 MCU - note UNO R4 WiFi is not yet supported)
> - Support setting PWM polarity on ESP32 (thanks to [@mcells](https://github.com/mcells))
> - Expose I2C errors in MagneticSensorI2C (thanks to [@padok](https://github.com/padok))
> - Improved default trig functions (sine, cosine) - faster, smaller
> - Overridable trig functions - plug in your own optimized versions
> - Bugfix: microseconds overflow in velocity mode [#287](https://github.com/simplefoc/Arduino-FOC/issues/287)
> - Bugfix: KV initialization ([5fc3128](https://github.com/simplefoc/Arduino-FOC/commit/5fc3128d282b65c141ca486327c6235089999627))
> - And more bugfixes - see the [complete list of 2.3.1 fixes here](https://github.com/simplefoc/Arduino-FOC/issues?q=is%3Aissue+milestone%3A2.3.1_Release)
> - Change: simplify initFOC() API ([d57d32d](https://github.com/simplefoc/Arduino-FOC/commit/d57d32dd8715dbed4e476469bc3de0c052f1d531). [5231e5e](https://github.com/simplefoc/Arduino-FOC/commit/5231e5e1d044b0cc33ede67664b6ef2f9d0a8cdf), [10c5b87](https://github.com/simplefoc/Arduino-FOC/commit/10c5b872672cab72df16ddd738bbf09bcce95d28))
> - Change: check for linked driver in currentsense and exit gracefully ([5ef4d9d](https://github.com/simplefoc/Arduino-FOC/commit/5ef4d9d5a92e03da0dd5af7f624243ab30f1b688))
> - Compatibility with newest versions of Arduino framework for STM32, Renesas, ESP32, Atmel SAM, Atmel AVR, nRF52 and RP2040

## Arduino *SimpleFOClibrary* v2.3.1

<p align="">
<a href="https://youtu.be/Y5kLeqTc6Zk">
Expand All @@ -78,7 +64,7 @@ This video demonstrates the *Simple**FOC**library* basic usage, electronic conne
- **Cross-platform**:
- Seamless code transfer from one microcontroller family to another
- Supports multiple [MCU architectures](https://docs.simplefoc.com/microcontrollers):
- Arduino: UNO, MEGA, DUE, Leonardo ....
- Arduino: UNO R4, UNO, MEGA, DUE, Leonardo, Nano, Nano33 ....
- STM32
- ESP32
- Teensy
Expand Down Expand Up @@ -132,7 +118,9 @@ Please do not hesitate to leave an issue if you have problems/advices/suggestion

Pull requests are welcome, but let's first discuss them in [community forum](https://community.simplefoc.com)!

If you'd like to contribute to this porject but you are not very familiar with github, don't worry, let us know either by posting at the community forum , by posting a github issue or at our discord server.
If you'd like to contribute to this project but you are not very familiar with github, don't worry, let us know either by posting at the community forum , by posting a github issue or at our discord server.

If you are familiar, we accept pull requests to the dev branch!

## Arduino code example
This is a simple Arduino code example implementing the velocity control program of a BLDC motor with encoder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void setup() {
void loop() {
// open loop angle movements
// using motor.voltage_limit and motor.velocity_limit
// angles can be positive or negative, negative angles correspond to opposite motor direction
motor.move(target_position);

// user communication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void loop() {

// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
// to turn the motor "backwards", just set a negative target_velocity
motor.move(target_velocity);

// user communication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
* Simple example intended to help users find the zero offset and natural direction of the sensor.
*
* These values can further be used to avoid motor and sensor alignment procedure.
*
* motor.initFOC(zero_offset, sensor_direction);
* To use these values add them to the code:");
* motor.sensor_direction=Direction::CW; // or Direction::CCW
* motor.zero_electric_angle=1.2345; // use the real value!
*
* This will only work for abosolute value sensors - magnetic sensors.
* Bypassing the alignment procedure is not possible for the encoders and for the current implementation of the Hall sensors.
Expand Down Expand Up @@ -44,6 +45,9 @@ void setup() {
// set motion control loop to be used
motor.controller = MotionControlType::torque;

// force direction search - because default is CW
motor.sensor_direction = Direction::UNKNOWN;

// initialize motor
motor.init();
// align sensor and start FOC
Expand All @@ -54,9 +58,16 @@ void setup() {
Serial.println("Sensor zero offset is:");
Serial.println(motor.zero_electric_angle, 4);
Serial.println("Sensor natural direction is: ");
Serial.println(motor.sensor_direction == 1 ? "Direction::CW" : "Direction::CCW");
Serial.println(motor.sensor_direction == Direction::CW ? "Direction::CW" : "Direction::CCW");

Serial.println("To use these values add them to the code:");
Serial.print(" motor.sensor_direction=");
Serial.print(motor.sensor_direction == Direction::CW ? "Direction::CW" : "Direction::CCW");
Serial.println(";");
Serial.print(" motor.zero_electric_angle=");
Serial.print(motor.zero_electric_angle, 4);
Serial.println(";");

Serial.println("To use these values provide them to the: motor.initFOC(offset, direction)");
_delay(1000);
Serial.println("If motor is not moving the alignment procedure was not successfull!!");
}
Expand Down
44 changes: 22 additions & 22 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ BLDCMotor::BLDCMotor(int pp, float _R, float _KV, float _inductance)
phase_resistance = _R;
// save back emf constant KV = 1/KV
// 1/sqrt(2) - rms value
KV_rating = _KV*_SQRT2;
KV_rating = NOT_SET;
if (_isset(_KV))
KV_rating = _KV*_SQRT2;
// save phase inductance
phase_inductance = _inductance;

Expand Down Expand Up @@ -90,6 +92,13 @@ void 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;
}

_delay(500);
// enable motor
SIMPLEFOC_DEBUG("MOT: Enable driver.");
Expand Down Expand Up @@ -124,20 +133,13 @@ void BLDCMotor::enable()
FOC functions
*/
// FOC initialization function
int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction) {
int BLDCMotor::initFOC() {
int exit_flag = 1;

motor_status = FOCMotorStatus::motor_calibrating;

// align motor if necessary
// alignment necessary for encoders!
if(_isset(zero_electric_offset)){
// abosolute zero offset provided - no need to align
zero_electric_angle = zero_electric_offset;
// set the sensor direction - default CW
sensor_direction = _sensor_direction;
}

// sensor and motor alignment - can be skipped
// by setting motor.sensor_direction and motor.zero_electric_angle
_delay(500);
Expand Down Expand Up @@ -165,7 +167,7 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
exit_flag *= alignCurrentSense();
}
}
else SIMPLEFOC_DEBUG("MOT: No current sense.");
else { SIMPLEFOC_DEBUG("MOT: No current sense."); }
}

if(exit_flag){
Expand Down Expand Up @@ -211,7 +213,7 @@ int BLDCMotor::alignSensor() {
if(!exit_flag) return exit_flag;

// if unknown natural direction
if(!_isset(sensor_direction)){
if(sensor_direction==Direction::UNKNOWN){

// find natural direction
// move one electrical revolution forward
Expand Down Expand Up @@ -250,10 +252,11 @@ int BLDCMotor::alignSensor() {
// check pole pair number
if( fabs(moved*pole_pairs - _2PI) > 0.5f ) { // 0.5f is arbitrary number it can be lower or higher!
SIMPLEFOC_DEBUG("MOT: PP check: fail - estimated pp: ", _2PI/moved);
} else
} else {
SIMPLEFOC_DEBUG("MOT: PP check: OK!");
}

} else SIMPLEFOC_DEBUG("MOT: Skip dir calib.");
} else { SIMPLEFOC_DEBUG("MOT: Skip dir calib."); }

// zero electric angle not known
if(!_isset(zero_electric_angle)){
Expand All @@ -274,7 +277,7 @@ int BLDCMotor::alignSensor() {
// stop everything
setPhaseVoltage(0, 0, 0);
_delay(200);
}else SIMPLEFOC_DEBUG("MOT: Skip offset calib.");
} else { SIMPLEFOC_DEBUG("MOT: Skip offset calib."); }
return exit_flag;
}

Expand Down Expand Up @@ -303,8 +306,8 @@ int BLDCMotor::absoluteZeroSearch() {
voltage_limit = limit_volt;
// check if the zero found
if(monitor_port){
if(sensor->needsSearch()) SIMPLEFOC_DEBUG("MOT: Error: Not found!");
else SIMPLEFOC_DEBUG("MOT: Success!");
if(sensor->needsSearch()) { SIMPLEFOC_DEBUG("MOT: Error: Not found!"); }
else { SIMPLEFOC_DEBUG("MOT: Success!"); }
}
return !sensor->needsSearch();
}
Expand Down Expand Up @@ -418,7 +421,8 @@ void BLDCMotor::move(float new_target) {
// angle set point
shaft_angle_sp = target;
// calculate velocity set point
shaft_velocity_sp = P_angle( shaft_angle_sp - shaft_angle );
shaft_velocity_sp = feed_forward_velocity + P_angle( shaft_angle_sp - shaft_angle );
shaft_angle_sp = _constrain(shaft_angle_sp,-velocity_limit, velocity_limit);
// calculate the torque command - sensor precision: this calculation is ok, but based on bad value from previous calculation
current_sp = PID_velocity(shaft_velocity_sp - shaft_velocity); // if voltage torque control
// if torque controlled through voltage
Expand Down Expand Up @@ -543,12 +547,8 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
case FOCModulationType::SinePWM :
// Sinusoidal PWM modulation
// Inverse Park + Clarke transformation
_sincos(angle_el, &_sa, &_ca);

// angle normalization in between 0 and 2pi
// only necessary if using _sin and _cos - approximation functions
angle_el = _normalizeAngle(angle_el);
_ca = _cos(angle_el);
_sa = _sin(angle_el);
// Inverse park transform
Ualpha = _ca * Ud - _sa * Uq; // -sin(angle) * Uq;
Ubeta = _sa * Ud + _ca * Uq; // cos(angle) * Uq;
Expand Down
2 changes: 1 addition & 1 deletion src/BLDCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class BLDCMotor: public FOCMotor
* Function initializing FOC algorithm
* and aligning sensor's and motors' zero position
*/
int initFOC( float zero_electric_offset = NOT_SET , Direction sensor_direction = Direction::CW) override;
int initFOC() override;
/**
* Function running FOC algorithm in real-time
* it calculates the gets motor angle and sets the appropriate voltages
Expand Down
39 changes: 20 additions & 19 deletions src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ void StepperMotor::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;
}

_delay(500);
// enable motor
SIMPLEFOC_DEBUG("MOT: Enable driver.");
Expand Down Expand Up @@ -92,20 +99,13 @@ void StepperMotor::enable()
FOC functions
*/
// FOC initialization function
int StepperMotor::initFOC( float zero_electric_offset, Direction _sensor_direction ) {
int StepperMotor::initFOC() {
int exit_flag = 1;

motor_status = FOCMotorStatus::motor_calibrating;

// align motor if necessary
// alignment necessary for encoders!
if(_isset(zero_electric_offset)){
// abosolute zero offset provided - no need to align
zero_electric_angle = zero_electric_offset;
// set the sensor direction - default CW
sensor_direction = _sensor_direction;
}

// sensor and motor alignment - can be skipped
// by setting motor.sensor_direction and motor.zero_electric_angle
_delay(500);
Expand All @@ -114,7 +114,7 @@ int StepperMotor::initFOC( float zero_electric_offset, Direction _sensor_direct
// added the shaft_angle update
sensor->update();
shaft_angle = sensor->getAngle();
}else SIMPLEFOC_DEBUG("MOT: No sensor.");
} else { SIMPLEFOC_DEBUG("MOT: No sensor."); }

if(exit_flag){
SIMPLEFOC_DEBUG("MOT: Ready.");
Expand Down Expand Up @@ -177,10 +177,13 @@ int StepperMotor::alignSensor() {
float moved = fabs(mid_angle - end_angle);
if( fabs(moved*pole_pairs - _2PI) > 0.5f ) { // 0.5f is arbitrary number it can be lower or higher!
SIMPLEFOC_DEBUG("MOT: PP check: fail - estimated pp: ", _2PI/moved);
} else
} else {
SIMPLEFOC_DEBUG("MOT: PP check: OK!");
}

}else SIMPLEFOC_DEBUG("MOT: Skip dir calib.");
} else {
SIMPLEFOC_DEBUG("MOT: Skip dir calib.");
}

// zero electric angle not known
if(!_isset(zero_electric_angle)){
Expand All @@ -200,7 +203,7 @@ int StepperMotor::alignSensor() {
// stop everything
setPhaseVoltage(0, 0, 0);
_delay(200);
}else SIMPLEFOC_DEBUG("MOT: Skip offset calib.");
} else { SIMPLEFOC_DEBUG("MOT: Skip offset calib."); }
return exit_flag;
}

Expand Down Expand Up @@ -229,7 +232,7 @@ int StepperMotor::absoluteZeroSearch() {
// check if the zero found
if(monitor_port){
if(sensor->needsSearch()) SIMPLEFOC_DEBUG("MOT: Error: Not found!");
else SIMPLEFOC_DEBUG("MOT: Success!");
else { SIMPLEFOC_DEBUG("MOT: Success!"); }
}
return !sensor->needsSearch();
}
Expand Down Expand Up @@ -307,7 +310,8 @@ void StepperMotor::move(float new_target) {
// angle set point
shaft_angle_sp = target;
// calculate velocity set point
shaft_velocity_sp = P_angle( shaft_angle_sp - shaft_angle );
shaft_velocity_sp = feed_forward_velocity + P_angle( shaft_angle_sp - shaft_angle );
shaft_angle_sp = _constrain(shaft_angle_sp, -velocity_limit, velocity_limit);
// calculate the torque command
current_sp = PID_velocity(shaft_velocity_sp - shaft_velocity); // if voltage torque control
// if torque controlled through voltage
Expand Down Expand Up @@ -357,12 +361,9 @@ void StepperMotor::move(float new_target) {
void StepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
// Sinusoidal PWM modulation
// Inverse Park transformation
float _sa, _ca;
_sincos(angle_el, &_sa, &_ca);

// angle normalization in between 0 and 2pi
// only necessary if using _sin and _cos - approximation functions
angle_el = _normalizeAngle(angle_el);
float _ca = _cos(angle_el);
float _sa = _sin(angle_el);
// Inverse park transform
Ualpha = _ca * Ud - _sa * Uq; // -sin(angle) * Uq;
Ubeta = _sa * Ud + _ca * Uq; // cos(angle) * Uq;
Expand Down
6 changes: 1 addition & 5 deletions src/StepperMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,8 @@ class StepperMotor: public FOCMotor
* and aligning sensor's and motors' zero position
*
* - If zero_electric_offset parameter is set the alignment procedure is skipped
*
* @param zero_electric_offset value of the sensors absolute position electrical offset in respect to motor's electrical 0 position.
* @param sensor_direction sensor natural direction - default is CW
*
*/
int initFOC( float zero_electric_offset = NOT_SET , Direction sensor_direction = Direction::CW) override;
int initFOC() override;
/**
* Function running FOC algorithm in real-time
* it calculates the gets motor angle and sets the appropriate voltages
Expand Down
Loading