Careful Bot Finds the target

Control Barrier Functions on a robot arm

The rule itself. The arm is the dot; it can never fall below the curve.

How it works

1Where the end effector is

p(q) = Σi Li ( cos(q₁ + … + qi) , sin(q₁ + … + qi) )[1]

Each angle is measured against the link before it, so the angles simply add up. Everything below is, by default, a rule about that one point at the end — Expert mode extends it to the whole arm — and the formula does not care whether there are two joints or four.

ṗ = J(q) q̇ ,column i of J isẑ × ( p − joint i )[1]

Spinning one joint sweeps everything beyond it around that joint, and moves nothing before it. That single sentence is the whole Jacobian, for any number of joints, and it is why every point on the arm has one of its own — which is what lets the filter protect a link and not only the tip. With two joints J is square and det J = L₁L₂ sin q₂ vanishes when the arm is straight or folded, and the radial direction is then unreachable at any joint speed. With three or four the arm is redundant: J is wide, whole families of joint motions produce the same tip motion. The damped inverse below does not pick among them exactly: for λ > 0 it minimises ‖J u − v‖² + λ²‖u‖², trading tracking error against joint speed, and only tends to the minimum-norm solution as λ → 0.

2Where you want to go

v = (p* − p) · min( kp , vmax‖p* − p‖ ) then unom = JT ( J JT + λ²I )−1 v[2][3]

Head straight at the target, never faster than the speed cap. This controller has never heard of the obstacle and it is never replanned — the detours you are about to see are the filter’s doing, not a smarter plan.

The cap is applied to the Cartesian velocity before the inverse, so the unfiltered command is a straight line at constant speed until the end effector is within vmax/kp of the target, after which it decays proportionally — the reference the detour is read against. The realised path is close to that line but not exactly on it, because the damped inverse trades tracking accuracy for bounded joint speed. The inverse is damped least squares: J JT is 2×2 however many joints there are, and its determinant is at least λ⁴ > 0 for every pose, so there is no singular case to special-case. Writing if (det < ε) would put back exactly the discontinuity that damping exists to remove. λ is a length and scales with the arm (0.10 m here); it caps the joint-speed gain, so near full stretch the arm refuses the radial command and sweeps sideways instead of exploding. Anything genuinely time-optimal would need a double-integrator model and a higher-order CBF — a different lesson.

3What is forbidden

h(p) = √(ab) · [ ( |x′|an + |y′|bn )1/n − 1 ] with n = 2ε[4][5]
h > 0outside — safe
h = 0exactly on the boundary
h < 0inside — the rule is violated

One formula draws every forbidden region: ε = 1 is the ellipse you drag out yourself, and a small ε squares off the corners so the region hugs the rectangular obstacle. The obstacle and a region you drew are the same rule, one more h. The √(ab) in front turns the shape value into metres of clearance, so h is very nearly the gap you can see on screen.

∂h∂x = √(ab) · ( |x′| / aF )n−1 · sgn(x′) / a F is the bracket above

Taking the n-th root of the superquadric sum is a monotone rescale that fixes zero, so the zero level set, the safe set and the CBF property are all untouched — but the raw sum grows like distancen. At ε = 0.25 that is the eighth power, so an unrooted h would reach about 106 at the edge of the workspace and throttle the arm to a fraction of a sensible approach speed while it is still half a metre away. With the root, ‖∇h‖ stays bounded: it never exceeds √(a/b), and for an ellipse (ε = 1) it never falls below √(b/a). For smaller ε it dips a little further — 0.71 rather than 0.78 on the default obstacle. h is therefore proportional to the true clearance up to a bounded factor, and for a circle it is exactly the signed distance, which is what lets one α mean much the same thing for every shape. The absolute values cause no kink for ε < 2. ∇h fails to exist at exactly one point, the centre, where the rescaled norm has a conical cusp; the code returns an outward direction there rather than dividing by zero. There is no separate clearance term: the outline you see is the h = 0 curve.

The obstacle is a rectangle and stays one; ε shapes the region around it, which is always the superellipse that just contains the rectangle — at the corner (a, b) we need (a/A)n + (b/B)n = 1, so A = 21/n·a. At ε → 0 the region is the rectangle itself; at ε = 1 it is the ellipse circumscribing it.

On vocabulary: the set where h ≥ 0 is the safe set, and that name is standard. Its complement has no single canonical name — papers say unsafe set or avoid set, applications say obstacle, and aerospace work says keep-out zone. “Forbidden region” is the phrasing used here, and it is also the established term in the virtual-fixtures literature, where a forbidden-region virtual fixture[6] is exactly this: a software constraint that keeps a tool out of a volume.

4How h is allowed to change

ḣ = ∂h∂p ∂p∂q q̇ = ∇h(p)T J(q) u ≥ − α(h) with α(h) = α h[7][8]

The rule is not “never get closer than a metre”. It is: the closer you are, the slower you may approach. −α(h) is an approach budget that uses itself up — on the boundary h = 0, so the budget is zero, so ḣ ≥ 0, and you are guided along the boundary instead of through it. Because h is in metres, α reads off directly: at α = 2 you may close at 2 m/s for every metre of clearance, so at 10 cm you may close at 20 cm/s. α has units of 1/s.

The plot under the picture is this line. The curve is −α(h), the fastest the clearance is allowed to fall; the dot is the arm right now. Everything above the curve is permitted, and while the safety filter is on the dot cannot drop below it. Watch it slide down into the corner as the arm arrives: at h = 0 the only permitted rate is zero.

α(h) = α · sgn(h) · |h|p , and for p = 1 h(t) ≥ h(0) e−αt[9]

α·h is the simplest extended class-K function: through the origin, strictly increasing, and defined for h < 0 as well, which is what makes the inequality meaningful inside a region. With that choice the comparison lemma gives the bound above — forward invariance from h(0) ≥ 0, and exponential recovery from h(0) < 0. The general form is extended class-K for every p > 0, and the sign factor is what keeps it increasing through zero: α·hp alone would be positive on both sides for even p. p = 1 is the textbook straight line and p = 2 is the paper’s h²; larger p buys caution close to the boundary and freedom far from it, and turns the recovery bound from exponential into a power law. The slider starts at p = 1 because for p < 1 the function is no longer locally Lipschitz at the origin and the comparison lemma no longer applies; in this simulation p = 0.5 lets the Euler step overshoot the boundary by up to 1.7 mm.

Because the robot is velocity-commanded, u appears already in the first derivative of h, so wherever ∇hTJ ≠ 0 the constraint has relative degree 1 and a single inequality linear in u suffices. Where that row vanishes the arm has no authority over h at all, and the filter reports it rather than pretending otherwise. Command torque instead and u drops out of ḣ entirely, and a higher-order CBF[10] is needed.

The guarantee is continuous-time. We integrate with explicit Euler at Δt = 1/240 s, where αΔt ≤ 1 keeps the linearised update hk+1 ≥ (1 − αΔt)hk non-negative; at the largest α on the slider αΔt ≈ 0.08. That is not a discrete-time proof — the neglected second-order term is what could let a trajectory dip past the boundary — but over the parameter sweeps run for this page no violation occurred for p ≥ 1, though at the tightest setting the remaining margin was under a micrometre.

5The filter

u = arg min ‖u − unom‖² subject to ∇hT J u ≥ − α(h) for every guarded point[7]

If the command is already safe, the filter hands it back untouched — that is what it means when the ghost arrow is nowhere to be seen, sitting exactly under the solid one. Otherwise it makes the smallest change that obeys every rule at once.

Standard: guarding the end effector

The objective is strictly convex, so the solution is the unique Euclidean projection of unom onto the feasible polyhedron, and at the optimum some subset of the rows holds with equality. More rows than that can be tight, but the correction u − unom lies in the cone they generate, and in ℝn such a cone is generated by at most n of them, so subsets of size n suffice. Enumerating the subsets, solving the equality-constrained problem for each, and retaining the feasible candidate of least cost therefore returns the exact optimum, and requires no multiplier sign test. Most rows are eliminated before the enumeration begins: on the safe set u = 0 is feasible, so the optimum satisfies ‖u − unom‖ ≤ ‖unom‖, and any row whose slack exceeds ‖a‖·‖unom‖ cannot be active.

Feasibility is guaranteed on the safe set: if every h ≥ 0 then every right-hand side −α(h) ≤ 0, so u = 0 satisfies every row. Infeasibility therefore requires at least one h < 0, and the enumeration certifies it at no additional cost. The arm is then stopped and the condition reported. Stopping does not restore safety — with h < 0 the row demands ḣ > 0 and u = 0 delivers ḣ = 0 — but it fails visibly, whereas a slack variable would report success on a constraint it had just relaxed.

Link guarding: the closest point of each link

pk(s) = (1 − s) jk−1 + s jk , and s*k = arg mins∈[0,1] h( pk(s) ) ak = J(q, k, s*k)T ∇h( pk(s*k) ) , and bk = − α(h)[11]

Instead of a single row for the end effector, one row per link, written at that link’s closest point to the region. h is convex along a straight line, so a ternary search locates the minimiser to about 10−5 of the link length in 28 iterations. Where that minimiser is unique, Danskin’s theorem[12] gives the derivative of the minimum as the derivative at the minimiser, so the row may be evaluated at the frozen parameter s*k; a region with a nearly flat face can make it non-unique, and there the minimum is only directionally differentiable and the row takes one element of the subdifferential. This is both tighter and cheaper than sampling points along the link. With three or four joints and the option disabled, a forearm passes through the region while the end effector goes around it.

Self-collision guarding: the manipulator against itself

dij = mins,t ‖ pi(s) − pj(t) ‖ , and n̂ = pj(t*) − pi(s*)dij ḋij = n̂T ( Jj(t*) − Ji(s*) ) u ≥ − α( dij − dmin )[11]

The same construction with the manipulator as both bodies: h is the clearance between two non-adjacent links — their distance less the margin dmin, as the second formula shows — s* and t* are the parameters of their closest points, and the row is the difference of the two link Jacobians projected onto the line joining those points. Adjacent links share a joint, so their distance is identically zero and no such constraint can be imposed; the option therefore has no effect below three joints.

What the filter does not promise

The objective is minimal in joint space, not in task space: the task-space correction direction is J JT∇h rather than ∇h, so the end effector also decelerates as it slides along a boundary rather than only changing direction. This is a property of the formulation, not an artefact. Safety is likewise not liveness — the arm may stall with the target behind a region, and nothing in the construction precludes it. A safety filter certifies constraint satisfaction; reaching the goal remains the planner’s task.

WHAT is forbidden lives in h. HOW CAUTIOUSLY you approach lives in α. Draw a new shape and you have changed h. Move one slider and you have changed α. Nothing else in the controller needs to know.

Sources

  1. B. Siciliano, L. Sciavicco, L. Villani, G. Oriolo. “Robotics: Modelling, Planning and Control.” Springer, Advanced Textbooks in Control and Signal Processing, 2009. doi:10.1007/978-1-84628-642-1. — forward kinematics and the geometric Jacobian.
  2. C. W. Wampler. “Manipulator inverse kinematic solutions based on vector formulations and damped least-squares methods.” IEEE Trans. Systems, Man, and Cybernetics 16(1), 1986. doi:10.1109/TSMC.1986.289285. — the damped inverse that keeps the joint step bounded near a singularity.
  3. Y. Nakamura, H. Hanafusa. “Inverse kinematic solutions with singularity robustness for robot manipulator control.” ASME J. Dynamic Systems, Measurement, and Control 108(3), 1986. doi:10.1115/1.3143764. — the same damped inverse, derived independently in the same year.
  4. A. H. Barr. “Superquadrics and angle-preserving transformations.” IEEE Computer Graphics and Applications 1(1), 1981. doi:10.1109/MCG.1981.1673799. — the superquadric and its 2D case, the superellipse — the shape family the barrier is built from.
  5. L. Brunke, Y. Zhang, R. Römer, J. Naimer, N. Staykov, S. Zhou, A. P. Schoellig. “Semantically safe robot manipulation: from semantic scene understanding to motion safeguards.” IEEE Robotics and Automation Letters 10(5), 2025. doi:10.1109/LRA.2025.3553046. — superquadrics used as control barrier functions, and α as the dial for how cautiously to approach. Preprint: arXiv:2410.15185.
  6. J. J. Abbott, P. Marayong, A. M. Okamura. “Haptic virtual fixtures for robot-assisted manipulation.” Robotics Research (ISRR 2005), Springer Tracts in Advanced Robotics 28, 2007. doi:10.1007/978-3-540-48113-3_5. — the forbidden-region / guidance distinction, and the name used on this page.
  7. A. D. Ames, X. Xu, J. W. Grizzle, P. Tabuada. “Control barrier function based quadratic programs for safety critical systems.” IEEE Trans. Automatic Control 62(8), 2017. doi:10.1109/TAC.2016.2638961. — the condition ḣ ≥ −α(h), and the minimum-norm quadratic program that enforces it.
  8. A. D. Ames, S. Coogan, M. Egerstedt, G. Notomista, K. Sreenath, P. Tabuada. “Control barrier functions: theory and applications.” European Control Conference (ECC), 2019. doi:10.23919/ECC.2019.8796030. — the survey; extended class-K functions and forward invariance.
  9. H. K. Khalil. “Nonlinear Systems.” 3rd ed., Prentice Hall, Upper Saddle River, NJ, 2002. — the comparison lemma (Lemma 3.4), which turns the pointwise inequality into h(t) ≥ h(0)e−αt. ISBN 0-13-067389-7; this book has no DOI.
  10. Q. Nguyen, K. Sreenath. “Exponential control barrier functions for enforcing high relative-degree safety-critical constraints.” American Control Conference (ACC), 2016. doi:10.1109/ACC.2016.7524935. — what is needed when the input does not appear in the first derivative of h.
  11. B. Faverjon, P. Tournassoud. “A local based approach for path planning of manipulators with a high number of degrees of freedom.” IEEE Int. Conf. Robotics and Automation (ICRA), 1987. doi:10.1109/ROBOT.1987.1087982. — a distance constraint linear in the joint velocity, one per body pair — the ancestor of the per-link rows here, and of self-collision, which is the same constraint with the manipulator as both bodies.
  12. J. M. Danskin. “The theory of max-min, with applications.” SIAM J. Applied Mathematics 14(4), 1966. doi:10.1137/0114053. — differentiating a minimum at its minimiser, which licenses writing the row at the closest point.