Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move setting target to start of move() #404 #405

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading