|
| | Homing (TMC51x0 &driver) noexcept |
| | Construct homing subsystem.
|
| |
| Result< void > | PerformSensorlessHoming (bool direction, const BoundsOptions &opt, int32_t &final_position, CancelCallback should_cancel=nullptr) noexcept |
| | Perform sensorless homing using StallGuard2 (with settings caching)
|
| |
| Result< void > | PerformSwitchHoming (bool direction, const BoundsOptions &opt, int32_t &final_position, bool use_left_switch, CancelCallback should_cancel=nullptr) noexcept |
| | Perform homing using a reference switch (with settings caching)
|
| |
| Result< void > | PerformEncoderIndexHoming (bool direction, const BoundsOptions &opt, int32_t &final_position, CancelCallback should_cancel=nullptr) noexcept |
| | Perform homing using encoder index pulse (N-channel) with latch_x_act.
|
| |
| Result< BoundsResult > | FindBoundsStallGuard (const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept |
| | Find motion bounds using StallGuard2 (sensorless hard-stop detection).
|
| |
| Result< BoundsResult > | FindBoundsEncoder (const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept |
| | Find motion bounds using encoder feedback (detects "no further motion" via stalled encoder).
|
| |
| Result< BoundsResult > | FindBoundsSwitch (const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept |
| | Find motion bounds using reference switches (REFL/REFR stop events).
|
| |
| Result< BoundsResult > | FindBounds (BoundsMethod method, const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept |
| | Dispatch bounds finding by method.
|
| |
template<typename CommType>
struct tmc51x0::TMC51x0< CommType >::Homing
Homing subsystem with automatic settings caching.
Provides homing methods that automatically cache and restore settings modified during homing operations.
template<typename CommType >
Find motion bounds using encoder feedback (detects "no further motion" via stalled encoder).
This routine performs two span-capped searches (± opt.search_span). For each direction, it monitors the encoder position during motion and considers a bound detected when the encoder position stops changing for a short window while motion has already started.
Behavior
- Requires internal ramp mode (SD_MODE=0).
- Requires the encoder subsystem to be configured (otherwise returns
INVALID_STATE).
- Establishes a local coordinate frame by setting the current position to 0 in
opt.position_unit.
- For each direction:
- Command a relative move (±
opt.search_span) using either opt.search_speed or cached VMAX, with optional accel/decel overrides.
- Detect a bound when the encoder position does not change by a minimum delta for a short time after motion begins.
- On detection, performs a physical backoff move of
opt.backoff_distance away from the bound and records the post-backoff position as the bound.
Home placement After both directions complete, home is applied via the same policy as the StallGuard variant.
- Parameters
-
| opt | Bounds-search options (units, span/speed, backoff, timeouts, accel/decel overrides). |
| home | Optional home placement policy (defaults to AtCenter). |
| should_cancel | Optional cancellation callback polled during motion; when it returns true, motion is stopped and the function returns CANCELLED. |
- Returns
Result<BoundsResult> on success, otherwise an error code.
- Warning
- This function moves the motor. Ensure your encoder is correctly wired and configured; a missing/failed encoder can prevent detection and lead to large travel up to
search_span.
- Note
- When a side does not "stall" within
search_span, BoundsResult.bounded will be false and that side's bound is the final span endpoint (i.e., not a detected limit).
template<typename CommType >
Find motion bounds using reference switches (REFL/REFR stop events).
This routine configures the TMC51x0 reference-switch stop sources and performs two span-capped searches. A bound is detected when the corresponding stop event fires; the routine then backs off from the switch and records the post-backoff position as the bound.
Behavior
- Requires internal ramp mode (SD_MODE=0).
- Establishes a local coordinate frame by setting the current position to 0 in
opt.position_unit.
- Preflight handling: if a switch is already active at the start and
opt.preflight_clear_active_switch is true, the routine attempts a bounded move away (using opt.backoff_distance) to clear it. If preflight is disabled or backoff_distance is not configured, returns INVALID_STATE.
- During bounds finding, enables both
SW_MODE.stop_l_enable and SW_MODE.stop_r_enable (hard stop), disables latching, and clears stale stop/latch state between passes.
- On each direction search:
- Positive direction expects the right stop event; negative direction expects the left stop event.
- After a hit, performs a physical backoff move of
opt.backoff_distance away from the switch.
Home placement After both directions complete, home is applied via the same policy as the other variants.
- Parameters
-
| opt | Bounds-search options (units, span/speed, backoff, timeouts, accel/decel overrides). |
| home | Optional home placement policy (defaults to AtCenter). |
| should_cancel | Optional cancellation callback polled during motion; when it returns true, motion is stopped and the function returns CANCELLED. |
- Returns
Result<BoundsResult> on success, otherwise an error code.
- Warning
- This function moves the motor and relies on correctly wired/functional limit switches.
- Note
- When a side does not trigger within
search_span, BoundsResult.bounded will be false and that side's bound is the final span endpoint (i.e., not a detected limit).
template<typename CommType >
Perform sensorless homing using StallGuard2 (with settings caching)
- Parameters
-
| direction | Direction to search (true = positive, false = negative) |
| opt | Homing options (unit-aware). Uses opt.search_speed, opt.search_span, opt.timeout_ms. |
| final_position | Reference to store final position after homing (in steps). Note: if opt.backoff_distance > 0, the motor backs off and the post-backoff point becomes home (XACTUAL=0). |
- Returns
- Result<void> indicating success or error
This is a blocking function that automatically:
- Caches current settings (StealthChop, SW_MODE, ramp settings)
- Disables StealthChop if enabled (StallGuard requires SpreadCycle)
- Uses existing StallGuard configuration (SGT threshold from motor config)
- Enables sg_stop and waits for stall event
- Restores cached settings after homing completes
- Note
- StallGuard threshold (SGT) should be configured via Initialize() or ConfigureStallGuard() before calling this method. The method uses the existing SGT configuration (or opt.stallguard_override if provided).
Perform sensorless homing using StallGuard2 (span-capped, unit-aware)
Uses BoundsOptions.search_speed (in speed_unit) and BoundsOptions.search_span (in position_unit) to perform a single-direction homing move. If StallGuard stop triggers, the current position is defined as home (XACTUAL=0).
final_position returns the pre-zero position in steps (i.e., the position at the moment homing finished, after any optional backoff, before XACTUAL is reset to 0).
- Note
search_span is a hard cap on travel; this prevents excessive motion even if timeout_ms is large.
template<typename CommType >
Perform homing using a reference switch (with settings caching)
- Parameters
-
| direction | Direction to search (true = positive, false = negative) |
| opt | Homing options (unit-aware). Uses opt.search_speed, opt.search_span, opt.timeout_ms. |
| final_position | Reference to store final position after homing (in steps). Note: if opt.backoff_distance > 0, the motor backs off and the post-backoff point becomes home (XACTUAL=0). |
| use_left_switch | true to use REFL, false to use REFR |
- Returns
- Result<void> indicating success or error
This is a blocking function that automatically:
- Caches current settings (SW_MODE, ramp settings)
- Configures switches and performs homing
- Restores cached settings after homing completes
Perform homing using a reference switch (span-capped, unit-aware)
Uses BoundsOptions.search_speed and BoundsOptions.search_span to perform a single-direction homing move. When the selected switch triggers, the current position is defined as home (XACTUAL=0).
final_position returns the pre-zero position in steps (i.e., the position at the moment homing finished, after any optional backoff, before XACTUAL is reset to 0).
BoundsOptions.search_span is the max relative travel cap. StallGuard-only fields in BoundsOptions are ignored.