主要内容

High-Order Control Barrier Function

Modify control actions to satisfy high-order control barrier function (CBF) constraints and action bounds

Since R2026a

  • High-Order Control Barrier Function block

Libraries:
Simulink Control Design / Constraint Control

Description

The High-Order Control Barrier Function block computes the modified control actions that are closest to specified control actions subject to high-order control barrier function constraints and action bounds.

A control barrier function defines a safety set h(x) ≥ 0 based on the system state x. If the initial system start within the safety set, the High-Order Control Barrier Function block adjusts the control actions to keep the states within the safety set. The block uses a quadratic programming (QP) solver to find the control action u that minimizes |uu0|2 in real time. Here, u0 is the original control action from the controller.

The solver applies constraints based on the barrier function relative order.

Barrier Function Relative OrderConstraint Equation
FirstLfh+Lghu+γ1hβ10uminuumax
SecondLf2h+LgLfhu+γ1hβ1+γ2(Lfh)β20uminuumax
ThirdLf3h+LgLf2hu+γ1hβ1+γ2(Lfh)β2+γ3(Lf2h)β30uminuumax
FourthLf4h+LgLf3hu+γ1hβ1+γ2(Lfh)β2+γ3(Lf2h)β3+γ4(Lf3h)β40uminuumax

Here:

  • f(x) and g(x) are the drift and control vector fields of the plant dynamics equation x˙=f(x)+g(x)u, respectively.

  • h(x) is the barrier function.

  • Lfih is the i-th Lie derivative of hx with respect to x, with Lfh(x)=hxf(x) and Lfih(x)=Lfi1h(x)xf(x).

  • LgLfih is given by LgLfih(x)=Lfih(x)xg(x).

  • γi and βi are parameters for controlling the effect of the barrier certificate.

  • umin is a lower bound for the control action.

  • umax is an upper bound for the control action.

The High-Order Control Barrier Function block requires Optimization Toolbox™ software.

For more information on control barrier function enforcement, see Enforce Safety Constraints with Control Barrier Functions.

Examples

expand all

This example shows how to compute Lie derivatives for a quadruple integrator and apply constraints using the High-Order Control Barrier Function block.

Consider the quadruple integrator system defined as:

x˙1=x2x˙2=x3x˙3=x4x˙4=u

Writing in the control-affine form, you get:

x˙=f(x)+g(x)u,f(x)=[x2x3x40],g(x)=[0001]

This example provides the model quadIntegratorCBF preconfigured with two variant subsystems, one for baseline state-feedback control and the other that imposes CBF constraints.

Baseline Simulation

Design a baseline state-feedback controller using pole placement to drive all system states to zero.

A = [0 1 0 0;
     0 0 1 0;
     0 0 0 1;
     0 0 0 0];
B = [0;0;0;1];
C = eye(4);
D = zeros(4,1);
sys = ss(A,B,C,D);
initcond = [4;0;0;0];
p = [-0.5+1.5j, -0.5-1.5j,-5,-6]; 
K = place(A,B,p);

Simulate the model with the baseline controller.

mdl = "quadIntegratorCBF";
open_system("quadIntegratorCBF")
set_param([mdl+"/Select Input"], 'LabelModeActiveChoice','nominal')
sim(mdl,15);
open_system("quadIntegratorCBF/Scope")

Safety Set and Lie Derivatives

Now, define a control barrier function (CBF) for this system that ensures x1 stays above the boundary x10.5.

h(x)=x1-0.5

To determine the relative degree, compute successive time derivatives of h(x) until u appears explicitly.

h˙=x˙1=x2

h¨=x˙2=x3

h=x˙3=x4

h=x˙4=u

The control input term u appears in the fourth derivative of h(x), so the relative degree for this system is 4. Compute the required Lie derivatives for relative degree 4.

Lfh=[x1h(x)x2h(x)x3h(x)x4h(x)]f(x)=[1000][x2x3x40]=x2

Similarly,

Lf2h=(xLfh)f(x)=[0100][x2x3x40]=x3

Lf3h=(xLf2h)f(x)=[0010][x2x3x40]=x4

Lf4h=(xLf3h)f(x)=[0001][x2x3x40]=0

LgLf3h=(xLf3h)g(x)=[0001][0000]=1

Simulation with Constraints

To impose the CBF constraints, use the High-Order Control Barrier Function block. In the Simulink model, the CBF Constraint variant of the Select Input subsystem shows how to provide the required inputs: the baseline controller output, the control barrier function, and the computed Lie derivatives.

By default, the order (relative degree) parameter is set to 2, so you must configure the block parameter as follows.

Enable the CBF Constraint variant and run the simulation.

x1min = 0.5;
set_param([mdl+"/Select Input"], 'LabelModeActiveChoice','enableCBF')
sim(mdl,15);
open_system("quadIntegratorCBF/Scope")

Additionally, you can tune the Poles for exponential decay rate parameter to speed up convergence. For example, set the decay to to -2 and simulate the model. x1 converges faster to the boundary but causes more overshoot in other states.

set_param([mdl+"/Select Input/CBF Constraint/High-Order Control Barrier Function"],"DecayPoles","-2")
sim(mdl,15);
open_system("quadIntegratorCBF/Scope")

Extended Examples

Ports

Input

expand all

Unmodified control actions, specified as a scalar or a vector.

If the Number of actions parameter is 1, connect u0 to a scalar signal. Otherwise, connect u0 to a vector signal with length equal to Number of actions.

Control barrier function, defined as the following safety set for plant states.

{x:h(x)0}

Connect hx to an Nc-by-1 signal, where Nc is equal to the Number of barrier certificates parameter.

First Lie derivative of h(x) along the f(x), defined as:

Lfh(x)=hxf(x)

Connect this port to an Nc-by-1 signal, where Nc is equal to Number of barrier certificates.

First Lie derivative of h(x) along the g(x), defined as:

Lgh(x)=hxg(x)

Connect this port to an Nc-by-Nu signal, where Nc is equal to Number of barrier certificates and Nu is equal to Number of actions.

Dependencies

To enable this port, set Order to 1.

Second Lie derivative of h(x) along the f(x), defined as:

Lf2h(x)=Lfh(x)xf(x)

Connect this port to an Nc-by-1 signal, where Nc is equal to Number of barrier certificates.

Dependencies

To enable this port, set Order to 2, 3, or 4.

Lie derivative of Lfh(x) along the g(x), defined as:

LgLfh(x)=Lfh(x)xg(x)

Connect this port to an Nc-by-Nu signal, where Nc is equal to Number of barrier certificates and Nu is equal to Number of actions.

Dependencies

To enable this port, set Order to 2.

Third Lie derivative of h(x) along the f(x), defined as:

Lf3h(x)=Lf2h(x)xf(x)

Connect this port to an Nc-by-1 signal, where Nc is equal to Number of barrier certificates.

Dependencies

To enable this port, set Order to 3.

Lie derivative of L2fh(x) along the g(x), defined as:

LgLf2h(x)=Lf2h(x)xg(x)

Connect this port to an Nc-by-Nu signal, where Nc is equal to Number of barrier certificates and Nu is equal to Number of actions.

Dependencies

To enable this port, set Order to 3.

Fourth Lie derivative of h(x) along the f(x), defined as:

Lf4h(x)=Lf3h(x)xf(x)

Connect this port to an Nc-by-1 signal, where Nc is equal to Number of barrier certificates.

Dependencies

To enable this port, set Order to 4.

Lie derivative of L3fh(x) along the g(x), defined as:

LgLf3h(x)=Lf3h(x)xg(x)

Connect this port to an Nc-by-Nu signal, where Nc is equal to Number of barrier certificates and Nu is equal to Number of actions.

Dependencies

To enable this port, set Order to 4.

To specify run-time upper bounds to the action signals, enable this input port. If this port is disabled, the block does not apply any upper bounds to the control actions.

If the Number of actions parameter is 1, connect umax to a scalar signal. Otherwise, connect umax to a vector signal with length equal to Number of actions.

Dependencies

To enable this input port, select the Use external source for upper bound parameter.

To specify run-time lower bounds to the action signals, enable this input port. If this port is disabled, the block does not apply any lower bounds to the control actions.

If the Number of actions parameter is 1, connect umin to a scalar signal. Otherwise, connect umin to a vector signal with length equal to Number of actions.

Dependencies

To enable this input port, select the Use external source for lower bound parameter.

Output

expand all

Modified control action returned by the QP solver.

If the solver finds a solution before reaching the maximum number of iterations, u* outputs this optimal solution.

If the solver reaches the maximum number of iterations, optimization stops and u* outputs a suboptimal solution.

If the initial optimization problem is infeasible, the returned control action depends on the whether the block is configured to ignore constraint or action bounds. For more information, see the exitflag parameter.

If the Number of actions parameter is 1, u* outputs a scalar signal. Otherwise, u* outputs a vector signal with length equal to Number of actions.

Optimization status of the QP solver. The following table shows the possible status values.

Exit FlagDescription
1The solver converged to an optimal solution with all constraints and bounds active. In this case, u* outputs the optimal control actions.
0The solver reached the maximum number of iterations. The control actions output in u* might be suboptimal.
negative integer

The initial optimization problem was infeasible and one of the following scenarios applies.

  • Rerunning the optimization without action bounds did not produce a feasible solution.

  • Rerunning the optimization without constraint bounds did not produce a feasible solution.

In this case, the control actions output in u* are zero.

Dependencies

To enable this output port, select the Optimization status parameter.

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Specify the number of plant states.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: nx
Values: "1" (default) | positive integer in quotes

Example: set_param(gcb,"nx","3")

Specify the number of control actions to apply bounds to and optimize.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: nu
Values: "1" (default) | positive integer in quotes

Example: set_param(gcb,"nu","2")

Specify the number of barrier certificate constraints to enforce.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: nc
Values: "1" (default) | positive integer in quotes

Example: set_param(gcb,"nc","2")

Specify the barrier function order. This is the number of time derivatives of h you must take before the control term u appears explicitly

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Order
Values: "2" (default) | "1" | "3" | "4"

Example: set_param(gcb,"Order","2")

Enforce strict state-dependent high-relative degree safety for nonlinear systems. When you enable this option, the software automatically computes the constraint factor gains γi based on the poles specified in the Poles for exponential decay rate parameter.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: ExponentialCBF
Values: "on" (default) | "off"

Example: set_param(gcb,"ExponentialCBF","off")

Pole values for exponential decay rate, specified as a real negative scalar or matrix of size nc-by-no, where nc is the Number of barrier certificates and no is the Order.

Dependencies

To enable this option, select Use exponential high-order CBF.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: DecayPoles
Values: "-1" (default) | real negative scalar in quotes | nc-by-no matrix in quotes

Example: set_param(gcb,"DecayPoles","[-1,-2;-3,-4]")

Constraint factor γi in the barrier certificate constraint, specified as a positive scalar or matrix of size nc-by-no, where nc is the Number of barrier certificates and no is the Order.

Dependencies

To enable this option, disable Use exponential high-order CBF.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: gamma
Values: "10" (default) | positive scalar in quotes

Example: set_param(gcb,"gamma","4")

Constraint power β in the barrier certificate constraint, specified as a positive scalar or matrix of size nc-by-no, where nc is the Number of barrier certificates and no is the Order.

Dependencies

To enable this option, disable Use exponential high-order CBF.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: beta
Values: "1" (default) | positive scalar in quotes

Example: set_param(gcb,"beta","2")

Select this parameter to add the umax input port for external upper action bounds.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: external_umax
Values: "off" (default) | "on"

Example: set_param(gcb,"external_umax","on")

Select this parameter to add the umin input port for external lower action bounds.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: external_umin
Values: "off" (default) | "on"

Example: set_param(gcb,"external_umin","on")

Specify the output data type.

The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click .

You can specify the following data types.

  • Built insingle or double data types.

  • Expression — Use a MATLAB expression that specifies the type.

For more information, see Specify Data Types Using Data Type Assistant.

Specify the sample time for running the optimization.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: Ts
Values: "0.1" (default) | positive scalar in quotes

Example: set_param(gcb,"Ts","0.2")

Specify the maximum number of optimization iterations.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: maxiter
Values: "200" (default) | positive integer in quotes

Example: set_param(gcb,"maxiter","300")

Specify a tolerance value for constraint violations.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: tol
Values: "1e-6" (default) | nonnegative scalar in quotes

Example: set_param(gcb,"tol","1e-4")

Select this parameter to add the exitflag output port for the optimization status of the QP solver.

Programmatic Use

To set the block parameter value programmatically, use the set_param function.

Parameter: output_exitflag
Values: "off" (default) | "on"

Example: set_param(gcb,"output_exitflag","on")

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2026a