Tuning Marlin for an arm, one commit at a time
Getting six motors to answer to six letters was the easy part.
Code: marlin-firmware commit history · Watch: 6DOF arm first test · Pick and place with a new gripper
Getting six motors to answer to six letters was the easy part. Getting each joint to move the right way, by the right amount, without overheating, took about a dozen small commits over three days in late April. Reading them back, they make a decent checklist.
The history, roughly
| Date | Commit | What changed |
|---|---|---|
| 17 Mar | enabled I, J and K | 88.88 steps per degree on every joint, a guess at 10:1 gearing |
| 18 Mar | minor axis unit updates | 8.89 on every joint (no gearing), 30°/s max speed |
| 25 Apr | updated gear ratio and axis limits | real gear ratios per joint, real travel limits |
| 25 Apr | reversed the x axis direction | X turned the wrong way |
| 25 to 26 Apr | backoff after homing | move away from the hard stop once homed |
| 26 Apr | current for Y axis | Y current lowered to reduce heating |
| 26 Apr | limited maximum accel | cap what a host can set with M201 |
| 26 Apr | editable homing feedrate | change homing speed with M210 |
| 27 Apr | accurate control over the angles | Y, J and K gear trains corrected |
Steps per degree
This is the number everything else depends on. Marlin’s “steps per unit” becomes steps per degree on an arm, and you work it out from the motor and the gearing:
// steps per degree = microsteps / step angle × gear ratio
const stepsPerDegree = ({ stepAngle, microsteps = 16, ratio = 1 }) =>
(microsteps / stepAngle) * ratio;
stepsPerDegree({ stepAngle: 1.8, ratio: 100 / 16 }); // 55.56
stepsPerDegree({ stepAngle: 0.9, ratio: 32 / 16 }); // 35.56
A standard 1.8° motor at 16 microsteps gives 8.89 steps per degree of motor shaft. Every pulley or gearbox after that multiplies it. Here’s where the config ended up:
| Joint | Motor | Gearing | Steps per degree |
|---|---|---|---|
| X | 1.8° NEMA 17 | 16T to 100T belt, 6.25:1 | 55.56 |
| Y | 1.8° motor with a 5.18:1 gearbox | gearbox, then 16T to 80T belt, 25.9:1 total | 230.22 |
| Z | 1.8° NEMA 17 | 16T to 100T belt, 6.25:1 | 55.56 |
| A | 1.8° NEMA 14 | 16T to 60T belt, 3.75:1 | 33.33 |
| B | 0.9° NEMA 14 | 16T to 32T belt, 2:1 | 35.56 |
| C | 1.8° motor | direct drive | 8.89 |
#define DEFAULT_AXIS_STEPS_PER_UNIT { 55.56, 230.22, 55.56, 33.33, 35.56, 8.89 }
The history shows why it’s worth writing the gear train down. On 25 April, Y was set to 74.0, worked out as if it were a motor with a tiny step angle. Two days later it became 230.22, as a normal motor behind a 5.18:1 gearbox and a 5:1 belt. With the old value, asking Y for 90° would have moved it about 29°. B and C changed in the same commit, once it was clear that B had the 0.9° motor and a 2:1 belt, and C was direct drive.
To check a joint, home it, command a big move like G1 A90, and measure the angle with a protractor or a phone level app. If it’s off, scale the value (new = old × commanded ÷ measured) and try it live before reflashing:
M92 A33.33 ; set steps per degree for A
M500 ; save to EEPROM
M503 ; print all current settings
M503 is worth running before every commit. Pasting its output into the commit message gives you a record of what the board was actually running, not just what the source said.
Travel limits
Each joint homes to its minimum, so 0 is the home position and the limits are measured from there:
#define X_MIN_POS 0 #define X_MAX_POS 260 #define Y_MIN_POS 0 #define Y_MAX_POS 80 #define Z_MIN_POS 0 #define Z_MAX_POS 102.5 #define I_MIN_POS 0 #define I_MAX_POS 180
With software endstops on (the default), Marlin clips any move to these ranges. On a printer that keeps the nozzle over the bed. On an arm it keeps the joint from tearing its own cables.
Direction
For each joint, decide which way is positive, then flip INVERT_X_DIR and friends until G1 X10 after homing goes that way. The history shows X flipped in April, then other joints in May and June, one at a time as they were tested.
If you plan to use ROS later, pick “positive” to match the joint axes in the robot’s URDF. Otherwise MoveIt and Marlin will disagree about which way is up, and you’ll end up negating values in code, which is exactly the problem the line follower had.
Current
The TMC2209 sets motor current in software, as an RMS value in milliamps:
#define X_CURRENT 800 #define Y_CURRENT 250 // was 300, lowered to reduce heating #define Z_CURRENT 700 #define I_CURRENT 180 #define J_CURRENT 200 #define K_CURRENT 200
The small motors near the wrist need far less than the ones at the base, and running them near their rating means hot motors and soft PLA mounts. The geared Y motor gets torque from its gearbox, which is why its current could come down. M906 changes current live, so you can lower it step by step until the joint starts to skip, then add a margin.
Homing, then backing off
#define HOMING_BACKOFF_POST_MM { 5, 15, 5, 5, 5, 5 }
After homing, each joint moves a few degrees away from its stop (the name says mm, but on these axes it’s degrees). Without it, the joint starts its first move pressed against the hard stop. Y backs off further, at 15°.
One thing I’d revisit: the config bumps every axis again after the first touch (HOMING_BUMP_MM is 5 for all six). Marlin’s own comment recommends a bump of 0 for sensorless homing, because the slow second approach is where stall detection is least reliable.
Limits on the host
#define LIMITED_MAX_ACCEL_EDITING
#define MAX_ACCEL_EDIT_VALUES { 2000, 2000, 2000, 2000, 2000, 2000 }
Hosts like Pronterface can send M201 to change the maximum acceleration. This caps what they can set at 2000°/s², whatever the host asks for. It’s server-side validation for firmware: the client can send anything, the firmware decides what’s allowed.
The pattern
Every one of these commits changes one thing, has a name that says what, and was tested before the next. That’s slower than changing ten defines and flashing once, but with a robot arm, “something is wrong” is not a useful bug report. One change per flash means you always know which change caused it.