Skip to content

Latest commit

 

History

History
300 lines (203 loc) · 8.58 KB

concepts.md

File metadata and controls

300 lines (203 loc) · 8.58 KB

Concepts

Barrier States (BaS) turn safety information into dynamical state variables that can be regulated together with the physical plant. The central design idea is to move safety from an external pointwise condition into an augmented dynamical model that can be used by standard control and optimization machinery.

Safe sets and safety functions

A state constraint is represented by one or more safety functions

$$ h_i(x)>0. $$

The library uses the convention

$$ h_i(x)>0 \quad \text{safe}, \qquad h_i(x)=0 \quad \text{boundary}, \qquad h_i(x)<0 \quad \text{unsafe}. $$

For multiple constraints,

$$ \mathcal{S} = \lbrace x \in \mathcal{X} \mid h(x) > 0 \rbrace. $$

This sign convention is used consistently by constraint constructors, barrier functions, safety checks, plotting, and trajectory optimization.

Barrier functions

A barrier operator maps a positive safety margin into a quantity that grows near the boundary:

$$ \beta(x)=B(h(x)). $$

The two built-in operators are the reciprocal barrier

$$ B_{\mathrm{rec}}(h)=\frac{\alpha}{h} $$

and the logarithmic barrier

$$ B_{\log}(h)=\alpha \ \log!\left(\frac{1+h}{h}\right). $$

Both become large as $h\rightarrow0^+$.

from barrier_states.barriers import logarithmic, reciprocal

barrier = reciprocal(constraint, alpha=1.0)
barrier = logarithmic(constraint, alpha=1.0)

Multiple constraints and aggregation

A constraint object may contain several scalar constraints. Barrier construction supports three modes:

aggregate="none"
aggregate="harmonic"
aggregate="barrier_sum"

"none" keeps one active barrier coordinate per scalar constraint. This is useful when individual safety quantities should remain visible to the controller.

"harmonic" produces one active barrier through a weighted harmonic aggregation of the safety functions.

"barrier_sum" produces one active barrier by summing the component barrier values.

Aggregation changes the number of active Barrier States, not the underlying definition of physical safety: safety is still checked against all original constraints.

Dynamic Barrier States

The barrier value $\beta(x)$ is algebraic. A dynamic Barrier State introduces a state $z$ whose dynamics reproduce the barrier evolution on a consistent manifold while adding stabilizing correction away from that manifold.

This library deliberately separates the Barrier State subsystem from the physical plant.

bas = DynamicContinuous(model, barrier, gamma=1.0)

DynamicContinuous represents only the continuous-time $z$ subsystem and provides quantities such as

bas.value(x)
bas.error(x, z)
bas.f(x, z)
bas.g(x, z)
bas.flow(x, z, u)
bas.flow_x(x, z, u)
bas.flow_z(x, z, u)
bas.flow_u(x, z, u)

Similarly, DynamicDiscrete represents only the discrete-time Barrier State subsystem:

dbas.value(x)
dbas.error(x, z)
dbas.step(x, z, u)
dbas.step_x(x, z, u)
dbas.step_z(x, z, u)
dbas.step_u(x, z, u)

This separation keeps the mathematical roles explicit:

physical model:       x dynamics
Barrier State model:  z dynamics
embedding:             [x, z] dynamics

Shifted Barrier State coordinates

When a safe reference state $x_{\mathrm{ref}}$ is supplied, the library uses a shifted Barrier State coordinate. Conceptually,

$$ z=\beta(x)-\beta(x_{\mathrm{ref}}) $$

on the consistent manifold. Therefore the Barrier State reference is zero:

$$ z_{\mathrm{ref}}=0. $$

bas = DynamicContinuous(model, barrier, gamma=1.0, reference_state=x_ref)

The same convention is available in discrete time.

Shifted coordinates are especially convenient for regulation and quadratic costs because the physical target and the Barrier State target can share one augmented reference.

Continuous-time realization

For a control-affine physical system

$$ \dot x=f(x)+g(x)u, $$

the continuous Barrier State dynamics are constructed so that, on the consistent manifold, $z$ follows the derivative of the barrier value along the physical trajectory. An error correction term weighted by gamma drives off-manifold Barrier State error back toward consistency.

The parameter

gamma > 0

controls the rate of that correction. It is a realization parameter, not a replacement for controller tuning.

Discrete-time realization

For

$$ x_{k+1}=F(x_k,u_k), $$

the discrete Barrier State realization propagates the next barrier value and contracts any off-manifold error with rho.

dbas = DynamicDiscrete(model, barrier, rho=0.05)

rho may be a scalar, a diagonal vector, or a contraction matrix. Scalar and diagonal entries satisfy

$$ 0\le\rho<1, $$

while a full matrix must have spectral radius less than one.

Safety embedding

The embedding layer combines the physical state and Barrier State:

$$ \bar x=\begin{bmatrix}x \\ z\end{bmatrix}. $$

Continuous time:

embedded = EmbeddedContinuous(model, bas)
xbar = embedded.augment_state(x)

Discrete time:

embedded = EmbeddedDiscrete(model, dbas)
xbar = embedded.augment_state(x)

The embedded models expose the ordinary model interface expected by controllers and solvers. For example:

embedded.flow(xbar, u)
embedded.flow_x(xbar, u)
embedded.flow_u(xbar, u)

or

embedded.step(xbar, u)
embedded.step_x(xbar, u)
embedded.step_u(xbar, u)

The embedding is therefore the bridge between the BaS construction and standard control algorithms.

Safety as a control objective

Once embedded, safety information appears in the augmented state itself. A controller or optimizer can penalize, stabilize, or otherwise regulate the Barrier State coordinates together with the physical states.

This is what allows the same construction to be paired with different methods:

BaS + state feedback / LQR
BaS + PID-style feedback
BaS + SDRE
BaS + DDP / iLQR
BaS + receding-horizon MPC
BaS + custom feedback policies

The library does not force one controller architecture around the Barrier State.

SDC form and SDRE

State-Dependent Riccati Equation control uses a state-dependent coefficient representation. For suitable continuous-time systems, the physical dynamics are written relative to a reference as

$$ \dot e=A(x)e+B(x)\tilde u. $$

DynamicContinuousSDC combines the ordinary continuous BaS realization with plant SDC data and a Barrier State SDC factorization. EmbeddedContinuous then assembles the full embedded state-dependent matrices used by SDREFeedback.

bas = DynamicContinuousSDC(model, barrier, plant_sdc, gamma=1.0, reference_state=x_ref, reference_input=u_ref)
embedded = EmbeddedContinuous(model, bas)
controller = SDREFeedback(embedded, Q, R)

The SDC factorization is part of the SDRE representation; it does not change the underlying safe set or barrier definition.

Trajectory optimization

For discrete-time embedded dynamics, BaS can be included directly in a finite-horizon objective. With an augmented reference $\bar x_{\mathrm{ref}}$, a quadratic cost can penalize both physical tracking error and Barrier State magnitude.

cost = quadratic_discrete(Q, R, Qf, x_ref=xbar_ref, u_ref=u_ref, x_final_ref=xbar_ref)

The DDP-family solver then optimizes the embedded trajectory:

solution = ddp(embedded, cost, xbar0, initial_controls, method="ilqr")

The same solver can use either an iLQR first-order dynamics approximation or full second-order DDP when the model provides the required second-order tensors.

Receding-horizon MPC

DDPMPC repeatedly solves the finite-horizon problem online:

measure x_k
   ↓
solve finite-horizon DDP/iLQR
   ↓
apply only u*_0
   ↓
plant advances to x_{k+1}
   ↓
shift the optimized controls as the next warm start
   ↓
solve again

The full predicted state and control sequences are retained for diagnostics and animation, while only the first optimized control is returned to the plant at each call.

What a BaS construction does—and does not—mean

Barrier States provide a dynamics-level way to represent and regulate safety. They should not be interpreted as a universal safety wrapper that makes an arbitrary controller safe automatically.

In practice, safety conclusions depend on the assumptions of the selected Barrier State construction, safe initialization, numerical validity, and successful bounded regulation of the embedded safety dynamics. The resulting guarantees also depend on the chosen controller and its ability to regulate the nonlinear embedded system over the relevant region of operation.

The library therefore keeps safety checks explicit and exposes Barrier State and constraint histories so that a result can be inspected rather than assumed.