Mach 4 Screw Mapping
Screw Mapping in Mach 4
Mach 4 (after build 2107) implements symmetric bidirectional screw mapping. Builds after YYYY implement asymmetric bidirectional screw mapping.
DEV: Replace YYYY with the appropriate build number.
What is Screw Mapping?
Screw mapping refers to the means by which the CNC compensates for wear, stretch, or other inaccuracies in the mechanical means by which the motors move an axis. It is sometimes called "screw mapping" because CNC machines frequently use ball screws to mechanically link the motor and the axis. The compensation we're discussing works for any kind of mechanical linkage.
The relationship between motor position and axis position is theoretically a linear relationship. In reality, It is not (sufficiently) precisely linear. When the CNC commands the motor to go to position X, we expect that the corresponding axis position, Y. We expect that as X increases, Y will increase in direct proportion (by the encoder counts per unit parameter).
There can be many sources of error that cause this non-linearity.
- wear on the screw (making the threads slightly farther apart)
- thread pitch is inaccurate over longer distances
- any mechanical reality that would result in backlash
Mapping the Axis
Map Points and Error
Mach 4 expects that mapping is done at even intervals along the length of travel for an axis. It expects parameters to be in
- Start Point
- This is the smallest (most negative) position of the motor on the axis.
- Length
- This is the (positive) amount of travel in the positive direction from the start point along the axis.
- Number of Points
- The number of (evenly-spaced) points between (and including) the start point and (start point + length).
- This number is one more than the number of "regions" over which you want to measure (e.g. measuring every inch over a 100 inch distance would need 101 points).
- Error at Each Point
- The difference between the expected position and the actual position
Exceeding the Mapped Region
If you command a position outside the mapped region, Mach will assume that the amount of error is zero and smoothly transition over the course of the distance between the map points to that error amount.
Other Parameters
Map Transition Rate (VAL_SCREWMAP_PERCENT_PER)
Mach 4 employs this parameter to determine how quickly the planner transitions from one map to the other (usually when changing directions).
When this value is too small, the resulting motion commanded from Mach 4 will exceed the configured motor velocity/acceleration parameters.
The value the reciprocal of the number of time slices over which the planner should gradually apply more and more of the target map. If you wanted the transition from one map to another to take 50 ms (and your time slice is 1 ms), you would set this parameter to 1 / 50 = 0.02.
| Transition Time (ms) | Transition Rate | Comment |
| 100 | .01 | (Mach 4 default) |
| 20 | .05 | |
| 50 | .02 | |
| 200 | .005 |
The worst case time to transition (to ensure that the transition will not violate the motor velocity/acceleration parameters) can be calculated.
If you use this formula, make sure that you use consistent units for time, and then convert the time to milliseconds.
Comparison of Values
Consider what happens when the CNC changes direction and has to switch between two different maps. The G code for this example would look something like
G1 F300
X49
X50
X49
The graphs show motor position (red: no mapping; blue: mapping enabled) as well as velocity, acceleration, and the correction amount applied.
Transition Time: 100 ms (Value: 0.01)
Transition Time: 10 ms (Value: 0.1)
Note: the acceleration of the commanded move is quite high. This would probably cause a noticeable thump in the motion.
Transition Time: 200 ms (Value 0.005)
Note: the acceleration is lower, but it takes longer to transition to the negative map.




