Skip to content

Conversation

@henrycoding
Copy link

@henrycoding henrycoding commented Oct 20, 2024

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:

  • 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.

Heng Zhang, [email protected]

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.
@github-actions
Copy link

Hello @henrycoding, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Copy link
Member

@jilaypandya jilaypandya left a 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.

@henrycoding
Copy link
Author

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:

1.	Configurable Current Holding: The driver will have an option to enable or disable current holding based on whether the motor position needs to be locked electrically. If mechanical locking is available, we can disable the current holding, reducing heating and power consumption.
2.	Freewheeling Mode: When the motor is in a stopped state, and latching is not needed, the motor can be set to freewheel by cutting off power to the coils, thereby preventing overheating.

@jilaypandya
Copy link
Member

jilaypandya commented Oct 24, 2024

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

  • Attach a callback to set_target_position.
  • And you can switch off the coils in the application code, if a latch is activated.

@jilaypandya jilaypandya requested a review from dipakgmx October 25, 2024 08:05
@dipakgmx
Copy link
Member

Hi @henrycoding,
Could you use another name rather than latch. The Trinamic drivers uses the term latching to set the current motor/encoder position, upon a reference switch event:

image

Wouldn't something like hold_position be better?

@jilaypandya
Copy link
Member

#80646 So with this PR, once you disable the driver the coils would be powered down

@henrycoding henrycoding closed this by deleting the head repository Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants