@@ -216,13 +216,14 @@ int StepperMotor::absoluteZeroSearch() {
216
216
// Iterative function looping FOC algorithm, setting Uq on the Motor
217
217
// The faster it can be run the better
218
218
void StepperMotor::loopFOC () {
219
- // if disabled do nothing
220
- if (!enabled) return ;
221
219
// if open-loop do nothing
222
220
if ( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return ;
223
-
224
221
// shaft angle
225
222
shaft_angle = shaftAngle ();
223
+
224
+ // if disabled do nothing
225
+ if (!enabled) return ;
226
+
226
227
electrical_angle = electricalAngle ();
227
228
228
229
// set the phase voltage - FOC heart function :)
@@ -235,15 +236,15 @@ void StepperMotor::loopFOC() {
235
236
// - needs to be called iteratively it is asynchronous function
236
237
// - if target is not set it uses motor.target value
237
238
void StepperMotor::move (float new_target) {
239
+ // get angular velocity
240
+ shaft_velocity = shaftVelocity ();
238
241
// if disabled do nothing
239
242
if (!enabled) return ;
240
243
// downsampling (optional)
241
244
if (motion_cnt++ < motion_downsample) return ;
242
245
motion_cnt = 0 ;
243
246
// set internal target variable
244
247
if (_isset (new_target) ) target = new_target;
245
- // get angular velocity
246
- shaft_velocity = shaftVelocity ();
247
248
// choose control loop
248
249
switch (controller) {
249
250
case MotionControlType::torque:
0 commit comments