6
6
// - pp - pole pair number
7
7
// - R - motor phase resistance
8
8
// - KV - motor kv rating (rmp/v)
9
- StepperMotor::StepperMotor (int pp, float _R, float _KV)
9
+ // - L - motor phase inductance [H]
10
+ StepperMotor::StepperMotor (int pp, float _R, float _KV, float _inductance)
10
11
: FOCMotor()
11
12
{
12
13
// number od pole pairs
@@ -16,6 +17,8 @@ StepperMotor::StepperMotor(int pp, float _R, float _KV)
16
17
// save back emf constant KV = 1/K_bemf
17
18
// usually used rms
18
19
KV_rating = _KV*_SQRT2;
20
+ // save phase inductance
21
+ phase_inductance = _inductance;
19
22
20
23
// torque control type is voltage by default
21
24
// current and foc_current not supported yet
@@ -296,7 +299,9 @@ void StepperMotor::move(float new_target) {
296
299
if (!_isset (phase_resistance)) voltage.q = target; // if voltage torque control
297
300
else voltage.q = target*phase_resistance + voltage_bemf;
298
301
voltage.q = _constrain (voltage.q , -voltage_limit, voltage_limit);
299
- voltage.d = 0 ;
302
+ // set d-component (lag compensation if known inductance)
303
+ if (!_isset (phase_inductance)) voltage.d = 0 ;
304
+ else voltage.d = _constrain ( -target*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
300
305
break ;
301
306
case MotionControlType::angle:
302
307
// angle set point
@@ -309,7 +314,9 @@ void StepperMotor::move(float new_target) {
309
314
// use voltage if phase-resistance not provided
310
315
if (!_isset (phase_resistance)) voltage.q = current_sp;
311
316
else voltage.q = _constrain ( current_sp*phase_resistance + voltage_bemf , -voltage_limit, voltage_limit);
312
- voltage.d = 0 ;
317
+ // set d-component (lag compensation if known inductance)
318
+ if (!_isset (phase_inductance)) voltage.d = 0 ;
319
+ else voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
313
320
break ;
314
321
case MotionControlType::velocity:
315
322
// velocity set point
@@ -320,19 +327,21 @@ void StepperMotor::move(float new_target) {
320
327
// use voltage if phase-resistance not provided
321
328
if (!_isset (phase_resistance)) voltage.q = current_sp;
322
329
else voltage.q = _constrain ( current_sp*phase_resistance + voltage_bemf , -voltage_limit, voltage_limit);
323
- voltage.d = 0 ;
330
+ // set d-component (lag compensation if known inductance)
331
+ if (!_isset (phase_inductance)) voltage.d = 0 ;
332
+ else voltage.d = _constrain ( -current_sp*shaft_velocity*pole_pairs*phase_inductance, -voltage_limit, voltage_limit);
324
333
break ;
325
334
case MotionControlType::velocity_openloop:
326
335
// velocity control in open loop
327
336
shaft_velocity_sp = target;
328
337
voltage.q = velocityOpenloop (shaft_velocity_sp); // returns the voltage that is set to the motor
329
- voltage.d = 0 ;
338
+ voltage.d = 0 ; // TODO d-component lag-compensation
330
339
break ;
331
340
case MotionControlType::angle_openloop:
332
341
// angle control in open loop
333
342
shaft_angle_sp = target;
334
343
voltage.q = angleOpenloop (shaft_angle_sp); // returns the voltage that is set to the motor
335
- voltage.d = 0 ;
344
+ voltage.d = 0 ; // TODO d-component lag-compensation
336
345
break ;
337
346
}
338
347
}
0 commit comments