Control Barrier Function
Modify control actions to satisfy barrier certificate constraints and action bounds
Since R2022a
Libraries:
Simulink Control Design /
Constraint Control
Description
The Control Barrier Function block computes the modified control actions that are closest to specified control actions subject to barrier certificate constraints and action bounds.
The block uses a quadratic programming (QP) solver to find the control action u that minimizes the function . Here, u0 is the unmodified control action.
The solver applies the following constraints to the optimization problem.
Here:
fx and gx are functions defined by the plant dynamics .
hx is the control barrier function.
qx is the partial derivative of the control barrier function over states x.
γ is the constraint factor.
β is the constraint power.
umin is a lower bound for the control action.
umax is an upper bound for the control action.
The Control Barrier Function block requires Optimization Toolbox™ software.
For more information on barrier certificate enforcement, see Enforce Safety Constraints with Control Barrier Functions.
Examples
Enforce Barrier Certificate Constraints for PID Controllers
Apply barrier certificate constraints to a PID control application using the Barrier Certificate Enforcement block.
Enforce Barrier Certificate Constraints for Adaptive Cruise Control
Enforce barrier certificate constraints for adaptive cruise control to maintain velocity and following distance.
Enforce Barrier Certificate Constraints for Collision-Free Robots
Enforce barrier certificate constraints for two robots to reach their target positions in collision-free manner.
Enforce Barrier Certificate Constraints for Collision-Free Multi-Robot System
Enforce barrier certificate constraints for three robots to reach their target positions in collision-free manner.
Ports
Input
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.
State function f(x) in the following plant dynamics equation.
Connect fx to an Nx-by-1 signal, where Nx is equal to the Number of states parameter.
Input function g(x) in the following plant dynamics equation.
Connect gx to an Nx-by-Nu signal, where Nx is equal to the Number of states parameter and Nu is equal to the Number of actions parameter.
Control barrier function, defined as the following safety set for plant states.
Connect hx to an Nc-by-1 signal, where Nc is equal to the Number of barrier certificates parameter.
Partial derivative of the control barrier function over plant states.
Connect qx to an Nc-by-Nx signal, where Nc is equal to the Number of barrier certificates parameter and Nx is equal to the Number of states parameter.
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
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 Flag | Description |
|---|---|
1 | The solver converged to an optimal solution with all constraints and bounds active. In this case, u* outputs the optimal control actions. |
0 | The 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.
In this case, the control actions output in u* are zero. |
Dependencies
To enable this output port, select the Optimization status parameter.
Parameters
Parameters Tab
Specify the number of states in your plant.
Programmatic Use
Block Parameter:
nx |
| Type: character vector |
Default:
'1' |
Specify the number of actions to apply bounds to and optimize.
Programmatic Use
Block Parameter:
nu |
| Type: character vector |
Default:
'1' |
Specify the number of barrier certificate constraints to enforce.
Programmatic Use
Block Parameter:
nc |
| Type: character vector |
Default:
'1' |
Specify the constraint factor γ in the barrier certificate constraint.
If the Number of barrier certificates parameter is
1, specify Constraint factor as
a finite positive scalar. Otherwise, you can specify Constraint
factor as either a finite positive scalar value or a column
vector of positive scalars with length equal to Number of barrier
certificates.
Programmatic Use
Block Parameter:
gamma |
| Type: character vector |
Default:
'10' |
Specify the constraint power β in the barrier certificate constraint.
If the Number of barrier certificates parameter is
1, specify Constraint power as a
positive odd integer. Otherwise, you can specify Constraint
power as either a positive odd integer or a column vector of
positive odd integers with length equal to Number of barrier
certificates.
Programmatic Use
Block Parameter:
beta |
| Type: character vector |
Default:
'1' |
Select this parameter to add the umax input port for external upper action bounds.
Programmatic Use
Block Parameter:
external_umax |
| Type: character vector |
Values:
'off'|'on' |
Default:
'off' |
Select this parameter to add the umin input port for external lower action bounds.
Programmatic Use
Block Parameter:
external_umin |
| Type: character vector |
Values:
'off'|'on' |
Default:
'off' |
Block Tab
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 in—singleordoubledata 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
Block Parameter:
Ts |
| Type: character vector |
Default:
'0.1' |
Specify the maximum number of optimization iterations.
Programmatic Use
Block Parameter:
maxiter |
| Type: character vector |
Default:
'200' |
Specify a tolerance value for constraint violations.
Programmatic Use
Block Parameter:
tol |
| Type: character vector |
Default:
'1e-6' |
Select this parameter to add the exitflag output port for the optimization status of the QP solver.
Programmatic Use
Block Parameter:
exitflag |
| Type: character vector |
Values:
'off'|'on' |
Default:
'off' |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2022aStarting in R2026a, the Barrier Certificate Enforcement block is renamed to the Control Barrier Function block.
The Barrier Certificate Enforcement block is now in the Simulink Control Design/Constraint Control sublibrary.
In R2023b, when you open a model saved in a previous release, the library links for Barrier Certificate Enforcement blocks update automatically.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)




