Skip to content

feat: add driver presets for Bondtech steppers#102

Open
dalegaard wants to merge 1 commit intoRat-OS:v2.1.xfrom
devrandomdk:feat/bondtech_driver_presets
Open

feat: add driver presets for Bondtech steppers#102
dalegaard wants to merge 1 commit intoRat-OS:v2.1.xfrom
devrandomdk:feat/bondtech_driver_presets

Conversation

@dalegaard
Copy link
Contributor

@dalegaard dalegaard commented Aug 19, 2025

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

  • New Features
    • Added multiple preset configurations for Bondtech and LDO stepper motors, enabling users to select from various driver options and settings tailored to different hardware setups.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

The change adds a new presets field to multiple stepper entries in the Steppers data array. Each preset contains driver configuration details including run_current, voltage, driver type, and various timing/configuration parameters across different driver models (TMC2209, TMC2240, TMC5160). This extends stepper definitions with multiple preset configurations.

Changes

Cohort / File(s) Summary
Stepper Presets Configuration
src/data/steppers.ts
Added presets field to multiple Bondtech and LDO stepper entries (BONDTECH-42H025H-0704-002, BONDTECH-42H030H-1504A-001, BONDTECH-ACC01STM41280, LDO-42STH48-2504AC, LDO-42STH40-1684AC, LDO-42STH48-2004AC, LDO-42STH25-1404MAC, LDO-36STH20-1004AHG, and others). Each preset object specifies run_current, voltage, driver, sense_resistor (optional), and driver configuration parameters (driver_TBL, driver_TOFF, driver_HEND, driver_HSTRT, etc.), supporting multiple driver types with varying configurations per stepper.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add driver presets for Bondtech steppers' clearly and accurately describes the main change—adding driver presets specifically for Bondtech stepper motors. It is concise, specific, and directly reflects the changeset content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.
@dalegaard dalegaard force-pushed the feat/bondtech_driver_presets branch from 291e17d to e1e331f Compare February 2, 2026 18:14
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

Comment on lines +70 to +129
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,
},
],
Copy link
Contributor

@coderabbitai coderabbitai bot Feb 2, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find the findPreset function definition and all call sites
rg -nP 'findPreset\s*[\(\:]' --type=ts -B 2 -A 5

Repository: 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.ts

Repository: 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.tsx

Repository: 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 2

Repository: 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 2

Repository: 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.tsx

Repository: 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The intention is for the 1.0A presets to only match if the user sets current to 1.0A, so current behavior is correct.

Copy link
Contributor

Choose a reason for hiding this comment

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant