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

RFC: Change Stepper API to use step interval #83726

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

faxe1008
Copy link
Collaborator

@faxe1008 faxe1008 commented Jan 9, 2025

As discussed in the original RFC issue: Change the stepper API to accept the interval to wait at a minimum in between executing consequtive steps. This allows for a more granular control then the previous interface.

Resolves #83591

@faxe1008
Copy link
Collaborator Author

faxe1008 commented Jan 9, 2025

Did not include it yet, but the stepper.h could be a macro STEP_INTERVAL_US_FROM_VELOCITY to ease the transition for people already using the old API.

@faxe1008 faxe1008 force-pushed the stepper_velocity branch 7 times, most recently from 5090c7c to d09f9cb Compare January 9, 2025 08:19
@jilaypandya
Copy link
Contributor

The API Change and then relevant changes in shell, drivers, tests should be squashed in one commit.


static inline int z_impl_stepper_run(const struct device *dev,
const enum stepper_direction direction,
const uint32_t velocity)
const uint64_t step_interval_us)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now that passing step interval again over here is just redundant.
User would set_interval->enable->run

Suggested change
const uint64_t step_interval_us)
static inline int z_impl_stepper_run(const struct device *dev,
const enum stepper_direction direction)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thats also true.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But with this you can stop the motor - maybe thats worth keeping?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved the stopping of the motor to the set_step_interval function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need to handle this in a different manner. Setting step_interval to zero in theory means that the motor spins at inf speed, hence setting step_interval to zero should not in theory stop the motor. If anything 0 is -EINVAL.

setting velocity to zero in drivers as of now does not power down the coils and is in hence some sort of hold mode. This could be done using stepper_hold(device, HOLD_MODE) or stepper_stop(device) where HOLD_MODE could even include stuff like passive_braking when it is supported by the driver.

fabiobaltieri
fabiobaltieri previously approved these changes Jan 9, 2025
@faxe1008
Copy link
Collaborator Author

faxe1008 commented Jan 9, 2025

About the squashing - don't know whats the proper ettiquette for it. Did not do that many treewide changes as of now.

@jilaypandya
Copy link
Contributor

About the squashing - don't know whats the proper ettiquette for it. Did not do that many treewide changes as of now.

when we recently shifted to DEVICE_API, we introduced that change in all the drivers in a single commit, I believe its easier to track. The way it's done right now is like this that we introduce a change and then do the correction in drivers, tests, shell successively in respective commits.

I would have had one commit for stepper_set_step_interval, one commit for stepper_runand then one migration-guide commit.

@fabiobaltieri
Copy link
Member

About the squashing - don't know whats the proper ettiquette for it. Did not do that many treewide changes as of now.

You should really squash the API change with the code update to use the new API, basically no commit should break the build. Doc update can be on its own. In this case it does make it harder to review but that's how it should be done.

fabiobaltieri
fabiobaltieri previously approved these changes Jan 9, 2025
static inline uint32_t tmc5xxx_calculate_velocity_from_hz_to_fclk(uint64_t velocity_hz,
uint32_t clock_frequency)
static inline uint32_t
tmc5xxx_calculate_velocity_from_step_interval_to_fclk(uint64_t step_interval_us,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can the argument name be shortened in order to atleast have the function name and return type in a single line

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to change the function name for that to work, done.

@@ -20,10 +20,10 @@ typedef int (*stepper_timing_source_init)(const struct device *dev);
* @brief Update the stepper timing source.
*
* @param dev Pointer to the device structure.
* @param velocity Velocity in microsteps per second.
* @param step_interval_us The new step interval in microseconds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step interval in microseconds

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @details If velocity > 0, motor shall be set into motion and run incessantly until and unless
* stalled or stopped using some other command, for instance, motor_enable(false).
* This function is non-blocking.
* @details The motor shall be set into motion and run incessantly until and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continuously instead of incessantly

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Change the stepper API to instead of changing the stepper speed based on
the velocity in microsteps per second to use the delay in usec between
successive steps. Also remove the velocity from the `stepper_run` function
as typical API usage is enable -> set step interval -> run.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
Migrates the peripherals documentation to the new step interval based APi
instead of the velocity one.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
Adds a two bullet points explaining the change of the velocity based API
towards an step interval one.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Stepper Release Notes To be mentioned in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

drivers: stepper: API: Do not limit velocity to integer
4 participants