Skip to content

Commit 602c668

Browse files
committed
move setting target to start of move() #404
1 parent 627c0a8 commit 602c668

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/BLDCMotor.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ void BLDCMotor::loopFOC() {
393393
// - if target is not set it uses motor.target value
394394
void BLDCMotor::move(float new_target) {
395395

396+
// set internal target variable
397+
if(_isset(new_target)) target = new_target;
398+
396399
// downsampling (optional)
397400
if(motion_cnt++ < motion_downsample) return;
398401
motion_cnt = 0;
@@ -410,8 +413,6 @@ void BLDCMotor::move(float new_target) {
410413

411414
// if disabled do nothing
412415
if(!enabled) return;
413-
// set internal target variable
414-
if(_isset(new_target)) target = new_target;
415416

416417
// calculate the back-emf voltage if KV_rating available U_bemf = vel*(1/KV)
417418
if (_isset(KV_rating)) voltage_bemf = shaft_velocity/(KV_rating*_SQRT3)/_RPM_TO_RADS;

src/StepperMotor.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ void StepperMotor::loopFOC() {
283283
// - if target is not set it uses motor.target value
284284
void StepperMotor::move(float new_target) {
285285

286+
// set internal target variable
287+
if(_isset(new_target) ) target = new_target;
288+
286289
// downsampling (optional)
287290
if(motion_cnt++ < motion_downsample) return;
288291
motion_cnt = 0;
@@ -301,8 +304,6 @@ void StepperMotor::move(float new_target) {
301304
// if disabled do nothing
302305
if(!enabled) return;
303306

304-
// set internal target variable
305-
if(_isset(new_target) ) target = new_target;
306307

307308
// calculate the back-emf voltage if KV_rating available U_bemf = vel*(1/KV)
308309
if (_isset(KV_rating)) voltage_bemf = shaft_velocity/(KV_rating*_SQRT3)/_RPM_TO_RADS;

0 commit comments

Comments
 (0)