Skip to content

Commit

Permalink
Merge pull request #405 from runger1101001/dev
Browse files Browse the repository at this point in the history
move setting target to start of move() #404
  • Loading branch information
runger1101001 authored Jun 5, 2024
2 parents 492d147 + 602c668 commit ac640e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/BLDCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ void BLDCMotor::loopFOC() {
// - if target is not set it uses motor.target value
void BLDCMotor::move(float new_target) {

// set internal target variable
if(_isset(new_target)) target = new_target;

// downsampling (optional)
if(motion_cnt++ < motion_downsample) return;
motion_cnt = 0;
Expand All @@ -410,8 +413,6 @@ void BLDCMotor::move(float new_target) {

// if disabled do nothing
if(!enabled) return;
// set internal target variable
if(_isset(new_target)) target = new_target;

// calculate the back-emf voltage if KV_rating available U_bemf = vel*(1/KV)
if (_isset(KV_rating)) voltage_bemf = shaft_velocity/(KV_rating*_SQRT3)/_RPM_TO_RADS;
Expand Down
5 changes: 3 additions & 2 deletions src/StepperMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ void StepperMotor::loopFOC() {
// - if target is not set it uses motor.target value
void StepperMotor::move(float new_target) {

// set internal target variable
if(_isset(new_target) ) target = new_target;

// downsampling (optional)
if(motion_cnt++ < motion_downsample) return;
motion_cnt = 0;
Expand All @@ -301,8 +304,6 @@ void StepperMotor::move(float new_target) {
// if disabled do nothing
if(!enabled) return;

// set internal target variable
if(_isset(new_target) ) target = new_target;

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

0 comments on commit ac640e1

Please sign in to comment.