Two robots sharing a workspace

Robot A backs away from the 200 ms reachable space of robot B (red)

Two Franka Emika Panda robots work in the same space. Robot A holds its end-effector at a point, with its z axis pointing down. Robot B is moved by you with three sliders that set the target of its end-effector. Robot A must never put its end-effector where robot B’s end-effector could be within the next 200 ms.

At every control step:

  1. the reachable space of B’s end-effector within 200 ms (red) is computed with the nonlinear ray shooting method, pycapacity.robot.reachable_space_nonlinear(), from B’s forward kinematics and its joint position and velocity limits, and then its half-space representation \(Hx \leq d\);

  2. robot A’s joint velocities \(\dot{q}\) come from a QP that holds A’s point and keeps A’s end-effector outside B’s reachable space by a margin of 5 cm:

\[\min_{\dot{q}, s} ~\|J\dot{q} - v\|^2 + \|J_o\dot{q} - \omega\|^2 + w s^2 \quad \text{s.t.} \quad h_k^T(x + J\dot{q}\,\Delta t) \geq b_k + \text{margin} - s, \quad \text{joint limits}, \quad s \geq 0\]

where \(v = k_p(x_{ref} - x)\), the second term turns the end-effector’s z axis down, and \(h_k^T x \leq b_k\) is one row of \(Hx \leq d\), normalised.

“Outside a convex set” is not a convex constraint, but being on the outer side of one of its faces is enough to be outside. Each step, among the faces A is outside of, the QP uses the one whose outer side contains A’s point the most. This keeps the problem a small QP (8 variables, 1 inequality), at the price of being conservative. Only the end-effector points are considered, not the whole arms.

python examples/control/reachable_space_avoidance.py              # move robot B with sliders
python examples/control/reachable_space_avoidance.py --headless   # B reaches towards A and back; A must never be inside its reach

See the script on Github.

The same idea in a few lines, with random Jacobians and the reachable space of B approximated as \(x_B + T\,\mathcal{V}\) (velocity polytope \(\mathcal{V}\), horizon \(T\)), examples/control/minimal/avoid_reachable_space.py:

# Minimal: robot A moves towards a target but stays out of the space robot B can reach within 0.2 s
import numpy as np
from qpsolvers import solve_qp
from pycapacity.robot import velocity_polytope

np.random.seed(0)
dt, horizon, margin = 0.02, 0.2, 0.05

# robot B: everything its end-effector can reach within the horizon,  x_b + horizon * V,  as H x <= d
J_b, x_b, dq_max_b = np.random.randn(3, 6), np.array([1.0, 0.0, 0.5]), np.ones(6)
V = velocity_polytope(J_b, dq_max_b, -dq_max_b)
V.find_halfplanes()
n = np.linalg.norm(V.H, axis=1)
H, d = V.H / n[:, None], (horizon * V.d.ravel() + V.H @ x_b) / n     # normalised rows

# robot A: end-effector x_a, Jacobian J_a, wants to go to x_target
J_a, x_a, x_target, dq_max_a = np.random.randn(3, 7), np.array([0.3, 0.0, 0.5]), np.array([1.0, 0.0, 0.5]), np.ones(7)

# being outside one face is enough to be outside the polytope: take the face A is the most outside of
k = np.argmax(H @ x_a - d)
# QP in dq:  min ||J_a dq - v||^2   s.t.   h_k (x_a + J_a dq dt) >= d_k + margin,   |dq| <= dq_max
v = 5 * (x_target - x_a)
dq = solve_qp(J_a.T @ J_a + 1e-6 * np.eye(7), -J_a.T @ v,
              -dt * H[k:k+1] @ J_a, np.array([H[k] @ x_a - d[k] - margin]),
              lb=-dq_max_a, ub=dq_max_a, solver="proxqp")
print("next position", (x_a + J_a @ dq * dt).round(3), "outside B's reach:", np.any(H @ (x_a + J_a @ dq * dt) > d))