Skip to content
Open
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions src/HybridStepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ float HybridStepperMotor::estimateBEMF(float vel){
// Function implementing Sine PWM and SVPWM algorithms
void HybridStepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el)
{
float center;
const float center = fminf(driver->voltage_power_supply, driver->voltage_limit) / 2;
float _sa, _ca;

_sincos(angle_el, &_sa, &_ca);
Expand All @@ -152,8 +152,6 @@ void HybridStepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el)
Ua = (_ca * Ud) - (_sa * Uq);
Ub = (_sa * Ud) + (_ca * Uq);

center = driver->voltage_limit / 2;

Ua += center;
Ub += center;
Uc = center;
Expand All @@ -164,9 +162,9 @@ void HybridStepperMotor::setPhaseVoltage(float Uq, float Ud, float angle_el)
Ua = (_ca * Ud) - (_sa * Uq);
Ub = (_sa * Ud) + (_ca * Uq);

float Umin = fmin(fmin(Ua, Ub), 0);
float Umax = fmax(fmax(Ua, Ub), 0);
float Vo = -(Umin + Umax)/2 + driver->voltage_limit/2;
const float Umin = fminf(fminf(Ua, Ub), 0);
const float Umax = fmaxf(fmaxf(Ua, Ub), 0);
const float Vo = center - (Umin + Umax) / 2;

Ua = Ua + Vo;
Ub = Ub + Vo;
Expand Down
Loading