Skip to content

[APP-16401] add microsteps#6031

Open
npmenard wants to merge 2 commits into
viamrobotics:mainfrom
npmenard:APP-16401-add-microsteps
Open

[APP-16401] add microsteps#6031
npmenard wants to merge 2 commits into
viamrobotics:mainfrom
npmenard:APP-16401-add-microsteps

Conversation

@npmenard
Copy link
Copy Markdown
Member

Adding config field to set the max_rpm and microsteps in a effort to make gpiostepper motor easier to configure.
I didn't remove the stepper_delay_usec for backward compatibility

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label May 20, 2026
@npmenard npmenard requested a review from nfranczak May 20, 2026 20:08
// (a motor spec, e.g. 200 for a NEMA 17). The effective pulses-per-revolution
// on the step pin is TicksPerRotation * Microsteps.
TicksPerRotation int `json:"ticks_per_rotation"`
// Microsteps is the driver's microstep divisor (1, 2, 4, 8, 16, 32, ...),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment does not add much.
Seems also that it cannot be odd?
I'd consider updating.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

changed

// Microsteps is the driver's microstep divisor (1, 2, 4, 8, 16, 32, ...),
Microsteps int `json:"microsteps,omitempty"`
// MaxRPM is the motor's maximum shaft speed and is the preferred way to cap
// the step-pin pulse frequency: maxFreq = MaxRPM * TicksPerRotation * Microsteps / 60.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maxFreq = MaxRPM * TicksPerRotation * Microsteps / 60
where is maxFreq come from?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the comment wasn't formatted properly, the max frequency is the frequency if you wanted to drive the stepper motor at the max rpms

if cfg.Pins.Step == "" {
return nil, nil, resource.NewConfigValidationFieldRequiredError(path, "step")
}
if cfg.Microsteps < 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

also make sure that it's not odd?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

we can't because 1 is a valid value

Named: conf.ResourceName().AsNamed(),
theBoard: b,
stepsPerRotation: mc.TicksPerRotation,
stepsPerRotation: mc.TicksPerRotation * microsteps,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this feels incorrect.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

when microstepping the total counts for a rev is stepPerRev*microsteps

Comment thread components/motor/gpiostepper/gpiostepper.go
if mc.StepperDelay > 0 {
logger.Warnf(
"motor (%s) has both max_rpm and stepper_delay_usec set; max_rpm wins. "+
"stepper_delay_usec is deprecated, drop it from the config.",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if stepper delay is deprecated why did you give it a value above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

because we technically still use it in the code to calculate requested frequency

@npmenard npmenard changed the title add microsteps [APP-16401] add microsteps May 21, 2026
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test This pull request is marked safe to test from a trusted zone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants