-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Add latch functionality for stepper motor control #80110
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
Conversation
This commit introduces the latch functionality for stepper motors in the Zephyr motor driver framework. The latch feature allows the motor to hold its position after completing a movement, which is useful in applications that require precise position control without losing steps due to external forces. Changes include: - Added the `stepper_set_latch()` function to configure whether the motor should latch (hold position) after movement. - Added the `stepper_is_latch()` function to check the current latch configuration. - Updated the stepper driver API to support latch control. This functionality helps maintain the motor's position after movement, preventing unwanted drift when the motor is not in active movement. However, latching consumes more power as it keeps current flowing through the motor windings.
|
Hello @henrycoding, and thank you very much for your first pull request to the Zephyr project! |
jilaypandya
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @henrycoding ,
Thanks for contributing to the project. If i understand correctly you want the motor to hold the position, or?
So this would be opposite to freewheeling. In normal operation a motor shall always hold the position once it has reached it. However, one would explicitly want to enable freewheeling i.e. in standstill mode the motor shall be movable with or without some kind of passive braking.
Ain't the stepper holding its position with in-tree implementation of the driver.
|
The current driver implementation holds the position by keeping both coils energized after completing the pulse output, resulting in states like 0011 or 0110. While this can maintain the position in the short term, keeping the coils powered continuously leads to heating of the stepper motor. Additionally, this method doesn’t fully lock the position, so in many cases, mechanical locking is required. Using the current-based method causes the motor to heat up continuously and consume power. In light of this, I’m proposing a modification to the driver to provide a configurable option. If there is an alternative mechanical method to lock the position, we can disable the current-based locking, saving energy and preventing the stepper motor from heating up. Specifically, we can optimize in the following ways: |
|
Okay I see now the reasoning behind. This API is meant for stepper controllers solely, and handling a mechanical latch is not done by a stepper controller. But what you are trying could be achieved with the existing code as well
|
|
Hi @henrycoding, Wouldn't something like |
|
#80646 So with this PR, once you disable the driver the coils would be powered down |

This commit introduces the latch functionality for stepper motors in the Zephyr stepper driver framework. The latch feature allows the motor to hold its position after completing a movement, which is useful in applications that require precise position control without losing steps due to external forces.
Changes include:
stepper_set_latch()function to configure whether the motor should latch (hold position) after movement.stepper_is_latch()function to check the current latch configuration.This functionality helps maintain the motor's position after movement, preventing unwanted drift when the motor is not in active movement. However, latching consumes more power as it keeps current flowing through the motor windings.
Heng Zhang, [email protected]