feat: add driver presets for Bondtech steppers#102
feat: add driver presets for Bondtech steppers#102dalegaard wants to merge 1 commit intoRat-OS:v2.1.xfrom
Conversation
WalkthroughThe change adds a new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This adds driver presets for TMC2209/2240/5160 in common configurations(24V, common current sense resistors) for all Bondtech stepper motors. For the LGX Pro motor, we provide presets for both Metal(1.0A RMS) and non-Metal(0.75A RMS) versions.
291e17d to
e1e331f
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/data/steppers.ts`:
- Around line 70-129: The presets array contains duplicate driver+voltage
entries (0.75A and 1.0A) and recommendedPreset (called without current) picks
the lower run_current, causing setCurrent(recommendedPreset.run_current) to
auto-select the wrong tier; fix by adding an explicit disambiguator (e.g.,
variant or label) to each preset object and update recommendedPreset to prefer a
matching variant or require a current argument when multiple presets share
driver+voltage, then ensure the effect that calls setCurrent uses the
disambiguated preset (update the logic in recommendedPreset and the useEffect
that calls setCurrent).
| presets: [ | ||
| { | ||
| run_current: 0.75, | ||
| voltage: 24, | ||
| driver: 'TMC2209', | ||
| sense_resistor: 0.11, | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 1, | ||
| driver_HSTRT: 0, | ||
| }, | ||
| { | ||
| run_current: 0.75, | ||
| voltage: 24, | ||
| driver: 'TMC2240', | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 3, | ||
| driver_HSTRT: 6, | ||
| }, | ||
| { | ||
| run_current: 0.75, | ||
| voltage: 24, | ||
| driver: 'TMC5160', | ||
| sense_resistor: 0.075, | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 4, | ||
| driver_HSTRT: 7, | ||
| }, | ||
| { | ||
| run_current: 1.0, | ||
| voltage: 24, | ||
| driver: 'TMC2209', | ||
| sense_resistor: 0.11, | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 3, | ||
| driver_HSTRT: 0, | ||
| }, | ||
| { | ||
| run_current: 1.0, | ||
| voltage: 24, | ||
| driver: 'TMC2240', | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 3, | ||
| driver_HSTRT: 5, | ||
| }, | ||
| { | ||
| run_current: 1.0, | ||
| voltage: 24, | ||
| driver: 'TMC5160', | ||
| sense_resistor: 0.075, | ||
| driver_TBL: 0, | ||
| driver_TOFF: 5, | ||
| driver_HEND: 3, | ||
| driver_HSTRT: 7, | ||
| }, | ||
| ], |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find the findPreset function definition and all call sites
rg -nP 'findPreset\s*[\(\:]' --type=ts -B 2 -A 5Repository: Rat-OS/RatOS-configurator
Length of output: 4667
🏁 Script executed:
# Also check the full steppers.ts file structure to understand the context
head -150 src/data/steppers.tsRepository: Rat-OS/RatOS-configurator
Length of output: 3043
🏁 Script executed:
# Look at the context around recommendedPreset usage in printer-rail-settings.tsx
sed -n '155,220p' src/components/setup-steps/printer-rail-settings.tsxRepository: Rat-OS/RatOS-configurator
Length of output: 2294
🏁 Script executed:
# Check if there's any mention of "Metal" or variant distinction in the stepper definitions
rg -i 'metal|variant|pro' src/data/steppers.ts -B 2 -A 2Repository: Rat-OS/RatOS-configurator
Length of output: 296
🏁 Script executed:
# Check for any documentation or comments about Metal/non-Metal in steppers or related files
rg -i 'metal|non.metal|variant' . --type=ts --type=md -B 2 -A 2Repository: Rat-OS/RatOS-configurator
Length of output: 44884
🏁 Script executed:
# Check the usage of recommendedPreset in the UI component to understand its impact
sed -n '200,280p' src/components/setup-steps/printer-rail-settings.tsxRepository: Rat-OS/RatOS-configurator
Length of output: 3068
LGX Pro presets lack explicit disambiguation and auto-select lower current.
LGX Pro has two presets per driver/voltage (0.75 A and 1.0 A) with no variant or label field. When recommendedPreset is called without current (line 168), it selects the lower current by default. The useEffect at line 213 then auto-sets setCurrent(recommendedPreset.run_current), which may not match the intended preset if both current levels serve different hardware tiers. Either require current be specified when multiple presets share driver+voltage, or add an explicit variant field to disambiguate selection.
🤖 Prompt for AI Agents
In `@src/data/steppers.ts` around lines 70 - 129, The presets array contains
duplicate driver+voltage entries (0.75A and 1.0A) and recommendedPreset (called
without current) picks the lower run_current, causing
setCurrent(recommendedPreset.run_current) to auto-select the wrong tier; fix by
adding an explicit disambiguator (e.g., variant or label) to each preset object
and update recommendedPreset to prefer a matching variant or require a current
argument when multiple presets share driver+voltage, then ensure the effect that
calls setCurrent uses the disambiguated preset (update the logic in
recommendedPreset and the useEffect that calls setCurrent).
There was a problem hiding this comment.
The intention is for the 1.0A presets to only match if the user sets current to 1.0A, so current behavior is correct.
There was a problem hiding this comment.
@dalegaard, thank you for clarifying! I understand now that the design intentionally requires users to explicitly set the current to 1.0A to match the higher-current presets, while the default selection (when current is unspecified) will pick the lower 0.75A preset. This makes sense as a safe default behavior.
✏️ Learnings added
Learnt from: dalegaard
Repo: Rat-OS/RatOS-configurator PR: 102
File: src/data/steppers.ts:70-129
Timestamp: 2026-02-02T21:59:50.836Z
Learning: In `src/data/steppers.ts`, when a stepper has multiple presets for the same driver and voltage (e.g., Bondtech LGX Pro with 0.75A and 1.0A presets), the `findPreset` function is designed to require explicit current specification to match higher-current presets. When current is not specified, it defaults to the lowest current preset (or highest if performanceMode is true). This is intentional behavior.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
This adds driver presets for TMC2209/2240/5160 in common configurations(24V, common current sense resistors) for all Bondtech stepper motors. For the LGX Pro motor, we provide presets for both Metal(1.0A RMS) and non-Metal(0.75A RMS) versions. These were calculated with the TMC-provided calculation sheets for each driver.
Summary by CodeRabbit