@@ -216,13 +216,14 @@ int StepperMotor::absoluteZeroSearch() {
216216// Iterative function looping FOC algorithm, setting Uq on the Motor
217217// The faster it can be run the better
218218void StepperMotor::loopFOC () {
219- // if disabled do nothing
220- if (!enabled) return ;
221219 // if open-loop do nothing
222220 if ( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return ;
223-
224221 // shaft angle
225222 shaft_angle = shaftAngle ();
223+
224+ // if disabled do nothing
225+ if (!enabled) return ;
226+
226227 electrical_angle = electricalAngle ();
227228
228229 // set the phase voltage - FOC heart function :)
@@ -235,15 +236,15 @@ void StepperMotor::loopFOC() {
235236// - needs to be called iteratively it is asynchronous function
236237// - if target is not set it uses motor.target value
237238void StepperMotor::move (float new_target) {
239+ // get angular velocity
240+ shaft_velocity = shaftVelocity ();
238241 // if disabled do nothing
239242 if (!enabled) return ;
240243 // downsampling (optional)
241244 if (motion_cnt++ < motion_downsample) return ;
242245 motion_cnt = 0 ;
243246 // set internal target variable
244247 if (_isset (new_target) ) target = new_target;
245- // get angular velocity
246- shaft_velocity = shaftVelocity ();
247248 // choose control loop
248249 switch (controller) {
249250 case MotionControlType::torque:
0 commit comments