Algorithmresearch
Constant engagement toolpath
Also called adaptive clearing, engagement angle control.
Stori and Wright's and later toolpaths that bound the angle of tool engagement with the material by curved paths and medial axis spirals, for high-speed roughing.
- Solves
- Pocket machining
- Time
- O(m (n + k)) worst
- Space
- O(m) extra
- Where
- k = number of pixels in the box around one move; m = number of tool moves; n = number of samples on the front half circle
- Model
- Real RAM
- Properties
- deterministiciterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- J. A. Stori, P. K. Wright, 2000
A constant engagement toolpath is a roughing path for pocket machining along which the angle of the tool circle that is in contact with the material stays near a chosen value. The engagement angle sets the load on the tool and the chip thickness. An ordinary contour-parallel path keeps the distance between passes constant, so the engagement jumps at inner corners and grows on curves that bend toward the material, and the feed must be set for the worst case. A constant engagement path changes the distance between passes instead, so the tool can run at a high feed everywhere. Stori and Wright gave the first construction in 2000, for convex shapes. Commercial systems call the idea adaptive clearing. The version here grows the path step by step: it keeps a pixel model of the stock and, at each step, turns the tool until the measured engagement equals the target.
In plain words
A cutter that moves through a block of metal touches the uncut metal along part of its edge. The size of that part is the engagement. A big engagement is a heavy load, and a small one wastes time.
If the cutter goes round a pocket in rings that are always the same distance apart, the load is not steady. In a corner or on a bend the cutter suddenly bites much more.
So the method does not fix the distance. It keeps a picture of the metal that is left. Before each small move, it looks at how much of the cutter edge would touch metal in each direction it could go. Then it steers toward the metal or away from it until the touch is just right, makes the move, and erases the metal it cut from the picture.
The problem
The tool is a disk of radius that moves in the plane. At the center with the feed direction , the front half circle is the set of points with . The engagement angle is the measure of the part of the front half circle that lies in the remaining material. Given the initial material, a start point, a start heading and a target , the task is to produce a sequence of tool moves along which stays close to and the material is removed.
Two closed forms set the scale. For a straight cut that leaves a wall at the radial depth inside the tool,
For a tool on a circle of radius that cuts into material outside the radius about the same center,
So for a fixed stepover , with , the engagement on a circle is larger than on a straight line, and it grows as falls. To keep , the stepover must be
which is smaller on tight curves. Both formulas are proved in the proof file.
The algorithm
The generator below moves the tool by a fixed step . The material lies on the side side of the path, for the left and for the right. Let be the engagement, sampled at points of the front half circle in the pixel stock, at the point with the heading .
CONSTANT-ENGAGEMENT-PATH(stock, c, ψ, R, θ*, σ, Δ, m, side)- 1
repeat m times - 2
E(φ) ← sampled engagement at c + σ(cos φ, sin φ) with heading φ - 3
toward ← ψ + side·Δ; away ← ψ − side·Δ ▷ the turn limits - 4
if E(away) ≥ θ* then φ ← away ▷ too much material even when turning away - 5
else if E(toward) ≤ θ* then φ ← toward ▷ too little even when turning in - 6
else bisect φ between toward and away 12 times so that E crosses θ* - 7
remove the capsule of radius R around the segment c to c + σ(cos φ, sin φ) from the stock - 8
append (c + σ(cos φ, sin φ), φ, E(φ)) to the path; c, ψ ← that point, φ - 9
return the path
Turning toward the material raises the engagement, and turning away lowers it. Line L6 keeps a bracket with . The stock is a grid of pixels of side . A pixel is cut when its center is within of the move segment, so the stock always equals the initial material minus the swept capsules, at pixel resolution.
Example
The tool has , and the target is . On a straight wall, needs the depth . On a circle of radius , the same angle needs the stepover , and the stepover 2.5 gives instead. The table compares the pixel engagement, with and samples of , with the closed form for some circles.
| pixel | closed form | straight cut with the same | ||
|---|---|---|---|---|
| 8 | 1 | |||
| 10 | 2 | |||
| 15 | 2 | |||
| 25 | 3 |
In the test run, the stock is the square with a round hole of radius 8 cut in the middle, and the tool starts at , heading up, with the material on its right. The step is and the turn limit is . In 600 steps the tool spirals out from the radius 5.64 to 13.33, and from step 100 on the engagement stays between and . An Archimedean spiral with the fixed pitch 2.5, the straight-cut stepover for , cut to the same radius in the same stock, has engagements from to after the same warm-up. Started on a straight wall at the depth 1, the generator turns into the material and settles at the depth 2.5.
Correctness
The proof file proves the straight and circular closed forms and the stepover formula. For the generator it proves what a single step does. The stock invariant holds: after each step the pixel stock is exactly the initial material minus the pixels within of the segments cut so far. The new heading is within of the old one. When the target lies between and , the bisection returns a heading inside an interval of width on which the sampled engagement crosses the target. The generator stops after steps.
What is proved and what is measured. The step is proved, but the path as a whole is not. No result here says that the engagement stays near the target over many steps, that the path leaves no islands of material, or that it clears the pocket. The tests measure these things. The generator holds to after a warm-up, which is within one sample of the target. It does more than twice as well as a fixed-pitch spiral. The pixel engagement is within two samples of an engagement computed with exact rational arithmetic from the true union of the cut capsules. It is within one sample plus of the closed forms on straight and circular cuts.
Proof: The engagement angle has closed forms for straight and circular cuts, and each step of the generator keeps the pixel stock exact and picks a heading at which the engagement crosses the targetfull
Setting. The tool is a disk of radius with center , moving in the unit direction . Let be turned by . The front half circle is . The engagement angle is the measure of the set of whose point is in material. The code samples values of , at the centers of equal arcs, so it returns the measure of the sampled set, times the fraction of samples in material.
Claim 1 (straight cut). Let the material be the half-plane above a line parallel to , at the distance inside the tool, measured from the side of the tool farthest into the material: in coordinates with and , the material is . Then .
Proof. The point at has height . It is in material when . On , is increasing, so the set is , of measure .
Claim 2 (circular cut). Let the tool center move on the circle of radius about , counterclockwise, so is the tangent, and let be the outward unit normal at . Let the material ahead of the tool be the set of points at distance more than from , with . Then
Proof. Write a point of the tool circle as , with measured from toward . Its squared distance from is , since and . So it lies beyond exactly when , with the right side above, that is when . The front half is -side: , that is . On it, the material set is , of measure . Points with lie behind the tool; in a steady pass they were already removed by earlier positions of the same pass, and in any case they are not in the front half.
Claim 3 (constant engagement stepover on a circle). If the previous pass left the boundary at , the engagement equals exactly when
Proof. Claim 2 with gives , and , so is the positive root. Solve for .
As this tends to , the stepover of Claim 1, and for finite it is smaller, because when .
Claim 4 (one step of the generator). Assume that before a step the stock holds exactly the pixels whose centers are in the initial material and at distance more than from every segment cut so far. Then:
(a) after line L7 the same holds with the new segment added;
(b) the new heading lies within the allowed turn of the old heading ;
(c) let be the sampled engagement at with heading . If , the bisection of line L6 ends with two headings and , , with , and returns their midpoint. In the other cases it returns the end of the allowed range that is nearest to the target, as lines L4 and L5 say.
Proof. (a) The function cut_capsule visits every pixel whose center can be within of the segment (a box around it), computes the exact nearest point of the segment to the center by clamping the projection parameter to , and clears the pixel when the distance is at most . No other pixel changes. (b) Lines L3 to L6 only return toward, away, or a point between them, which are . (c) The bisection keeps the invariant : it holds at the start by the case condition, and each step replaces or by the midpoint according to the side of on which falls. After 12 halvings the interval has length .
Termination. Each step evaluates at most 15 times, each evaluation looks at samples, and each cut visits a finite box of pixels. So the generator stops after its given number of steps.
What is proved and what is measured. Claims 1 to 3 are exact statements about the engagement of a disk. Claim 4 says what one step does: the stock stays exact for the pixel model, and the heading is a point where the sampled engagement crosses the target. If the engagement grows as the heading turns toward the material, which holds for the smooth boundaries met in the tests, this crossing is where the engagement equals the target up to the sample step of . Nothing here proves that a whole path keeps the engagement near the target, avoids leaving islands of material, or finishes the region. Those are measured: in the tests the path holds to after a warm-up, the pixel engagement agrees with an exact stock (Fractions, union of capsules) to within two samples, and it matches Claims 1 and 2 to within one sample plus .
Complexity
One evaluation of looks at points, each in time. Each step evaluates at most 15 times and cuts one capsule, which visits the pixels in a box around the segment, about of them. So steps take time. The stock takes the space of its pixel grid, which the caller provides, and the path takes space. In practice the stock is the main cost. A finer grid gives a more accurate engagement and costs quadratically more per cut.
Properties
- Steady load. The engagement stays close to the target wherever the turn limit allows the path to follow the material.
- Variable stepover. The distance between passes is not constant. It shrinks on curves that bend toward the material and in corners.
- Stock driven. The path depends on the actual remaining material, so it handles rest material and partly cut regions.
- Local and greedy. Each step looks only at the next move. Nothing in the method plans the whole pocket.
Variants and improvements
- Offset construction. Stori and Wright built each pass as a curve at the stepover of the stepover formula from the previous one, for convex shapes, with no stock model.
- Medial axis spirals. Elber, Cohen and Drake grow a spiral out from the medial axis of the pocket, so that the passes change slowly and the engagement does not jump. Fermat spiral and Voronoi paths are related.
- Stock models. A pixel grid is the simplest stock. A z-map, a polygon model of the stock boundary, or a distance transform gives the engagement faster or more accurately.
- Feed adjustment. Instead of changing the path, a planner can keep the path and change the feed to keep the chip thickness constant. This is a case of feedrate scheduling.
- Trochoidal moves. Where the stepover would have to be very small, for example in a narrow slot, many systems switch to trochoidal milling.
When to use it
Use a constant engagement path for roughing of pockets and open regions in hard materials at high speed, where tool load decides the tool life, and the machine can follow smooth curves at a high feed. In a soft material at a low speed, a simple contour-parallel or zigzag path is shorter and often faster.
Difference from trochoidal milling. Trochoidal milling is a fixed geometric pattern: a circle of loops that moves forward along a slot, with the same shape everywhere. It bounds the engagement by making the loops small, and the engagement still varies within each loop, from zero on the return to its highest value as the tool comes round to the front. A constant engagement path is computed from the stock, so its shape changes with the material, and it aims to keep the engagement at one value along the whole path.
Pitfalls
- Islands of material. A greedy path can leave thin islands or uncut regions between passes. A real system needs a final check of the stock and clean-up moves.
- Pixel noise. The sampled engagement moves in steps of , and a coarse grid shifts the boundary by up to a pixel. Choose much smaller than the stepover.
- The turn limit. A small keeps the path smooth but cannot follow sharp corners, so the engagement rises there. A large gives a path that zigzags, which the machine cannot follow at full feed.
- Engagement is not the only load. The axial depth, the chip thinning at small angles and the machine dynamics also matter. A constant angle does not mean a constant force.
- Air moves. Where there is no material, the engagement is zero, and the generator turns toward the material at the turn limit. It needs a rule to link to the next region.
Implementations
Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/constant-engagement-toolpath/. The authors are listed in prov/X9MBE5.jsonl.
"""A constant engagement toolpath, generated step by step from a pixel stock.
The stock is a grid of square pixels of side d; a pixel holds material until
the tool removes it. The tool is a disk of radius R. Its engagement angle at
the center c, moving in the direction psi, is the angle of the front half of
the tool circle (the points within 90 degrees of the feed direction) that
lies in material. It is sampled at n points of the front half circle.
For a straight cut with radial depth a, the engagement is arccos(1 - a/R).
For a tool on a circle of radius rho, cutting into material outside the
circle of radius Rb around the same center, it is
arccos((Rb^2 - rho^2 - R^2) / (2 rho R)).
The generator moves the tool by a step s at a time. At each step it chooses
the new heading within max_turn of the old one so that the engagement at
the new position equals the target, by bisection, then removes the swept
capsule from the stock. The material lies on the side `side` of the path:
+1 for the left, -1 for the right.
"""
import math
class Stock:
"""A pixel stock on [x0, x0 + nx d] x [y0, y0 + ny d]."""
def __init__(self, x0, y0, d, nx, ny, material):
self.x0, self.y0, self.d, self.nx, self.ny = x0, y0, d, nx, ny
self.cells = bytearray(nx * ny)
for j in range(ny):
y = y0 + (j + 0.5) * d
for i in range(nx):
if material(x0 + (i + 0.5) * d, y):
self.cells[j * nx + i] = 1
def has(self, x, y):
i = math.floor((x - self.x0) / self.d)
j = math.floor((y - self.y0) / self.d)
if 0 <= i < self.nx and 0 <= j < self.ny:
return self.cells[j * self.nx + i] == 1
return False
def cut_capsule(self, a, b, r):
"""Remove the pixels whose centers are within r of the segment from a to b."""
d = self.d
i0 = max(0, math.floor((min(a[0], b[0]) - r - self.x0) / d))
i1 = min(self.nx - 1, math.floor((max(a[0], b[0]) + r - self.x0) / d))
j0 = max(0, math.floor((min(a[1], b[1]) - r - self.y0) / d))
j1 = min(self.ny - 1, math.floor((max(a[1], b[1]) + r - self.y0) / d))
ex, ey = b[0] - a[0], b[1] - a[1]
ee = ex * ex + ey * ey
rr = r * r
for j in range(j0, j1 + 1):
y = self.y0 + (j + 0.5) * d
row = j * self.nx
for i in range(i0, i1 + 1):
x = self.x0 + (i + 0.5) * d
px, py = x - a[0], y - a[1]
t = 0.0 if ee == 0 else min(1.0, max(0.0, (px * ex + py * ey) / ee))
qx, qy = px - t * ex, py - t * ey
if qx * qx + qy * qy <= rr:
self.cells[row + i] = 0
def front_points(c, psi, R, n=60):
"""The n sample points of the front half of the tool circle, at the centers of n equal arcs."""
pts = []
for k in range(n):
t = psi - math.pi / 2 + math.pi * (k + 0.5) / n
pts.append((c[0] + R * math.cos(t), c[1] + R * math.sin(t)))
return pts
def engagement(stock, c, psi, R, n=60):
"""The engagement angle in degrees, from n samples of the front half circle."""
return 180.0 * sum(1 for x, y in front_points(c, psi, R, n) if stock.has(x, y)) / n
def straight_engagement(a, R):
"""Closed form for a straight cut of radial depth a, 0 <= a <= 2R, in degrees."""
return math.degrees(math.acos(1 - a / R))
def circle_engagement(rho, Rb, R):
"""Closed form for a tool on a circle of radius rho with material outside radius Rb."""
c = (Rb * Rb - rho * rho - R * R) / (2 * rho * R)
return math.degrees(math.acos(max(-1.0, min(1.0, c))))
def constant_engagement_path(stock, c, psi, R, target, step, max_turn, n_steps, side=-1, n=60):
"""Generate n_steps tool moves that hold the engagement at target (degrees).
Returns a list of (center, heading, engagement) after each move. The
stock is cut as the tool moves.
"""
path = []
def E(phi): # @line L2
p = (c[0] + step * math.cos(phi), c[1] + step * math.sin(phi))
return engagement(stock, p, phi, R, n)
for _ in range(n_steps): # @line L1
toward, away = psi + side * max_turn, psi - side * max_turn # @line L3
if E(away) >= target: # @line L4
phi = away
elif E(toward) <= target: # @line L5
phi = toward
else: # @line L6
lo, hi = toward, away
for _ in range(12):
mid = (lo + hi) / 2
if E(mid) > target:
lo = mid
else:
hi = mid
phi = (lo + hi) / 2
e = E(phi)
nc = (c[0] + step * math.cos(phi), c[1] + step * math.sin(phi))
stock.cut_capsule(c, nc, R) # @line L7
path.append((nc, phi, e)) # @line L8
c, psi = nc, phi
return path # @line L9
def follow_path(stock, centers, R, n=60):
"""Cut along a given list of centers and record the engagement at each one."""
out = []
for a, b in zip(centers, centers[1:]):
psi = math.atan2(b[1] - a[1], b[0] - a[0])
out.append(engagement(stock, b, psi, R, n))
stock.cut_capsule(a, b, R)
return out
test_constant_engagement_toolpath.py 137 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/constant-engagement-toolpath/. The authors are listed in prov/X9MBE5.jsonl.
import math
import random
from fractions import Fraction as F
import pytest
from constant_engagement_toolpath import (
Stock,
circle_engagement,
constant_engagement_path,
engagement,
follow_path,
front_points,
straight_engagement,
)
R = 5.0
D = 0.2
N = 60
STEP = 180.0 / N # the angle of one sample
def square_stock(L, material):
return Stock(-L, -L, D, int(2 * L / D), int(2 * L / D), material)
@pytest.mark.parametrize("a", [0.5, 1.0, 2.0, 2.5, 4.0, 5.0, 7.5, 9.5])
def test_straight_cut_matches_closed_form(a):
# material above y = 0; the tool center is at y = a - R, moving along +x
stock = square_stock(20.0, lambda x, y: y >= 0)
e = engagement(stock, (0.3, a - R), 0.0, R, N)
assert abs(e - straight_engagement(a, R)) <= STEP + 2.0
@pytest.mark.parametrize("rho,s", [(8.0, 1.0), (10.0, 2.0), (15.0, 2.0), (25.0, 3.0), (10.0, 4.0)])
def test_circular_cut_matches_closed_form(rho, s):
Rb = rho - s + R
stock = square_stock(40.0, lambda x, y: x * x + y * y > Rb * Rb)
e = engagement(stock, (rho, 0.0), math.pi / 2, R, N)
assert abs(e - circle_engagement(rho, Rb, R)) <= STEP + 2.0
def test_closed_form_numbers():
assert math.isclose(straight_engagement(2.0, 5.0), 53.13010235415598)
assert math.isclose(circle_engagement(10.0, 13.0, 5.0), math.degrees(math.acos(0.44)))
assert abs(circle_engagement(10.0, 13.0, 5.0) - 63.90) < 0.005
# the stepover that gives 53.13 degrees on a circle of radius 10
s = 10 + 5 - math.sqrt(100 + 25 + 2 * 10 * 5 * 0.6)
assert math.isclose(s, 1.3985, abs_tol=1e-4)
assert math.isclose(circle_engagement(10.0, 10.0 - s + 5.0, 5.0), 53.13010235415598)
HOLE = 8.0
L = 26.0
def spiral_run(n_steps):
stock = square_stock(L, lambda x, y: x * x + y * y > HOLE * HOLE)
start = (HOLE - R, 0.0)
path = constant_engagement_path(stock, start, math.pi / 2, R, 60.0, 0.5, math.radians(15), n_steps, side=-1, n=N)
return start, path
def exact_engagement(start, path, k):
"""Engagement at path[k] from the exact stock: the square minus the hole minus
the capsules cut before step k, tested with Fractions on the same sample points."""
centers = [start] + [c for c, _, _ in path]
caps = [(centers[i], centers[i + 1]) for i in range(k)] # cut before reaching path[k]
c, psi, _ = path[k]
rr = F(R) ** 2
hole2 = F(HOLE) ** 2
count = 0
for x, y in front_points(c, psi, R, N):
fx, fy = F(x), F(y)
if not (-L <= fx <= L and -L <= fy <= L and fx * fx + fy * fy > hole2):
continue
cut = False
for a, b in caps:
# a float prefilter with a wide margin, then the exact test
ex, ey = b[0] - a[0], b[1] - a[1]
t = max(0.0, min(1.0, ((x - a[0]) * ex + (y - a[1]) * ey) / (ex * ex + ey * ey)))
if math.hypot(x - a[0] - t * ex, y - a[1] - t * ey) > R + 1e-6:
continue
ax, ay, bx, by = F(a[0]), F(a[1]), F(b[0]), F(b[1])
ex, ey = bx - ax, by - ay
t = ((fx - ax) * ex + (fy - ay) * ey) / (ex * ex + ey * ey)
t = min(F(1), max(F(0), t))
qx, qy = fx - ax - t * ex, fy - ay - t * ey
if qx * qx + qy * qy <= rr:
cut = True
break
if not cut:
count += 1
return 180.0 * count / N
def test_pixel_engagement_matches_exact_stock():
start, path = spiral_run(300)
rng = random.Random(5)
for k in [40, 120] + rng.sample(range(150, 300), 3):
exact = exact_engagement(start, path, k)
assert abs(path[k][2] - exact) <= 2 * STEP
def test_generator_holds_the_target_and_beats_constant_stepover():
_, path = spiral_run(600)
dev_gen = max(abs(e - 60.0) for _, _, e in path[100:])
assert dev_gen <= STEP + 1.0
# the path really spirals out
r_end = math.hypot(*path[-1][0])
assert r_end > HOLE + 3
# an Archimedean spiral with the straight-cut stepover for 60 degrees
stock = square_stock(L, lambda x, y: x * x + y * y > HOLE * HOLE)
s0 = R * (1 - math.cos(math.radians(60)))
centers, phi, r = [], 0.0, HOLE - R
while r < r_end:
centers.append((r * math.cos(phi), r * math.sin(phi)))
phi += 0.5 / r
r += s0 * (0.5 / r) / (2 * math.pi)
es = follow_path(stock, centers, R, N)
dev_spiral = max(abs(e - 60.0) for e in es[100:])
assert dev_spiral >= 9.0
assert dev_spiral > 2 * dev_gen
def test_generator_settles_on_a_straight_wall():
# Material above y = 0; the tool starts with depth 1 and must find the
# depth R (1 - cos 60) = 2.5, where the straight engagement is 60 degrees.
stock = Stock(-5.0, -10.0, D, 400, 100, lambda x, y: y >= 0)
path = constant_engagement_path(stock, (0.0, 1.0 - R), 0.0, R, 60.0, 0.5, math.radians(10), 120, side=1, n=N)
ys = [c[1] for c, _, _ in path[60:]]
depth = sum(ys) / len(ys) + R
assert abs(depth - 2.5) <= 0.3
assert all(abs(e - 60.0) <= STEP + 1.0 for _, _, e in path[60:])
History
High-speed machining in the 1990s made tool load a main concern of roughing. Stori and Wright (2000) defined the constant engagement problem for pockets and gave an offset construction for convex shapes. Elber, Cohen and Drake (2005) used the medial axis to build spirals whose passes change slowly. Through the 2000s CAM systems added roughing strategies that compute the path from a model of the remaining stock and keep the engagement or the chip thickness within bounds. They are sold under names such as adaptive clearing.
References
- J. A. Stori and P. K. Wright, Constant engagement tool path generation for convex geometries, Journal of Manufacturing Systems 19(3), 172-184, 2000, the engagement angle of a tool on a curved path and the construction of offsets that keep it constant
- Gershon Elber, Elaine Cohen and Sam Drake, MATHSM, medial axis transform toward high speed machining of pockets, Computer-Aided Design 37(2), 241-250, 2005, the spiral paths built on the medial axis that limit the change of engagement in a pocket
- Byoung K. Choi and Robert B. Jerard, Sculptured Surface Machining, Theory and Applications, Kluwer Academic Publishers, 1998, the material on pocket machining and the stock models used for simulation
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag X9MBE5 Edit this page History Report an error Markdown