Two robots carrying a box
Two Pandas facing each other hold a box between their end-effectors. The heaviest box they can carry is a linear program on their force polytopes, and the load sharing for a given box is a QP:
\[\max_{f_1, f_2, m} ~m
\quad \text{s.t.} \quad
f_1 + f_2 = m g, \quad H_1 f_1 \leq d_1, \quad H_2 f_2 \leq d_2\]
\[\min_{f_1, f_2} ~\|f_1 - f_2\|^2
\quad \text{s.t.} \quad
f_1 + f_2 = m (g + a), \quad H_1 f_1 \leq d_1, \quad H_2 f_2 \leq d_2\]
Light boxes are shared equally; close to the heaviest box (26.8 kg here), the robot that is closer to the box carries more.
python examples/control/two_robots_carrying.py
Minimal version, with two random arms, examples/control/minimal/two_robots_box.py:
# Minimal: two robots carry a box: heaviest box (LP) and load sharing (QP)
import numpy as np
from qpsolvers import solve_qp
from scipy.optimize import linprog
from pycapacity.robot import force_polytope
np.random.seed(0)
P1 = force_polytope(np.random.randn(3, 7), np.full(7, 50.0), -np.full(7, 50.0))
P2 = force_polytope(np.random.randn(3, 7), np.full(7, 50.0), -np.full(7, 50.0))
P1.find_halfplanes()
P2.find_halfplanes()
g = np.array([0, 0, 9.81])
G = np.block([[P1.H, np.zeros((len(P1.H), 3))], [np.zeros((len(P2.H), 3)), P2.H]])
h = np.r_[P1.d.ravel(), P2.d.ravel()]
# heaviest box, LP in (f_1, f_2, m): max m s.t. f_1 + f_2 = m g, H_1 f_1 <= d_1, H_2 f_2 <= d_2
m_max = linprog(np.r_[np.zeros(6), -1], np.c_[G, np.zeros(len(G))], h,
np.c_[np.eye(3), np.eye(3), -g], np.zeros(3), bounds=[(None, None)] * 7).x[6]
print("heaviest box: %.1f kg" % m_max)
# load sharing, QP in (f_1, f_2): min ||f_1 - f_2||^2 s.t. f_1 + f_2 = m g, H_1 f_1 <= d_1, H_2 f_2 <= d_2
P = np.block([[np.eye(3), -np.eye(3)], [-np.eye(3), np.eye(3)]]) + 1e-6 * np.eye(6)
f = solve_qp(P, np.zeros(6), G, h, np.hstack([np.eye(3), np.eye(3)]), 0.8 * m_max * g, solver="proxqp")
print("box of %.1f kg: robot 1" % (0.8 * m_max), f[:3].round(1), "N, robot 2", f[3:].round(1), "N")