Algorithmresearch
Interconnection and damping assignment
Also called IDA-PBC.
A passivity-based method that solves matching equations to give the closed loop a chosen port-Hamiltonian form with a minimum at the target.
- Time
- O(n^2 m + m^3) worst
- Space
- O(n m + m^2) extra
- Where
- m = the number of inputs; n = the dimension of the state
- Model
- Real RAM
- Properties
- deterministicexactonlineiterative
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Romeo Ortega, Arjan van der Schaft, Bernhard Maschke, Gerardo Escobar, 2002
Interconnection and damping assignment (IDA-PBC) is an algorithm of passivity-based control for plants written as a port-Hamiltonian system . The designer does not choose the closed-loop energy directly. Instead, the designer chooses how energy should flow and be lost in the closed loop, the matrices and , and then solves the matching equations, a set of partial differential equations, for an energy that has its minimum at the target. The control is the solution of a linear equation at each point. The closed loop is again port-Hamiltonian, its energy can only decrease, and the LaSalle invariance principle gives convergence. It handles systems with fewer actuators than states, such as electromechanical systems, where the energy cannot be changed in every direction.
In plain words
A machine has an energy, and the energy flows between its parts and is lost in friction and resistance. You want the machine to rest at a new point. You cannot simply say what the new energy should be, because with few motors you cannot push in every direction. So you first decide how you would like the parts to pass energy to each other, and where you would like it to be lost. Then you look for an energy that fits this plan, using only the pushes your motors can make, and that has its lowest point where you want the machine to rest. If you find one, the controller makes the machine behave like a new machine with that energy, and the new machine slides down to the lowest point.
The problem
Input. A plant with , , and of full column rank . A target point . A choice of and , and an energy that solves the matching PDE
where is a full rank left annihilator of , with and .
Output. The state feedback such that the closed loop is , or a report that the matching equation fails at .
The hard part, solving the PDE, is a design step done once, by hand or with a computer algebra system. The algorithm below is what runs in the controller.
The algorithm
IDA-PBC-CONTROL(J - R, ∇H, g, J_d - R_d, ∇H_d, tol)- 1
a ← (J - R) ∇H - 2
c ← (J_d - R_d) ∇H_d - 3
w ← c - a - 4
u ← (gᵀ g)⁻¹ gᵀ w - 5
ρ ← w - g u - 6
if some |ρ_i| > tol then fail: the matching equation has no solution at x - 7
return u
All quantities are evaluated at the current state . Lines L1 and L2 compute the plant and the target vector fields without input. Line L3 is what the input must supply. Line L4 is the least squares solution of , which is the exact solution when one exists. Lines L5 and L6 check the part of that the input cannot reach; it is zero exactly when solves the matching PDE at . With exact data use .
Example
Magnetic levitation. A ball hangs under an electromagnet. The state is the flux , the height of the ball (up is positive, the coil is at ) and the momentum . The energy is , the coil has resistance , and the input is the voltage, so has rows , , and . The magnetic force pulls the ball up; at rest it balances gravity, so .
The plant has no input on and , and no term that couples to directly: the current changes the force only through . Choose with rows , , : the new term couples flux and momentum. The matching PDE has two rows, and its solutions are
for any function . Choosing with puts the minimum at , and the first row gives
Take , , (so and ), and , , . Start at rest with the flux of the target but the ball too low, , where . The simulation uses 4th order Runge-Kutta with step , and the feedback is evaluated inside the right side.
| 0 | 2 | 0.3 | 0 | 0.02 | 1.6 |
| 0.5 | 2.04738 | 0.30602 | 0.03189 | 0.01614 | 1.43149 |
| 1 | 2.03087 | 0.33331 | 0.07436 | 0.01468 | 1.29427 |
| 2 | 1.97975 | 0.41852 | 0.07840 | 0.007474 | 1.12631 |
| 4 | 1.99471 | 0.48943 | 0.00642 | 0.0001219 | 1.02937 |
| 10 | 1.99998 | 0.49982 | 0.00011 | 2.427e-8 | 1.00035 |
never increases (measured), and holds within (measured). The ball rises to without overshoot, and the distance to stays below from on. Theorem 6 of the proof shows that every motion that starts in the set with converges to .
Correctness
The full proof is in proofs/correctness.md. Its main steps:
- Theorem (matching). has a solution if and only if at line L5, because is the orthogonal projection onto the range of . The solution is unique and is the of line L4. Then the closed loop equals the target system.
- Theorem (energy decrease). Since is skew, . With a strict minimum of at , this gives Lyapunov stability by the Lyapunov direct method.
- Theorem (convergence). On a compact positively invariant set where the only solution with is , every motion converges to (LaSalle; Ortega et al. 2002, Proposition 1).
- The example. The proof solves the matching PDE by characteristics, shows the Hessian of has determinant and is positive definite for , builds the compact invariant set from convexity, and checks the LaSalle condition: forces , so and then . The tests check the matching, the energy identity and the LaSalle identity exactly in Fraction.
Proof: The IDA-PBC control solves the matching equation exactly when the residual is zero, and the target port-Hamiltonian system makes the minimum of the assigned energy asymptotically stablefull
The plant is with , and of full column rank . The target is with and . Lines L1 to L7 compute, at one point ,
and return if . Here is the Euclidean norm.
Theorem 1: the matching step
At a point , the matching equation has a solution if and only if , and then the solution is unique and equals the of line L4. If solves it at every of an open set, the closed loop equals the target system on that set.
Proof. is invertible because has full column rank. Let . Then , , and , so is the orthogonal projection onto the range of , and . If for some , then is in the range of , so , and gives . If , then . For the last claim, substitute into the plant: .
Let be a full rank left annihilator of , so . Then is the same as
For fixed and this is a system of partial differential equations in , the matching PDE (Ortega, van der Schaft, Maschke and Escobar 2002, Section 3.2).
Theorem 2: the target system
Let the closed loop be the target system, with of class and , . Then
(a) along the motion;
(b) is a stable equilibrium in the sense of Lyapunov;
(c) if is a compact set that is positively invariant, and the only solution in along which is , then every motion that starts in converges to , and is asymptotically stable.
Proof. (a) , and for every because is skew. (b) is positive definite near by the second-order condition, and its derivative is nonpositive by (a); this is a Lyapunov function, and the Lyapunov direct method gives stability. (c) This is the LaSalle invariance principle applied with the function on (Khalil 2002, Section 4.2): the motion converges to the largest invariant set in , which is by assumption.
This is the content of Proposition 1 of Ortega et al. (2002), stated here for the target system.
The magnetic levitation example
The state is : the flux of the coil, the position of the ball, and its momentum. With constants ,
So , , . For a target , the equilibrium needs and .
Solving the matching PDE. Take with rows , , , for constants and . The annihilator is , and the matching PDE has two rows:
The first gives . In the second, the function is a particular solution, and holds for every , because . Choose with and :
The first row of the matching equation then gives the control, by Theorem 1:
The tests check, exactly in Fraction at 150 random points, that lines L1 to L7 return this and that the closed loop equals the target system, and that a with the wrong makes the residual nonzero.
Lemma 3: the minimum. at , and for the Hessian of is positive definite. If , then for it is positive semidefinite.
Proof. and , both at since . The Hessian is block diagonal with the block for and
With and , the diagonal entry is positive and the determinant is positive for and at .
Lemma 4: a compact invariant set. Let , and . For , the set is compact, lies in , and is positively invariant for the closed loop.
Proof. Let , a convex set. By Lemma 3, is convex on , so , where the gradient is , is a minimum of on . It is the only one: if were another, would be constant on the segment from to , which lies in , against the positive definite Hessian at . Let be the sphere of radius around , and (a minimum of a continuous positive function on a compact set). For with , the point is in , and convexity gives , so . Hence lies in the ball of radius , and it is closed, so it is compact.
On , , while , using . So on , and does not meet it. A motion that starts in has nonincreasing (Theorem 2(a)) while it exists; it cannot reach , where , without first leaving , which it cannot do. So it stays in the compact set , and therefore exists for all .
Lemma 5: the LaSalle condition. Let . The only solution in with is .
Proof. Suppose along a solution. Then and , and
Since in , . Then gives . So along the solution, and , the only critical point of in (Lemma 4).
Theorem 6. For the magnetic levitation plant with and the control above, is asymptotically stable, and every motion that starts in with converges to .
Proof. Theorem 2 with Lemmas 3, 4 and 5.
For the page example, , , , , , , : , and the initial state has , so it is in and Theorem 6 applies. The tests check Lemma 3 and the identity of Lemma 5 exactly, and measure along the RK4 solution and the balance within .
The model of the plant is valid only for , where the inductance is positive. Theorem 6 is a statement about the model; in the example the position stays in .
Complexity
Count real operations at unit cost, as in the real RAM. Lines L1 and L2 cost each. Forming costs , costs , and solving the system costs . Line L5 costs . The total per evaluation is , which is within , plus the cost of and . The extra space is . If is constant, can be computed once. The design step, solving the matching PDE, has no general bound: it may have no useful solution.
Properties
- Structure kept. The closed loop is port-Hamiltonian with energy , so it is passive from a new input to the output , and further passive loops can be added.
- Energy as Lyapunov function. is a Lyapunov function by construction; no separate search is needed.
- Underactuation handled. The matching PDE has rows. With full actuation () it is empty, and any works.
- Not unique. Different choices of , and of the free function give different controllers. The free function sets the shape of the energy and so the region of attraction.
- Local or global. The guaranteed region is a compact sublevel set of . In the example it is local, because has the cubic term , but large: any below .
Variants and improvements
- Fixing and first (non-parameterized). The usual approach, as in the example: choose the matrices, then solve the PDE.
- Fixing first (algebraic). Choose , and solve the matching equation for and , which is then algebraic.
- Mechanical systems. For underactuated mechanical systems, has a kinetic and a potential part, and the matching PDE splits into one for the inertia matrix and one for the potential energy. This covers the cart-pole, the ball and beam, and similar systems.
- Adding integral action or adaptation. Add states to the controller to reject constant disturbances or estimate parameters, keeping the port-Hamiltonian form.
- Damping injection only. If already has its minimum at , take , and only increase : this is the damping injection of the port-Hamiltonian system page.
When to use it
Use it for physical systems that have a clear energy, such as electromechanical systems, power converters, motors and mechanical systems, especially when they are underactuated, so that simple energy shaping does not apply. It is useful when you want a controller that keeps the physical meaning and gives a Lyapunov function for free. If the matching PDE has no solution you can find, or the plant has no natural energy, use backstepping or feedback linearization instead. For a fully actuated robot arm, PD control with gravity compensation is the simple special case.
Pitfalls
- The PDE is the real work. Line L6 only checks the matching at one point. If does not solve the PDE everywhere, the controller fails at some states, or the closed loop is not the target.
- No minimum at the target. A solution of the PDE is useless unless the free function can place a strict minimum at . Check the Hessian.
- A non-constant or must keep the signs. must be skew and positive semidefinite at every , or fails.
- The LaSalle condition. is usually only positive semidefinite, so on a set larger than . Check that no other solution stays there, as in the example.
- Model validity. The levitation model needs . The region from the theory is a statement about the model, and it may include states the real system cannot reach.
- Numerical residual. With floating point data, set a small at line L6; with , rounding makes the check fail.
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
# Shared helper of the control pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Fixed step simulation for the control pages.
Conventions:
- A continuous-time system is a function f(t, x, u) that returns x' as a
flat list. x is a flat list. u is whatever the control returns (a flat
list, a scalar, or None when there is no control).
- A discrete-time system is a function F(k, x, u) that returns x_(k+1).
- The integrator is the classical 4th order Runge-Kutta method with a fixed
step dt. The input is held constant over each step.
- Time t_k = t0 + k dt is computed by multiplication, not by summation.
- The number of steps round((t1 - t0) / dt) and the hold ratio
round(hold / dt) must match the real ratios within 1e-9 (relative), or
ValueError is raised.
This file holds no controller or observer of a control page.
"""
__all__ = ["rk4_step", "simulate", "simulate_discrete", "lti"]
def _axpy(a, x, y):
return [yi + a * xi for xi, yi in zip(x, y)]
def rk4_step(f, t, x, u, dt):
"""Return x(t + dt) after one RK4 step of x' = f(t, x, u), u held constant."""
k1 = f(t, x, u)
k2 = f(t + dt / 2, _axpy(dt / 2, k1, x), u)
k3 = f(t + dt / 2, _axpy(dt / 2, k2, x), u)
k4 = f(t + dt, _axpy(dt, k3, x), u)
return [xi + dt / 6 * (a + 2 * b + 2 * c + d) for xi, a, b, c, d in zip(x, k1, k2, k3, k4)]
def _ratio(num, den, what):
r = round(num / den)
if abs(r * den - num) > 1e-9 * max(abs(num), abs(den)):
raise ValueError(what + " is not an integer multiple of dt")
return r
def simulate(f, x0, t0, t1, dt, control=None, hold=None):
"""Simulate x' = f(t, x, u) from x(t0) = x0 to t1 with RK4 and step dt.
control(t, x) gives the input. It is called at each sampling instant
t0 + j hold, and its value is held (zero-order hold) until the next
instant. hold must be an integer multiple of dt; hold = None means
hold = dt. With control = None the input is None.
Returns (ts, xs, us): ts has N + 1 times, xs the N + 1 states, and us the
N inputs, where us[k] acts on [ts[k], ts[k + 1]].
"""
if dt <= 0:
raise ValueError("dt must be positive")
n_steps = _ratio(t1 - t0, dt, "t1 - t0")
if n_steps < 0:
raise ValueError("t1 is before t0")
r = 1 if hold is None else _ratio(hold, dt, "hold")
if r < 1:
raise ValueError("hold must be at least dt")
x = list(x0)
ts = [t0]
xs = [list(x)]
us = []
u = None
for k in range(n_steps):
t = t0 + k * dt
if control is not None and k % r == 0:
u = control(t, list(x))
x = rk4_step(f, t, x, u, dt)
ts.append(t0 + (k + 1) * dt)
xs.append(x)
us.append(u)
return ts, xs, us
def simulate_discrete(F, x0, N, control=None):
"""Run x_(k+1) = F(k, x_k, u_k) for k = 0, ..., N - 1.
u_k = control(k, x_k), or None if control is None. Returns (xs, us) with
N + 1 states and N inputs. Exact if F and control are exact.
"""
x = list(x0)
xs = [list(x)]
us = []
for k in range(N):
u = control(k, list(x)) if control is not None else None
x = list(F(k, x, u))
xs.append(x)
us.append(u)
return xs, us
def lti(A, B=None):
"""Return f(t, x, u) = A x + B u for the system x' = A x + B u.
u may be a flat list, a scalar (one input) or None (zero input). B may
be None for a system with no input.
"""
def f(t, x, u):
dx = [sum(a * xi for a, xi in zip(row, x)) for row in A]
if B is None or u is None:
return dx
uu = u if isinstance(u, (list, tuple)) else [u]
return [d + sum(b * ui for b, ui in zip(row, uu)) for d, row in zip(dx, B)]
return f
def _self_test():
import math
f = lti([[-1.0]])
_, xs, _ = simulate(f, [1.0], 0.0, 1.0, 0.01)
assert abs(xs[-1][0] - math.exp(-1.0)) < 1e-9
return True
if __name__ == "__main__":
_self_test()
ida_pbc.py 83 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ida-pbc/. The authors are listed in prov/ST8SKY.jsonl.
"""Interconnection and damping assignment (IDA-PBC): the control at one point.
The plant is the port-Hamiltonian system
x' = (J(x) - R(x)) grad H(x) + g(x) u,
and the design is a target system
x' = (J_d(x) - R_d(x)) grad H_d(x),
with J_d = -J_d^T, R_d = R_d^T >= 0 and H_d with a strict minimum at the
target point. The target is reachable by u at x if and only if the matching
equation
g(x) u = (J_d - R_d) grad H_d - (J - R) grad H
has a solution; when g has full column rank, the solution is
u = (g^T g)^(-1) g^T w with w the right side, and it solves the equation
exactly when the residual w - g u is zero.
matching_control evaluates this at one point. With int or Fraction inputs
and tol = 0 the result is exact; with floats, pass a small tol.
"""
from fractions import Fraction
__all__ = ["matching_control", "MatchingError"]
class MatchingError(ValueError):
"""The matching equation has no solution at this point."""
def _matvec(A, v):
return [sum(a * b for a, b in zip(row, v)) for row in A]
def _div(a, b):
if isinstance(a, int) and isinstance(b, int):
return Fraction(a, b)
return a / b
def _solve(M, v):
# Gauss-Jordan elimination with row pivoting on a small square system.
n = len(M)
A = [list(M[i]) + [v[i]] for i in range(n)]
for c in range(n):
p = max(range(c, n), key=lambda i: abs(A[i][c]))
if A[p][c] == 0:
raise ValueError("g must have full column rank")
A[c], A[p] = A[p], A[c]
for i in range(n):
if i != c and A[i][c] != 0:
f = _div(A[i][c], A[c][c])
A[i] = [a - f * b for a, b in zip(A[i], A[c])]
return [_div(A[i][n], A[i][i]) for i in range(n)]
def matching_control(jr, grad_h, g, jrd, grad_hd, tol=0):
"""Return u with g u = (J_d - R_d) grad H_d - (J - R) grad H.
jr = J - R and jrd = J_d - R_d are n x n, g is n x m (a list of n rows),
grad_h and grad_hd are vectors of length n, all evaluated at the same x.
Raises MatchingError if the residual exceeds tol in some component.
"""
n = len(grad_h)
if len(g) != n or len(jr) != n or len(jrd) != n or len(grad_hd) != n:
raise ValueError("dimensions do not match")
m = len(g[0])
a = _matvec(jr, grad_h) # @line L1
c = _matvec(jrd, grad_hd) # @line L2
w = [ci - ai for ci, ai in zip(c, a)] # @line L3
gtg = [[sum(g[k][i] * g[k][j] for k in range(n)) for j in range(m)] for i in range(m)]
gtw = [sum(g[k][i] * w[k] for k in range(n)) for i in range(m)]
u = _solve(gtg, gtw) # @line L4
rho = [wi - gi for wi, gi in zip(w, _matvec(g, u))] # @line L5
if any(abs(r) > tol for r in rho): # @line L6
raise MatchingError("the matching equation has no solution at this point")
return u # @line L7
test_ida_pbc.py 166 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/ida-pbc/. The authors are listed in prov/ST8SKY.jsonl.
import math
import random
from fractions import Fraction
import ctlsim
from ida_pbc import MatchingError, matching_control
# Magnetic levitation, x = (lambda, theta, p): flux, position, momentum, with
# k = m = 1, g0 = 2, r = 1, target theta* = 1/2, lambda* = 2. Design alpha = 2,
# b = 1, r_d = 2. Exact checks use Fraction. The simulation uses classical RK4
# (ctlsim) with step DT = 0.01, with the feedback evaluated inside the right
# side. Tolerances are stated at each check.
K, M, G0, RES = Fraction(1), Fraction(1), Fraction(2), Fraction(1)
ALPHA, BW, RD = Fraction(2), Fraction(1), Fraction(2)
LAM_S, TH_S = Fraction(2), Fraction(1, 2)
ZS = TH_S + Fraction(LAM_S, ALPHA)
DT = 0.01
def steps(T, dt):
n = round(T / dt)
assert abs(n * dt - T) < 1e-12
return n
def grad_h(x):
lam, th, p = x
# H = (1 - theta) lambda^2 / (2k) + p^2 / (2m) + m g0 theta
return [(1 - th) * lam / K, -lam * lam / (2 * K) + M * G0, p / M]
JR = [[-RES, 0, 0], [0, 0, 1], [0, -1, 0]]
G = [[1], [0], [0]]
def jrd(alpha=ALPHA):
return [[-RD, 0, -alpha], [0, 0, 1], [alpha, -1, 0]]
def h_d(x):
lam, th, p = x
return p * p / (2 * M) + lam ** 3 / (6 * K * ALPHA) - M * G0 * lam / ALPHA + BW * (th + lam / ALPHA - ZS) ** 2 / 2
def grad_hd(x):
lam, th, p = x
s = th + lam / ALPHA - ZS
return [lam * lam / (2 * K * ALPHA) - M * G0 / ALPHA + BW * s / ALPHA, BW * s, p / M]
def control(x):
# closed form of the matching solution: u = r (1 - theta) lambda / k - alpha p / m - r_d H_d,lambda
lam, th, p = x
return RES * (1 - th) * lam / K - ALPHA * p / M - RD * grad_hd(x)[0]
def plant(x, u):
a = [sum(r * v for r, v in zip(row, grad_h(x))) for row in JR]
return [a[0] + u, a[1], a[2]]
def rand_point(rng):
return [Fraction(rng.randint(1, 60), rng.randint(1, 20)), Fraction(rng.randint(-20, 19), 20), Fraction(rng.randint(-30, 30), rng.randint(1, 9))]
def test_matching_exact():
rng = random.Random(1)
for _ in range(150):
x = rand_point(rng)
u = matching_control(JR, grad_h(x), G, jrd(), grad_hd(x))
assert u == [control(x)]
target = [sum(r * v for r, v in zip(row, grad_hd(x))) for row in jrd()]
assert plant(x, u[0]) == target
def test_energy_decay_exact():
# dH_d/dt = grad H_d^T (J_d - R_d) grad H_d = -r_d (H_d,lambda)^2
rng = random.Random(2)
for _ in range(150):
x = rand_point(rng)
gd = grad_hd(x)
xdot = plant(x, control(x))
assert sum(a * b for a, b in zip(gd, xdot)) == -RD * gd[0] ** 2
def test_target_is_strict_minimum_exact():
xs = [LAM_S, TH_S, 0]
assert grad_hd(xs) == [0, 0, 0] and control(xs) == 1 and plant(xs, 1) == [0, 0, 0]
# potential part V(lambda, theta): Hessian [[lam/(k a) + b/a^2, b/a], [b/a, b]], det = b lam / (k a) > 0
rng = random.Random(4)
for _ in range(50):
lam = Fraction(rng.randint(1, 100), rng.randint(1, 10))
hll, hlt, htt = lam / (K * ALPHA) + Fraction(BW, ALPHA ** 2), Fraction(BW, ALPHA), BW
assert htt > 0 and hll * htt - hlt * hlt == BW * lam / (K * ALPHA)
# margin to the boundary lambda = 0: V(0, theta) >= 0 and V* = -2 m g0 lambda* / (3 alpha) = -4/3
assert h_d(xs) == Fraction(-4, 3) == Fraction(-2 * M * G0 * LAM_S, 3 * ALPHA)
def test_lasalle_step_exact():
# on H_d,lambda = 0 the closed loop gives d/dt H_d,lambda = -lambda p / (k m),
# so H_d,lambda = 0 for all time forces p = 0 when lambda > 0
rng = random.Random(6)
for _ in range(100):
lam = Fraction(rng.randint(1, 60), rng.randint(1, 20))
p = Fraction(rng.randint(-30, 30), rng.randint(1, 9))
th = ZS - lam / ALPHA - Fraction(ALPHA, BW) * (lam * lam / (2 * K * ALPHA) - Fraction(M * G0, ALPHA))
x = [lam, th, p]
assert grad_hd(x)[0] == 0
lamd, thd, pd = plant(x, control(x))
dhl = (lam / (K * ALPHA) + Fraction(BW, ALPHA ** 2)) * lamd + Fraction(BW, ALPHA) * thd
assert dhl == -lam * p / (K * M)
def test_page_simulation():
def f(t, x, u):
return plant(x, control(x))
T = 10.0
ts, xs, us = ctlsim.simulate(f, [2.0, 0.3, 0.0], 0.0, T, DT)
assert len(us) == steps(T, DT)
hs = float(h_d([LAM_S, TH_S, 0]))
# rows: lambda, theta, p, u within 5e-5, and H_d - H_d* within 1 percent
table = {0.5: (2.04738, 0.30602, 0.03189, 1.43149, 1.614e-2), 1: (2.03087, 0.33331, 0.07436, 1.29427, 1.468e-2), 2: (1.97975, 0.41852, 0.07840, 1.12631, 7.474e-3), 4: (1.99471, 0.48943, 0.00642, 1.02937, 1.219e-4), 10: (1.99998, 0.49982, 0.00011, 1.00035, 2.427e-8)}
hd = [h_d(x) - hs for x in xs]
for t, row in table.items():
i = steps(t, DT)
x = xs[i]
assert all(abs(a - b) < 5e-5 for a, b in zip(list(x) + [control(x)], row[:4]))
assert abs(hd[i] - row[4]) < 0.01 * row[4]
assert abs(hd[0] - 0.02) < 1e-12
# H_d never increases (up to 1e-9 of RK4 error), and the energy balance
# H_d(T) - H_d(0) = -r_d int (H_d,lambda)^2 dt holds within 1e-8 (Simpson rule)
assert all(b - a < 1e-9 for a, b in zip(hd, hd[1:]))
v = [grad_hd(x)[0] ** 2 for x in xs]
simpson = DT / 3 * (v[0] + v[-1] + 4 * sum(v[1:-1:2]) + 2 * sum(v[2:-1:2]))
assert abs((hd[-1] - hd[0]) + RD * simpson) < 1e-8
# theta stays in [0.3, 0.5]; u runs from 1.6 down to u* = 1; error below 0.01 from t = 4.34 on
assert all(0.3 - 1e-12 <= x[1] <= 0.5 for x in xs)
uu = [control(x) for x in xs]
assert abs(uu[0] - 1.6) < 1e-12 and min(uu) > 1.0 and max(uu) <= 1.6 + 1e-12
err = [math.sqrt((x[0] - 2) ** 2 + (x[1] - 0.5) ** 2 + x[2] ** 2) for x in xs]
assert max(err[steps(4.34, DT):]) < 0.01 and err[steps(4.33, DT)] >= 0.01
def test_matching_failure_and_errors():
# a J_d whose coupling alpha = 3 does not fit the H_d built with alpha = 2:
# the unactuated momentum row cannot be matched
x = [Fraction(17, 10), Fraction(2, 5), Fraction(3, 10)]
try:
matching_control(JR, grad_h(x), G, jrd(3), grad_hd(x))
except MatchingError:
pass
else:
raise AssertionError("no error")
# floats with a tolerance
xf = [1.7, 0.4, 0.3]
assert abs(matching_control(JR, grad_h(xf), G, jrd(), grad_hd(xf), tol=1e-12)[0] - 1.225) < 1e-12
for bad in [lambda: matching_control(JR, grad_h(x), [[0], [0], [0]], jrd(), grad_hd(x)), lambda: matching_control(JR, grad_h(x), G[:2], jrd(), grad_hd(x))]:
try:
bad()
except ValueError:
continue
raise AssertionError("no error")
History
Passivity-based control of Euler-Lagrange systems was developed in the 1980s and 1990s, mainly for robots and electrical machines. Port-controlled Hamiltonian systems, introduced by Maschke and van der Schaft in the early 1990s, gave a model class with the energy, the interconnection and the dissipation as separate objects. Ortega, van der Schaft, Maschke and Escobar (2002) used this structure to make the design systematic: assign the interconnection and the damping of the closed loop, solve the matching equations for the energy, and prove convergence with LaSalle. Later work applied it to underactuated mechanical systems, power electronics and electrical machines.
References
- Romeo Ortega, Arjan van der Schaft, Bernhard Maschke and Gerardo Escobar, Interconnection and damping assignment passivity-based control of port-controlled Hamiltonian systems, Automatica 38(4), 585-596, 2002, Proposition 1 and Section 3.1 (the matching equation and the conditions on the target system), Section 3.2 (the matching PDE), and the condition for asymptotic stability by LaSalle
- Hassan K. Khalil, Nonlinear Systems, third edition, Prentice Hall, 2002, Section 4.2, the invariance principle
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 ST8SKY Edit this page History Report an error Markdown