Time-optimal motion along a path

Robot moving along a line with its velocity polytope and velocity, speed and torque profiles

A Panda moves its end-effector along a straight line as fast as possible. With \(b = \dot{s}^2\), the end-effector acceleration on a straight line is \(\ddot{x} = x'(s) \, b'(s)/2\), so the acceleration polytope \(H_i \ddot{x} \leq d_i\) at each point of the path (pycapacity.robot.acceleration_polytope()) gives linear constraints on \(b\), and the fastest motion is a linear program:

\[\max_{b} ~\sum_i b_i \quad \text{s.t.} \quad H_i x' \frac{b_{i+1} - b_i}{2 \Delta s} \leq d_i, \quad 0 \leq b_i \leq b_{max,i}, \quad b_0 = b_N = 0\]

where \(b_{max,i}\) comes from the velocity polytope \(H_{v,i}\, x'\dot{s} \leq d_{v,i}\) (pycapacity.robot.velocity_polytope(), joint velocity limits). Both polytopes use the redundancy of the 7 joints freely. The acceleration polytope neglects the velocity-dependent terms (Coriolis, \(\dot{J}\dot{q}\)); the script checks the resulting motion with them. The animation shows the robot along the path with its velocity polytope and its end-effector velocity, which touches the polytope wherever the joint velocity limits are active.

python examples/control/time_optimal_path.py

Minimal version, with one random posture for the whole path, examples/control/minimal/time_optimal.py:

# Minimal: fastest motion along a straight line with the acceleration and velocity polytopes (LP in b = sd^2)
import numpy as np
from scipy.optimize import linprog
from pycapacity.robot import acceleration_polytope, velocity_polytope

np.random.seed(0)
# one robot posture for the whole path, to keep it short (in the example: one per point of the path)
J = np.random.randn(3, 7)
M = np.eye(7) + 0.1 * np.ones((7, 7))                  # mass matrix
t_max, dq_max = np.full(7, 10.0), np.ones(7)
A = acceleration_polytope(J, M, t_max, -t_max)          # H xdd <= d
V = velocity_polytope(J, dq_max, -dq_max)
V.find_halfplanes()                                     # Hv xd <= dv

dx = np.array([0.0, 0.5, 0.3])                          # path x(s) = x0 + s dx, s in [0, 1]
N = 50
ds = 1 / N
# on the path  xdd = dx sdd = dx (b_{i+1} - b_i) / (2 ds),   xd = dx sd
A_ub, b_ub = [], []
for i in range(N):
    for h, d in zip(A.H, A.d.ravel()):
        row = np.zeros(N + 1)
        row[i], row[i + 1] = -h @ dx / (2 * ds), h @ dx / (2 * ds)
        A_ub.append(row)
        b_ub.append(d)
up = V.H @ dx > 0
b_max = np.min(V.d.ravel()[up] / (V.H @ dx)[up]) ** 2   # velocity polytope:  sd <= dv / (Hv dx)
bounds = [(0, 0)] + [(0, b_max)] * (N - 1) + [(0, 0)]  # start and stop at rest
b = linprog(-np.ones(N + 1), np.array(A_ub), np.array(b_ub), bounds=bounds).x

sd = np.sqrt(np.maximum(b, 0))
print("motion time: %.3f s" % np.sum(2 * ds / (sd[1:] + sd[:-1])))