Skip to content

Commit 271de7d

Browse files
committed
Update StepperMotor.cpp
1 parent ced13e3 commit 271de7d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/StepperMotor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ float wrap_to_1(float x) {
399399
}
400400
return x;
401401
}
402-
402+
/// @runger();
403+
/// @brief
404+
/// @param Uq
405+
/// @param Ud
406+
/// @param angle_el
403407
void StepperMotor::setPhaseVoltageCORDIC(float Uq, float Ud, float angle_el) {
404408
// Sinusoidal PWM modulation
405409
// Inverse Park transformation
@@ -415,20 +419,20 @@ cordic_cosine = CORDIC->RDATA;
415419
value_f32_sine = (float)cordic_sine/(float)0x80000000;
416420
value_f32_cosine = (float)cordic_cosine/(float)0x80000000;
417421

418-
if (angle < 0){
422+
if (angle_el < 0){
419423
value_f32_sine = wrap_to_1(value_f32_sine);
420424
value_f32_sine = value_f32_sine * -1;
421425
}
422426

423-
if (angle > 0){
427+
if (angle_el > 0){
424428
value_f32_sine = wrap_to_1(value_f32_sine);
425429
}
426430

427431
value_f32_cosine = wrap_to_1(value_f32_cosine);
428432

429433
// Inverse park transform
430-
Ualpha = value_f32_cosine * Ud - cordic_sine * Uq; // -sin(angle) * Uq;
431-
Ubeta = cordic_sine * Ud + value_f32_cosine * Uq; // cos(angle) * Uq;
434+
Ualpha = value_f32_cosine * Ud - value_f32_sine * Uq; // -sin(angle) * Uq;
435+
Ubeta = value_f32_sine * Ud + value_f32_cosine * Uq; // cos(angle) * Uq;
432436

433437
// set the voltages in hardware
434438
driver->setPwm(Ualpha, Ubeta);

0 commit comments

Comments
 (0)