Skip to content
Back to skills

Motion Control

ASecurity

This skill should be used when the user designs, wires, sizes or debugs a stepper or servo axis, for example "NEMA 17", "A4988", "DRV8825", "TMC2209", "set the Vref", "sensorless homing", "missed steps", "PCA9685", "servo jitter", "bus servo", "steps per mm" or "motor torque sizing". It covers driver choice, current setting, wiring, homing and sizing, with stepper and servo calculators. Load it before answering, even for a short question, because driver current and wiring come from each datas...

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 1, 2026
ai-agentstestingcode-reviewgit

Works with

  • mcp

Security analysis

A100/100

Pro scans all 9 files and shows the line behind each finding

Scanned December 1, 2026

npx -y skills add gkochievi/boulder-hardware-skills --skill motion-control --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Motion Control?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Motion Control
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gkochievi-motion-control/badge)](https://www.skillsdirectory.com/skills/gkochievi-motion-control)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: motion-control
description: This skill should be used when the user designs, wires, sizes or debugs a stepper or servo axis, for example "NEMA 17", "A4988", "DRV8825", "TMC2209", "set the Vref", "sensorless homing", "missed steps", "PCA9685", "servo jitter", "bus servo", "steps per mm" or "motor torque sizing". It covers driver choice, current setting, wiring, homing and sizing, with stepper and servo calculators. Load it before answering, even for a short question, because driver current and wiring come from each datasheet.
user-invocable: false
---

# Motion control: steppers, servos, homing and sizing

Turn a motion requirement into a working axis: the actuator, the driver and its current setting, the supply and wiring, the step or pulse generation, homing and limits, and the mechanical numbers behind them. DC and brushless motors, relays, solenoids and fans are in `electronics-fundamentals/references/motors-and-actuators.md`; PWM with dead time, FOC, encoders and PID loops in `embedded-firmware/references/motor-control-firmware.md`. Read those two files' stepper and servo sections (4 and 5, and 3 and 4) for the short version; this skill holds the depth and the calculators.

## Procedure

Work through the steps in order and record the answers in the project's requirements file and decision log (`ask-gela` describes them). Do not pick a driver before step 3 has numbers.

### 1. Capture the requirements

Ask for these and turn vague answers into numbers:

| Question | Why it decides things | Example answer |
|---|---|---|
| What moves, how far, how heavy, which orientation | Load force, gravity, inertia | 1.5 kg carriage, 300 mm horizontal |
| Speed and acceleration (or move time) | Torque at speed, step rate, supply voltage | 200 mm/s, 3 m/s² |
| Resolution and repeatability | Drive ratio, microsteps, homing method | 0.05 mm repeatable |
| Holding when powered off | Brake, counterweight, self-locking drive | Z must not drop |
| Noise limits | StealthChop drivers, microstepping | Office, quiet |
| Supply available | Driver choice, speed limit | 24 V, 5 A |
| Duty and environment | Thermal design, sensor choice | Continuous, dusty |
| Feedback needed | Open-loop stepper, servo, encoder | Lost steps must be detected |
| Safety | Limit switches, emergency stop, falling loads | Operator nearby |

### 2. Choose the actuator

| Situation | Choice | Reference |
|---|---|---|
| Positioning with known loads, open loop, moderate speed | Hybrid bipolar stepper with a chopper driver | `references/steppers-and-drivers.md` |
| Quiet desktop machine, sensorless homing wanted | Stepper + TMC2209 / TMC2226 (UART) | `references/steppers-and-drivers.md` section 3.3, `references/stepper-tmc-and-firmware.md` section 9 |
| 24–48 V machine, simple STEP/DIR, accurate current | Stepper + DRV8434 | `references/steppers-and-drivers.md` section 4 |
| Motor above about 2 A RMS, or ramps offloaded to the driver | TMC5160 with external MOSFETs | `references/stepper-tmc-and-firmware.md` section 9.5 |
| Small, slow, cheap mechanism | 28BYJ-48-class geared motor + ULN2003A | `references/steppers-and-drivers.md` section 1 |
| Angle within about 180°, light load, simple wiring | Hobby PWM servo | `references/servos.md` sections 1–3 |
| Many joints, position and load feedback, daisy chain | Bus servo (Dynamixel, Feetech) | `references/servos.md` section 4 |
| Continuous rotation with speed or torque control | DC or BLDC motor (FOC) | `electronics-fundamentals/references/motors-and-actuators.md`, `embedded-firmware/references/motor-control-firmware.md` |

### 3. Size the mechanics

1. Pick the transmission (belt, lead or ball screw, rack, gearbox) and compute steps per mm: `scripts/stepper_calc.py steps-per-mm` (lead screws use the lead, never the pitch alone).
2. Compute load torque, acceleration torque including the rotor and pulley or screw inertia, and the inertia ratio; apply a safety factor of 1.5–2 (`references/mechanics-homing-and-sizing.md` section 2 has the formulas and two worked examples).
3. Compute the top step rate (`scripts/stepper_calc.py step-rate`) and check it against the driver and the step generator.
4. Choose the motor from its pull-out torque curve at the top speed, supply voltage and driver; holding torque is not a sizing number. `scripts/stepper_calc.py max-speed` gives a rough corner speed for comparing supply voltages and motors.
5. Keep cruise speeds out of the resonance region near 200 full steps/s.

### 4. Choose and set the driver

- Compare drivers in `references/steppers-and-drivers.md` section 4 (voltage, current, microsteps, interface, LCSC numbers).
- Compute the current setting with the exact driver's formula (`scripts/stepper_calc.py current --driver ... --rsense ... --current ...`). The A4988, DRV8825 and DRV8434 formulas give peak current; the TMC22xx formula gives RMS. Read the sense resistor on the board; never assume a module value.
- For TMC22xx in UART mode compute IRUN, IHOLD and vsense with `--uart` and set them in firmware; leave the trimmer alone (`I_scale_analog` = 0).
- The TMC22xx current constants (V_FS 0.325 / 0.180 V, the 20 mΩ term) are marked unverified in this skill: chapter 9 of the TMC2208/2209/2226 datasheets could not be read. Tell the user so when a TMC current matters, and have them check that chapter.
- Hobby servos: calibrate end points per model (`references/servos.md` section 1.2) and convert with `scripts/servo_calc.py angle`.

### 5. Power, wiring and layout

Check each item in schematic and layout review:

- [ ] Motor or servo supply sized for the worst case (stall currents, all axes accelerating), with bulk capacitance at each driver or at the servo connectors (`references/steppers-and-drivers.md` section 8, `references/servos.md` section 1.4, `scripts/servo_calc.py supply`).
- [ ] Supply below each driver's maximum with margin for regeneration on deceleration; TVS or brake circuit on large axes.
- [ ] MCU on its own regulator; motor and servo currents return on their own copper; one ground join.
- [ ] Logic levels: A4988 VDD at the MCU's logic voltage (VIH 0.7 × VDD); TMC VCC_IO at the MCU level; RP2040 and ESP32 pins never see 5 V.
- [ ] EN pulled to the disabled state while the MCU boots; servo signals pulled low.
- [ ] STEP pulse width and DIR setup meet the driver table (`references/steppers-and-drivers.md` section 6); wake time respected.
- [ ] TMC UART: 1 kΩ in TX, RX direct, address pins set, `pdn_disable` set in firmware.
- [ ] Sense resistors Kelvin-routed and close; exposed pad soldered with many vias; copper area for the dissipation (`references/steppers-and-drivers.md` section 10, `pcb-design/references/power-and-thermal.md`).
- [ ] Endstops NC to ground with pull-up, RC filter and Schmitt input (`references/mechanics-homing-and-sizing.md` section 4).
- [ ] Pins avoid strapping, flash and PSRAM pins (wiring tables in `references/steppers-and-drivers.md` section 11).
- [ ] Bus servos: direction control (buffer, half-duplex UART or RS-485 transceiver) and level translation for 3.3 V MCUs (`references/servos.md` section 4.1).

### 6. Firmware

- Steppers: timer-driven steps above a few kHz (FastAccelStepper, own timer ISR, RP2040 PIO); AccelStepper only for slow axes. Examples in `references/stepper-tmc-and-firmware.md` section 12; ramp mathematics in `embedded-firmware/references/motor-control-firmware.md` section 3.
- TMC drivers: write GCONF, IHOLD_IRUN, CHOPCONF and TPOWERDOWN at start-up and after every motor-supply return; confirm with IFCNT (`references/stepper-tmc-and-firmware.md` section 12.5).
- Hobby servos: one hardware timer channel or PCA9685 channel per servo; settings from `scripts/servo_calc.py timer` or `pca9685`; slew-limit commands and clamp to the calibrated range.
- Bus servos: CRC-16 for Dynamixel Protocol 2.0, inverted sum for Feetech; switch direction on UART transmission complete (`references/servos.md` section 4).
- Latch faults (limit hit, stall, driver fault pin) and require a deliberate reset and re-homing.

### 7. Homing and limits

- Choose the endstop type and wiring (`references/mechanics-homing-and-sizing.md` section 4); prefer NC.
- Home in two passes with distance and time bounds; latch the first edge in an interrupt (section 5).
- Use sensorless homing only within its caveats (section 5.4) and with the StallGuard version that matches the chopper mode (`references/stepper-tmc-and-firmware.md` section 9.3).
- Make hard limits stop the drivers independently of the motion code; plan for falling vertical axes; point machines that can injure people to a safety-rated design (section 6).

### 8. Bring-up and test

1. Current-limited bench supply; motor disconnected; check logic and enable states, then set VREF or write the UART current and read it back.
2. Power down, connect the motor, power up; single steps at low speed; check direction and that four full steps return the rotor to the same detent.
3. Run speed and acceleration ramps up to 1.5 × the planned values and back off to keep margin; watch for stalls near the resonance region.
4. Measure driver and motor temperature after 10 minutes at the worst duty (motor case at or below 100 °C for class B insulation).
5. Calibrate steps per mm with a long measured move; measure backlash with a dial indicator.
6. Home 20 times and record the spread; trip every limit switch; pull a switch connector and confirm the NC wiring reads it as triggered.
7. Servos: verify end points on the scope and with the current reading; move all servos together and watch the MCU supply for dips.

State in every answer what was measured on hardware, what was computed, and what was not checked.

## Scripts

| Script | Use | Example |
|---|---|---|
| `scripts/stepper_calc.py current` | Current ↔ VREF for A4988, DRV8825, DRV8434, TMC2208/2209/2226; TMC UART IRUN/IHOLD/vsense; rating checks | `stepper_calc.py current --driver tmc2209 --uart --rsense 0.11 --current 0.8 --hold-current 0.4` |
| `scripts/stepper_calc.py steps-per-mm` | Belt or screw steps per mm, resolution, microstep check against a driver | `stepper_calc.py steps-per-mm --step-angle 1.8 --microsteps 16 --belt-pitch 2 --teeth 20` |
| `scripts/stepper_calc.py step-rate` | Step frequency for mm/s or rpm, driver STEP limit | `stepper_calc.py step-rate --steps-per-mm 80 --speed 200 --driver drv8825` |
| `scripts/stepper_calc.py max-speed` | Rough corner speed from L, I, V (an estimate; the basis is printed) | `stepper_calc.py max-speed --inductance-mh 3 --current 1.5 --supply 24 --resistance 1.6 --step-angle 1.8` |
| `scripts/servo_calc.py angle` | Angle ↔ pulse from calibrated end points | `servo_calc.py angle --min-us 600 --max-us 2400 --range-deg 180 --angle 45` |
| `scripts/servo_calc.py pca9685` | PRE_SCALE, real frame, tick, ON/OFF counts and registers | `servo_calc.py pca9685 --freq 50 --pulse-us 1500 --channel 3` |
| `scripts/servo_calc.py timer` | 50 Hz settings for ESP32/ESP32-S3 LEDC, STM32 PSC/ARR, RP2040 div/TOP | `servo_calc.py timer --platform stm32 --clock-mhz 170 --pulse-us 1500` |
| `scripts/servo_calc.py supply` | Servo rail current and bulk capacitance | `servo_calc.py supply --count 6 --stall-current 1.2` |

Both scripts print a readable report, or one JSON object with `--json`; exit 0 ok or warn, 1 a check failed (beyond a rating, outside the calibrated range), 2 usage error. Settings come from the command line, then `[stepper_calc]` or `[servo_calc]` in `boulder.toml`. Sense resistors, currents, step angles, microsteps, servo end points, timer clocks and stall currents are never defaulted.

## References

| File | Use for |
|---|---|
| `references/steppers-and-drivers.md` | Motor types and frame sizes, reading motor datasheets, finding coils, chopper and decay modes, microstep torque, StealthChop and SpreadCycle, driver comparison with LCSC numbers, current formulas and worked examples, STEP/DIR timing, speed limits and resonance, supply design, PCB layout, wiring tables (GRBL Uno, ESP32, STM32, RP2040), troubleshooting |
| `references/stepper-tmc-and-firmware.md` | ADI-Trinamic single-wire UART (datagrams, CRC, addressing, registers), StallGuard sensorless homing, CoolStep, DIAG and INDEX; step-generation firmware (timers, PWM, RMT / MCPWM, PIO, libraries, homing sequences) |
| `references/servos.md` | Hobby servo operation, calibration, supply and stall current, power design, signal levels, PCA9685 registers and code, ESP32 LEDC, STM32, RP2040 and AVR timers, Arduino Servo caveats, bus servo wiring and direction control, Dynamixel Protocol 2.0, Feetech FT-SCS, troubleshooting |
| `references/mechanics-homing-and-sizing.md` | Steps per mm for belts, screws, racks and rotary stages, torque and inertia formulas with worked belt and lead-screw examples, acceleration limits, endstop types and input circuit, NC versus NO, homing sequence and repeatability, sensorless caveats, limit-switch safety, backlash, troubleshooting |

## Corrections to common advice

- A4988 and DRV8825 VREF formulas give peak current; TMC formulas give RMS. Do not mix them (`references/steppers-and-drivers.md` section 5).
- An A4988 on 5 V VDD needs 3.5 V logic highs; power VDD from 3.3 V for a 3.3 V MCU.
- Microstepping smooths motion; it does not add accuracy under load (incremental torque about sin(90°/n) of holding torque).
- StallGuard4 (TMC2209/2226) needs StealthChop; StallGuard2 (TMC2130/5160) needs SpreadCycle; the TMC2208 has none.
- Lead screw steps per mm use the lead, not the pitch.
- Normally closed limit switches detect broken wires; normally open ones do not.
- PCA9685 prescale is round(osc / (4096 × f)) − 1 on a nominal oscillator with no stated tolerance: measure the frame.
- Dynamixel Protocol 2.0 uses CRC-16 (0x8005); Feetech FT-SCS uses an inverted sum; Feetech byte order differs between SCS and STS.

## Engineering plugin skills

If the Engineering plugin is installed: `/engineering:system-design` for the actuator and controller architecture; `/engineering:testing-strategy` for the step 8 bring-up plan; `/engineering:debug` for missed steps, resets and bus errors; `/engineering:code-review` on step generation, homing and fault latching.

## Related skills

- `electronics-fundamentals`: DC and BLDC motors, drivers, relays, solenoids, the motor power and grounding rules (`electronics-fundamentals/references/motors-and-actuators.md`), RS-485 and logic levels (`electronics-fundamentals/references/digital-interfaces.md`).
- `embedded-firmware`: acceleration profiles, step timing, FOC, encoders, PID (`embedded-firmware/references/motor-control-firmware.md`), output states at boot (`embedded-firmware/references/io-patterns.md`).
- `microcontrollers`: timer, PWM, PIO and pin rules per MCU family.
- `pcb-design`: copper, thermal vias and trace widths for drivers (`pcb-design/references/power-and-thermal.md`), connector protection.
- `peripherals`: optical sensors for endstops, magnetic angle sensors for feedback.
- `ask-gela`: requirements file, phases and decision log.

## Next step

When this is done, say what comes next: `kicad-generator` (the motion template and the driver blocks), then `embedded-firmware` for step generation and homing.

Files in this skill

  • SKILL.md14.9 KB
  • references/mechanics-homing-and-sizing.md24.1 KB
  • references/servos.md31.1 KB
  • references/stepper-tmc-and-firmware.md16.6 KB
  • references/steppers-and-drivers.md34.2 KB
  • scripts/servo_calc.py30.7 KB
  • scripts/stepper_calc.py38.9 KB
  • scripts/tests/test_servo_calc.py7.5 KB
  • scripts/tests/test_stepper_calc.py11 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.