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

[BUG] Passing a new target to move() is sometimes ignored #404

Closed
sylque opened this issue Jun 5, 2024 · 5 comments · Fixed by #405
Closed

[BUG] Passing a new target to move() is sometimes ignored #404

sylque opened this issue Jun 5, 2024 · 5 comments · Fixed by #405
Assignees
Labels
bug Something isn't working
Milestone

Comments

@sylque
Copy link

sylque commented Jun 5, 2024

In BLDCMotor::move(), if you pass a new target as a parameter, it is sometimes ignored.

This is due to this code being at the wrong place. I think it should be placed at the very top of the function.

Indeed, if either (motion_cnt++ < motion_downsample) or (!enabled), the new_target parameter is ignored.

@runger1101001
Copy link
Member

You're right... no one has ever reported this before, I think because it is generally assumed that you either

  • always pass the target value to the move function
  • or never pass the target value via move, and instead just set motor.target

To see the bug you're experiencing you must be passing the value sometimes, and sometimes not. As a workaround, I suggest just using motor.target = x; to change the target, rather than using the move function.

In the next release, I think we'll probably place the target setting at the top of the function like you suggest to solve this edge case.

In a future version of the API, I would remove the parameter to move() completely, as the semantics are confusing, and either just setting the member field directly or using a setter function like motor.setTarget() would be clearer, I feel.

@runger1101001 runger1101001 added bug Something isn't working and removed possible bug labels Jun 5, 2024
@runger1101001 runger1101001 self-assigned this Jun 5, 2024
@runger1101001 runger1101001 added this to the 2.3.4_Release milestone Jun 5, 2024
runger1101001 added a commit to runger1101001/Arduino-FOC that referenced this issue Jun 5, 2024
runger1101001 added a commit that referenced this issue Jun 5, 2024
move setting target to start of move() #404
@runger1101001
Copy link
Member

Solved for BLDCMotor, StepperMotor and HybridStepperMotor (drivers repository). DCMotor was not affected.

Merged to dev branch.

@runger1101001 runger1101001 linked a pull request Jun 5, 2024 that will close this issue
@sylque
Copy link
Author

sylque commented Jun 5, 2024

In a future version of the API, I would remove the parameter to move() completely, as the semantics are confusing

Agreed.

@askuric
Copy link
Member

askuric commented Jun 6, 2024

Thanks for this. This one is an old and sneaky one!

The parameter for move was the initial way to set the target value. We have pivoted from this paradigm some time ago with the motor.target. The parameter to move stayed no to break the API at first. And it stayed a bit too long :D

@askuric
Copy link
Member

askuric commented Jul 22, 2024

In the new release v2.3.4

@askuric askuric closed this as completed Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants