Algorithmadvanced
Goldberg's part orienting algorithm
Also called squeeze-grasp orienting plan.
Computes a shortest sequence of parallel-jaw squeezes that orients a polygonal part with unknown orientation, up to the symmetry of its squeeze function, in polynomial time.
- Time
- O(n^2 log n) worst
- Space
- O(n^2) extra
- Where
- n = the number of vertices of the convex hull of the part
- Model
- Word RAM
- Properties
- deterministicexactoptimal
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Kenneth Y. Goldberg, 1993
Goldberg's part orienting algorithm takes the vertices of a polygonal part and returns a list of gripper angles. A parallel-jaw gripper that squeezes the part at these angles, one after the other, brings the part to one known orientation, whatever its orientation was at the start. No sensor is used. The plan is the shortest possible, and it exists for every polygonal part, but only up to the symmetry of the part's squeeze function: a square, for example, is oriented only up to quarter turns. This page is the algorithm; sensorless part orienting is the general problem, with other actions such as pushes and tilted trays.
In plain words
Put a flat part between the two jaws of a gripper and close them. The part turns until one of its sides lies flat against a jaw, because that is how it gets thinnest between the jaws. Which side ends up flat depends on how the part was turned at the start, but there are only a few possible results. Now turn the gripper by a chosen angle and squeeze again. A good angle makes several of the possible results end in the same place. Repeat, and the list of possible results gets shorter each time, until only one is left. The algorithm finds the angles. It works backward: first it finds the widest range of starting turns that one squeeze sends to a single result, then the widest range that two squeezes can handle, and so on, until the range covers every starting turn.
The problem
The input is a list of points in the plane, the vertices of a part. Only the convex hull matters, because the jaws touch only hull vertices; let be the number of hull vertices. The model is the one of Goldberg (1993, Section 3): motion in the plane, slow enough that inertia does not matter (quasi-static); two parallel jaws that close along the direction normal to them and touch the part at the same time; no friction between the part and the jaws; a rigid part.
Angles are in radians. Let be the orientation of the part relative to the gripper. The diameter function is the distance between the jaws when both touch the part. It has period , because the gripper turned by is the same gripper. A squeeze turns the part so that decreases, until reaches a local minimum. So the squeeze function maps every between two neighbor local maxima of to the local minimum between them. As in Goldberg's paper, each step is closed on the left and open on the right. The steps continue over the real line, and satisfies
for its smallest period , which divides . Let be the number of steps in one period. A squeeze with the gripper at the world angle maps the world orientation of the part to .
A plan orients the part up to symmetry if every initial orientation ends at the same orientation modulo . Better is not possible: two orientations that differ by stay apart under every squeeze. The task is a shortest such plan.
The algorithm
An s-interval is a union of consecutive steps, with . Its s-image is the closed interval , of length . The algorithm builds a list of s-intervals in which the s-image of is shorter than , so that one squeeze can place it inside . Then it reads the plan off the list from the end.
GOLDBERG-PLAN(P) ▷ P: the vertices of the part- 1
H ← CONVEX-HULL(P) - 2
compute d and s for H: the maxima e_j and the minima m_j, e_j < m_j < e_(j+1) - 3
T ← the smallest period of s; r ← the number of steps in one period - 4
Θ_1 ← the widest step [e_j, e_(j+1)); i ← 1 - 5
while |Θ_i| < T do - 6
Θ_(i+1) ← the widest s-interval [e_p, e_(q+1)) with m_q - m_p < |Θ_i| - 7
i ← i + 1 - 8
k ← i; α_1 ← 0 - 9
for t ← 2 to k do - 10
[a, b) ← Θ_(k-t+1); [m_p, m_q] ← the s-image of Θ_(k-t+2) - 11
α_t ← α_(t-1) + m_p - a - ((b - a) - (m_q - m_p)) / 2 - 12
return (α_1, ..., α_k) and the final orientation α_k + s(Θ_1)
Line L2 needs the extremes of . Between two angles at which a jaw is flush with an edge, the same two vertices touch the jaws, and for the vector between them, a sinusoid with one maximum. At the flush angles has a convex kink, so the local minima are flush angles and the local maxima lie inside the pieces. Line L6 needs no search over all pairs: for each the best is the largest one with , and that grows with , so two pointers find the maximum in steps. Line L11 turns the gripper so that the s-image lands in the middle of the next s-interval, with half the slack on each side.
Example
Take a rectangle of size 2 by 1, with its long side along the axis, and the jaws closing along the axis of the gripper. Then . The minima are at , where and the long sides touch the jaws, and at , where . The maxima are at and . The rectangle has a half-turn symmetry, so and .
| Step | Interval | Width | Maps to |
|---|---|---|---|
| around | |||
| around |
Line L4 picks the wider step: , with . In line L6, the union of both steps, , has the s-image of length , so with . The loop stops with .
Line L11 gives the slack and the angle . The plan is: squeeze at , then squeeze at degrees. After the first squeeze the part is at or in the world frame. Relative to the gripper at these are and , and both are in modulo , so the second squeeze sends both to the world orientation , modulo . The turn of the gripper may err by up to half the slack, rad (18.4 degrees), and the plan still works. Goldberg's own figure gives the plan for a rectangle; it is the mirror image of this one, because the rectangle is symmetric and the tie in line L6 can be broken either way.
The quadrilateral with vertices , , and from Goldberg's paper has no symmetry, and . The algorithm finds s-intervals of lengths , , and , so the shortest plan has 4 squeezes, as in the paper's figure. A square and every regular polygon need one squeeze: their squeeze function has one step per period.
Correctness
The full proof is in proofs/correctness.md. It has four parts. First, a set of orientations can be brought to one orientation by squeezes if and only if it fits in an arc of length ; the proof is an induction on , and the "only if" direction uses that the minima inside an arc shorter than are consecutive. Second, the lengths grow while they are below . This is Goldberg's integral argument: the function has integral 0 over a period, so it is negative somewhere unless is a period, and a point where it is negative gives a longer s-interval. Third, each length is one of at most values, so the loop stops with . Fourth, the whole circle fits in an arc of length only when , so no plan has fewer than squeezes, and the angles of line L11 put each s-image strictly inside the next s-interval.
Proof: Goldberg's algorithm finds a shortest squeeze plan that orients a polygonal part up to the symmetry of its squeeze functionfull
We use the notation of the page. The squeeze function is a nondecreasing step function. Its steps are , closed on the left and open on the right, and step maps to the stable orientation with . The indices run over all integers. is the smallest period of , so for all , and there are steps in one period: and . A squeeze with the gripper at the world angle maps the world orientation of the part to . An arc of length is a set taken modulo ; when it is the whole circle . A set of orientations is collapsible in squeezes if some plan maps all of to one orientation modulo .
The lengths of the algorithm are , the widest step, and, while ,
Line L6 of the page computes this maximum, and the pair that attains it gives the s-interval with the s-image .
Lemma 1 (aliasing). For every plan and every , . So no plan maps and to the same orientation, and the best that a plan can do is to fix the orientation modulo .
Proof. For one squeeze, by the period of . A plan is a composition of squeezes, and each one commutes with the shift by .
Lemma 2 (characterization). Let and assume when . A set of orientations is collapsible in squeezes if and only if lies in an arc of length .
Proof. By induction on .
Case . Let be a widest step. If modulo , squeeze at . Then is in modulo for each , so each goes to modulo . Conversely, let one squeeze at map to one orientation modulo . The minima of one period are different modulo , so different steps of one period map to different orientations. So all with lie in one step modulo , and lies in an arc of length , so also in an arc of length .
Case , with . First the "if" part. Let with , and let lie in the arc . Squeeze at . Each is in modulo , which is the union of the steps to . (When this union covers the circle, so the claim holds for every .) So the image of is in modulo . This set lies in the closed arc from to , of length , so it lies in the arc . By the induction hypothesis, the image is collapsible in squeezes, so is collapsible in .
Now the "only if" part. Let collapse , and let be the image of after the first squeeze. Then is collapsible in squeezes, so by the induction hypothesis lies in an arc of length . Lift to the real interval . The indices with form a run of consecutive integers, because increases with , and . Each point of is modulo for such a . A point goes to only if is in step modulo . So lies in the union of the steps to modulo , which is the arc . Its length is by the definition of . So lies in an arc of length .
Lemma 3 (progress). If , then .
Proof. Let and . The function has period and is a bounded step function on , so it is integrable. With the substitution and the period of ,
so . This is the integral argument of Goldberg (1993, Section 6).
Suppose almost everywhere. Then almost everywhere, so for all outside a set of measure zero. Both sides are continuous from the right. For any , take with and pass to the limit: the identity holds for every . Then is a period of with , which contradicts the choice of as the smallest period.
So on a set of positive measure. The breakpoints form a discrete set, so we can pick in this set such that neither nor is a breakpoint. Let be the step of and the step of ; then , and . Because and are not breakpoints, and . So the pair is allowed in the definition of , and .
Lemma 4 (termination). The loop of lines L5 to L7 stops after at most rounds, with .
Proof. In the definition of , the condition gives . So with , and . By the period, the value depends only on modulo and on , so every is one of at most numbers in . By Lemma 3, the increase strictly while . A strictly increasing sequence in a set of at most numbers has at most terms, so some is not less than , and then .
The bound is only what this short proof gives. Goldberg (1993) proves and Chen and Ierardi (1995) prove squeezes, where is the number of vertices of the convex hull and .
Theorem (correctness and optimality). Let be the first index with . The plan of lines L8 to L11 maps every initial orientation to modulo , where . No plan with fewer than squeezes maps every initial orientation to one orientation modulo .
Proof. Optimality first. The set of all orientations lies in an arc of length only when , because an arc of length less than misses a point of the circle. By Lemma 2, the whole circle is collapsible in squeezes only if . For we have , so no plan of squeezes works.
Now the plan. Write for the pair of level , so that and its s-image is . We show by induction on that after squeeze the world orientation satisfies for some with , where .
For , and has length , so every has in modulo . The squeeze sends it to with .
For the step from to , let be the pair of level and . Line L11 sets with the slack , and because . By the induction hypothesis, , with . So lies in modulo , inside , and the squeeze sends it to some with . This is the claim for .
At the level is , where . So every initial orientation ends at modulo . By Lemma 1, this is the most that any plan can achieve.
Remark (margin). The proof shows more. If the gripper turn between squeezes and errs by less than of level , the orientation still lands strictly inside , and the plan still works. Goldberg (1993, Section 4.1) uses the same half slack for this reason.
Complexity
The cost model is the word RAM of Goldberg's Section 7, in which a distance, an angle, a comparison and an addition of two numbers take time. Goldberg (1993) computes the squeeze function in time, notes that there are s-intervals, sorts them by the length of their s-image, and scans the sorted list once. The sort dominates, so the algorithm runs in time with space. He proves that the plan has squeezes and conjectured ; Chen and Ierardi (1995) proved that squeezes always suffice.
The implementation on this page skips the sort. It computes in time (for each of the pieces it finds the touching vertices by a scan) and each round of line L6 in time with two pointers, where . With the bound of Chen and Ierardi on the number of rounds, the total time is and the extra space is .
Properties
- Optimal. The plan has the least number of squeezes among all plans that orient the part up to symmetry.
- Complete. A plan exists for every polygonal part, because the lengths keep growing until they reach .
- Open loop. The plan uses no sensing. The same angles work for every initial orientation, so a fixed machine can run them.
- Margin. Each turn of the gripper after the first has a slack, and errors below half the slack do not change the result.
- Up to symmetry only. The final orientation is known modulo . A part whose squeeze function has period ends in one of four orientations, and no squeeze plan can tell them apart.
Variants and improvements
- Push-grasp actions. Goldberg (1993, Section 8) lets one jaw touch first and push the part before the second jaw closes. The push function, from the radius function about the center of mass, composes with the squeeze function to a new step function with the same properties, and the same backward search applies. It can remove the half-turn ambiguity of pure squeezes, because the radius function has period for a part without rotational symmetry.
- Pushing only. A fence or a pusher that turns the part to a stable edge gives a push function; the planning is the same. Mason (2001, Section 7.4) presents squeeze and push planning together.
- Shorter worst case. Chen and Ierardi (1995) give plans with squeezes and study plans that tell different parts apart.
- Brute force. A breadth-first search over sets of stable orientations, with the gripper angles at the midpoints between critical angles, also finds a shortest plan. It takes exponential time in , and the test of this page uses it as the reference.
When to use it
Use it to program a parts feeder for flat parts that arrive at random orientations, when the gripper can turn between squeezes and a camera is too slow, too costly or not reliable. Use the push-grasp version when the half-turn ambiguity matters. Use a sensor when the part has symmetries of its squeeze function that the task must resolve, because no squeeze plan can resolve them.
Pitfalls
- Friction at the jaws. The squeeze function assumes frictionless jaws. With friction the part can stay wedged between two vertices. Goldberg suggests a linear bearing on one jaw, and mechanical vibration helps in practice.
- Unstable equilibria. At a maximum of the part is in an unstable balance. The left-closed steps are a convention. A plan with a margin keeps the orientations away from the maxima after the first squeeze.
- Symmetry of , not of the part. The period is the smallest period of the squeeze function. It can be shorter than the symmetry period of the part suggests, so compute it from .
- Floating ties. The angles are irrational, and the comparison can be a tie for symmetric parts. A tolerance must break ties toward the safe side, or the plan can lose its margin.
- Relative turns. The margin bounds the error of each turn between two squeezes, not the error of the absolute angle. An error in one angle shifts all later orientations by the same amount.
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/goldberg-part-orienting-algorithm/. The authors are listed in prov/8BG41W.jsonl.
"""Goldberg's part orienting algorithm for a parallel-jaw gripper.
Model (Goldberg 1993, Section 3): a rigid planar part, a gripper with two
parallel jaws that close at the same time, no friction between the part and
the jaws, and quasi-static motion. Only the convex hull of the part matters.
Angles are floats in radians. The part orientation theta is measured relative
to the gripper. The diameter d(theta) is the distance between the jaws when
both touch the part. A squeeze turns the part to the local minimum of d that
lies between the two local maxima around theta. Steps of the squeeze function
are closed on the left and open on the right, as in the paper. A squeeze with
the gripper at the world angle alpha maps the world orientation phi of the
part to alpha + s(phi - alpha).
All comparisons of angles use the tolerance TOL. The test file states the
tolerances of its checks.
"""
import math
TOL = 1e-9
def convex_hull(points):
"""Andrew's monotone chain. Returns the hull in counterclockwise order."""
pts = sorted(set((float(x), float(y)) for x, y in points))
if len(pts) < 3:
raise ValueError("the part needs at least three points not on a line")
def cross(o, a, b):
return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])
lower, upper = [], []
for p in pts:
while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 0:
lower.pop()
lower.append(p)
for p in reversed(pts):
while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 0:
upper.pop()
upper.append(p)
hull = lower[:-1] + upper[:-1]
if len(hull) < 3:
raise ValueError("the part needs at least three points not on a line")
return hull
def _u(theta):
# The closing direction of the jaws in the frame of the part, when the
# part is turned by theta relative to the gripper.
return (math.sin(theta), math.cos(theta))
def diameter(hull, theta):
"""The distance between the jaws for the relative orientation theta."""
ux, uy = _u(theta)
proj = [x * ux + y * uy for x, y in hull]
return max(proj) - min(proj)
def squeeze_function(hull):
"""Return (maxima, minima) on one period pi of the diameter function.
maxima[j] < minima[j] < maxima[j + 1], with maxima[r] = maxima[0] + pi.
The step j of the squeeze function is [maxima[j], maxima[j + 1]) and it
maps to minima[j].
"""
h = len(hull)
# Breakpoints: a jaw is flush with an edge, so u is normal to the edge.
bps = []
for i in range(h):
ex = hull[(i + 1) % h][0] - hull[i][0]
ey = hull[(i + 1) % h][1] - hull[i][1]
bps.append(math.atan2(-ey, ex) % math.pi)
bps.sort()
uniq = []
for b in bps:
if not uniq or b - uniq[-1] > TOL:
uniq.append(b)
if len(uniq) > 1 and uniq[0] + math.pi - uniq[-1] <= TOL:
uniq.pop()
K = len(uniq)
# On piece t, d(theta) = <w_t, u(theta)> for one antipodal pair.
pieces = []
for t in range(K):
lo = uniq[t]
hi = uniq[t + 1] if t + 1 < K else uniq[0] + math.pi
mid = 0.5 * (lo + hi)
ux, uy = _u(mid)
proj = [x * ux + y * uy for x, y in hull]
i = max(range(h), key=lambda k: proj[k])
j = min(range(h), key=lambda k: proj[k])
w = (hull[i][0] - hull[j][0], hull[i][1] - hull[j][1])
pieces.append((lo, hi, w))
def slope(w, theta):
return w[0] * math.cos(theta) - w[1] * math.sin(theta)
maxima, minima = [], []
for t, (lo, hi, w) in enumerate(pieces):
# A local minimum sits at a breakpoint where d turns from down to up.
# The left piece of piece 0 is the last piece, which ends at lo + pi.
hl, wl = pieces[t - 1][1], pieces[t - 1][2]
if slope(wl, hl) < 0 < slope(w, lo):
minima.append(lo)
# A local maximum is inside a piece, where the slope is zero.
top = math.atan2(w[0], w[1])
top = lo + ((top - lo) % math.pi)
if lo + TOL < top < hi - TOL:
maxima.append(top % math.pi)
maxima.sort()
minima.sort()
if len(maxima) != len(minima) or not maxima:
raise ValueError("degenerate diameter function")
# Pair each step [e_j, e_(j+1)) with the minimum inside it.
r = len(maxima)
e = maxima + [maxima[0] + math.pi]
m = []
for j in range(r):
inside = [x for x in minima + [y + math.pi for y in minima]
if e[j] < x < e[j + 1]]
if len(inside) != 1:
raise ValueError("degenerate diameter function")
m.append(inside[0])
return e[:r], m
def smallest_period(e, m):
"""Return (T, c): the smallest period T of s and c steps per period."""
r = len(e)
e2 = e + [x + math.pi for x in e]
width = [e2[j + 1] - e2[j] for j in range(r)]
offset = [m[j] - e[j] for j in range(r)]
for c in range(1, r + 1):
if r % c:
continue
if all(abs(width[j] - width[(j + c) % r]) < TOL and
abs(offset[j] - offset[(j + c) % r]) < TOL for j in range(r)):
return math.pi * c / r, c
return math.pi, r
class Squeeze:
"""The squeeze function of a part, with its smallest period T."""
def __init__(self, points):
self.hull = convex_hull(points)
e, m = squeeze_function(self.hull)
self.T, self.r = smallest_period(e, m)
self.e0 = e[:self.r] # maxima in one period
self.m0 = m[:self.r] # minima in one period
def e(self, j):
"""Maximum j, for any integer j (unrolled over the periods)."""
q, k = divmod(j, self.r)
return self.e0[k] + q * self.T
def m(self, j):
q, k = divmod(j, self.r)
return self.m0[k] + q * self.T
def step_of(self, theta):
"""The unrolled index j with e(j) <= theta < e(j + 1)."""
q = math.floor((theta - self.e0[0]) / self.T)
j = q * self.r
x = theta - q * self.T
k = 0
while k + 1 < self.r and self.e0[k + 1] <= x:
k += 1
return j + k
def s(self, theta):
return self.m(self.step_of(theta))
def act(self, phi, alpha):
"""World orientation after a squeeze with the gripper at alpha."""
return alpha + self.s(phi - alpha)
def plan(points):
"""Goldberg's algorithm.
Returns (alphas, final, S, levels). alphas are the gripper angles of the
shortest plan, final is the world orientation of the part after the plan
(modulo S.T), and levels is the list of s-intervals (p, q) with
Theta_i = [e(p), e(q + 1)) and s-image [m(p), m(q)].
"""
S = Squeeze(points) # @line L1 @line L2 @line L3
r, T = S.r, S.T
j = max(range(r), key=lambda k: S.e(k + 1) - S.e(k))
levels = [(j, j)] # @line L4
length = S.e(j + 1) - S.e(j)
while length < T - TOL: # @line L5
best, arg = -1.0, None
q = 0
for p in range(r): # @line L6
# Two pointers: the largest q with m(q) - m(p) < length.
q = max(q, p)
while q + 1 < p + r and S.m(q + 1) - S.m(p) < length - TOL:
q += 1
w = S.e(q + 1) - S.e(p)
if w > best + TOL:
best, arg = w, (p, q)
if best <= length + TOL:
raise ArithmeticError("no progress; the tolerance hides a tie")
levels.append(arg) # @line L7
length = best
k = len(levels) # @line L8
alphas = [0.0] # @line L8
for t in range(2, k + 1): # @line L9
p, q = levels[k - t + 1] # @line L10
a, b = S.e(levels[k - t][0]), S.e(levels[k - t][1] + 1) # @line L10
slack = (b - a) - (S.m(q) - S.m(p))
alphas.append(alphas[-1] + S.m(p) - a - slack / 2.0) # @line L11
final = alphas[-1] + S.m(levels[0][0])
return alphas, final, S, levels # @line L12
def run_plan(S, alphas, phi):
"""Execute a plan from the world orientation phi."""
for alpha in alphas:
phi = S.act(phi, alpha)
return phi
def same_mod(x, y, T, tol=1e-7):
d = (x - y) % T
return min(d, T - d) < tol
test_goldberg_part_orienting_algorithm.py 179 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/goldberg-part-orienting-algorithm/. The authors are listed in prov/8BG41W.jsonl.
# Angles are floats. Checks of angles use the tolerance 1e-7 unless a test
# states another one. The grid check of the squeeze function uses 4000 grid
# points on [0, pi) and allows 3 grid steps of error.
import math
import random
from goldberg_part_orienting_algorithm import (Squeeze, convex_hull, diameter,
plan, run_plan, same_mod)
RECT = [(-1, -0.5), (1, -0.5), (1, 0.5), (-1, 0.5)]
GOLDBERG_4GON = [(-42, -41), (48, -41), (39, 25), (-34, 59)]
def regular(k):
return [(math.cos(2 * math.pi * i / k), math.sin(2 * math.pi * i / k))
for i in range(k)]
def random_part(rng, n):
while True:
pts = [(rng.uniform(-1, 1), rng.uniform(-1, 1)) for _ in range(n)]
try:
S = Squeeze(pts)
except ValueError:
continue
return pts, S
# Reference: breadth-first search over sets of stable orientations. After the
# first squeeze the part is at one of the r minima of a period. The outcome of
# a squeeze at alpha changes only where some m_j - alpha crosses a maximum,
# so the midpoints between the sorted critical values cover every outcome.
def brute_force_length(S):
r, T = S.r, S.T
start = frozenset(range(r))
if len(start) == 1:
return 1
seen = {start}
frontier = [start]
depth = 1
while frontier:
depth += 1
nxt = []
for J in frontier:
crit = sorted(set(round((S.m(j) - S.e(i)) % T, 12)
for j in J for i in range(r)))
cands = [(crit[i] + crit[(i + 1) % len(crit)] +
(T if i + 1 == len(crit) else 0)) / 2
for i in range(len(crit))]
for alpha in cands:
J2 = frozenset(S.step_of(S.m(j) - alpha) % r for j in J)
if len(J2) == 1:
return depth
if J2 not in seen:
seen.add(J2)
nxt.append(J2)
frontier = nxt
raise AssertionError("no plan found")
def grid_squeeze(hull, theta, N=4000):
# Walk downhill on a grid of the diameter function.
h = math.pi / N
i = round(theta / h)
d = lambda k: diameter(hull, k * h)
while True:
if d(i - 1) < d(i) and d(i - 1) <= d(i + 1):
i -= 1
elif d(i + 1) < d(i):
i += 1
else:
return i * h
def test_rectangle_check_values():
alphas, final, S, levels = plan(RECT)
a = math.atan(2.0)
assert abs(S.T - math.pi) < 1e-12 and S.r == 2
widths = sorted(S.e(j + 1) - S.e(j) for j in range(2))
assert abs(widths[0] - (math.pi - 2 * a)) < 1e-9
assert abs(widths[1] - 2 * a) < 1e-9
assert len(alphas) == 2
assert abs(alphas[0]) < 1e-12 and abs(alphas[1] + math.pi / 4) < 1e-9
assert same_mod(final, 3 * math.pi / 4, math.pi)
assert abs(diameter(S.hull, 0.0) - 1.0) < 1e-12
assert abs(diameter(S.hull, math.pi / 2) - 2.0) < 1e-12
def test_regular_polygons_need_one_squeeze():
# Goldberg: a part with k-fold symmetry has T = 2 pi / (k (1 + k mod 2)).
for k in range(3, 9):
alphas, final, S, levels = plan(regular(k))
assert abs(S.T - 2 * math.pi / (k * (1 + k % 2))) < 1e-9
assert len(alphas) == 1
def test_goldberg_quadrilateral_needs_four_squeezes():
alphas, final, S, levels = plan(GOLDBERG_4GON)
assert abs(S.T - math.pi) < 1e-12 and S.r == 4
assert len(alphas) == 4
assert brute_force_length(S) == 4
def test_squeeze_function_against_grid_descent():
rng = random.Random(7)
for _ in range(4):
pts, S = random_part(rng, 7)
hull = convex_hull(pts)
for _ in range(20):
theta = rng.uniform(0, math.pi)
if any(abs((theta - S.e(j)) % math.pi) < 0.01 or
abs((S.e(j) - theta) % math.pi) < 0.01
for j in range(-S.r, 2 * S.r)):
continue
g = grid_squeeze(hull, theta)
assert same_mod(g, S.s(theta), math.pi, tol=3 * math.pi / 4000)
def test_period_identity():
rng = random.Random(3)
for _ in range(10):
pts, S = random_part(rng, 6)
for _ in range(50):
t = rng.uniform(-5, 5)
assert abs(S.s(t + S.T) - S.s(t) - S.T) < 1e-9
assert S.e(S.step_of(t)) <= t + 1e-12 < S.e(S.step_of(t) + 1)
def test_plan_orients_every_start():
rng = random.Random(11)
for _ in range(25):
pts, S = random_part(rng, rng.randint(3, 9))
alphas, final, S, levels = plan(pts)
starts = [rng.uniform(-4, 4) for _ in range(300)]
# Also start exactly at and next to each discontinuity.
starts += [S.e(j) + d for j in range(-S.r, S.r)
for d in (0.0, 1e-9, -1e-9)]
for phi in starts:
assert same_mod(run_plan(S, alphas, phi), final, S.T)
def test_margin_of_later_squeezes():
# The rotation of the gripper between squeezes t - 1 and t may err by
# less than half the slack of level k - t + 1.
rng = random.Random(5)
for _ in range(10):
pts, S = random_part(rng, 8)
alphas, final, S, levels = plan(pts)
k = len(alphas)
for _ in range(100):
noisy = [alphas[0]]
for t in range(2, k + 1):
p, q = levels[k - t + 1]
a = S.e(levels[k - t][0])
b = S.e(levels[k - t][1] + 1)
half = ((b - a) - (S.m(q) - S.m(p))) / 2
turn = alphas[t - 1] - alphas[t - 2]
noisy.append(noisy[-1] + turn +
rng.uniform(-0.99, 0.99) * half)
phi = rng.uniform(0, 7)
# The part ends at the planned stable orientation relative to
# the last gripper angle.
out = run_plan(S, noisy, phi)
assert same_mod(out - noisy[-1], final - alphas[-1], S.T)
def test_optimal_against_brute_force():
rng = random.Random(2024)
lengths = []
for _ in range(30):
pts, S = random_part(rng, rng.randint(4, 9))
alphas, final, S, levels = plan(pts)
assert len(alphas) == brute_force_length(S)
lengths.append(len(alphas))
assert max(lengths) >= 3
History
Erdmann and Mason (1988) showed that parts can be oriented without sensors, by tilting a tray. Goldberg (1993) turned the squeeze of a parallel-jaw gripper into the step function and proved that every polygonal part can be oriented up to symmetry by squeezes alone, with a shortest plan found in time. He conjectured that plans of squeezes always exist, and Chen and Ierardi (1995) proved it. Mason (2001) gives the method as the main example of sensorless parts orienting.
References
- Kenneth Y. Goldberg, Orienting polygonal parts without sensors, Algorithmica 10, 201-225, 1993, Section 3 (assumptions, the diameter and squeeze functions, steps closed on the left, period T), Section 4 (the algorithm and the recovery of the plan), Sections 5 and 6 (shortest plan and completeness), Section 7 (O(n^2 log n) time, plans of length O(n^2)), Section 8 (push-grasp actions)
- Yu-Bin Chen and Doug J. Ierardi, The complexity of oblivious plans for orienting and distinguishing polygonal parts, Algorithmica 14(5), 367-397, 1995, the whole paper (plans of O(n) squeezes, which proves Goldberg's conjecture)
- Matthew T. Mason, Mechanics of Robotic Manipulation, MIT Press, 2001, Chapter 7, Section 7.4 (parts orienting)
- Michael A. Erdmann and Matthew T. Mason, An exploration of sensorless manipulation, IEEE Journal of Robotics and Automation 4(4), 369-379, 1988, the whole paper (orienting parts in a tilted tray without sensors, the setting that Goldberg's work continues)
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 8BG41W Edit this page History Report an error Markdown