Main Content

ControlBarrierFunction

R2026b

Control barrier function

Since R2026b

    Description

    To compute modified control actions that are closest to nominal control actions subject to barrier certificate constraints and action bounds, you can use a ControlBarrierFunction object.

    1. Configure the barrier function constraints and action bounds using the ControlBarrierFunction object.

    2. Generate Lie derivatives for the barrier function using the generateLieDreivativeFcn function or specify a manually derived Lie-derivative function directly in the object.

    3. Compute the modified control actions using the solve function.

    This workflow requires Optimization Toolbox™ software.

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

    Creation

    Description

    cbf = ControlBarrierFunction(nx,nu) creates a control barrier function object for a system with nx states and nu control inputs. The object is configured with default settings: one safety constraint and relative order 1.

    example

    cbf = ControlBarrierFunction(nx,nu,Name=Value) additionally specifies the number of safety constraints or relative order using one or two name-value arguments.

    example

    Input Arguments

    expand all

    Number of states in the system, specified as a positive integer. This value sets the NumOfStates property, which is the expected length of the state vector passed to solve.

    Number of control inputs in the system, specified as a positive integer. This value sets the NumOfActions property, which is the expected length of the control action vector passed to solve.

    Name-Value Arguments

    expand all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: cbf = ControlBarrierFunction(nx,nu,RelativeOrder=2) creates a control barrier function with relative order 2.

    Number of safety constraints, specified as a positive integer. Each constraint corresponds to a separate barrier function condition that the safe control action must satisfy. The barrier function must return a column vector of this length.

    Specifying this argument sets the cbf.Constraints.NumOfConstraints property value. You must set the number of constraints when you create the control barrier function.

    Relative order of the barrier function, specified as an integer values from 1 to 4. The relative order determines how many Lie derivatives are needed to make the control input appear explicitly in the safety constraint. A relative order of 1 corresponds to a standard CBF, while higher orders handle systems where the barrier function has higher relative degree with respect to the control input.

    Specifying this argument sets the cbf.Constraints.RelativeOrder property value. You must set the relative order when you create the control barrier function.

    Properties

    expand all

    This property is read-only.

    Number of states in the system, specified as a positive integer. This value corresponds to the expected length of the state vector passed to solve.

    This property is read-only.

    Number of control inputs in the system, specified as a positive integer. This value corresponds to the expected length of the control action vector passed to solve.

    Constraint configuration, specified as a control.cbf.Constraints object with these properties.

    This property is read-only.

    Number of safety constraints, stored as a positive integer. Each constraint corresponds to a separate barrier function condition that the safe control action must satisfy. The barrier function must return a column vector of this length.

    Relative order of the barrier function, stored as an integer values from 1 to 4. The relative order determines how many Lie derivatives are needed to make the control input appear explicitly in the safety constraint. A relative order of 1 corresponds to a standard CBF, while higher orders handle systems where the barrier function has higher relative degree with respect to the control input.

    Barrier function, specified as a function name or function handle. For a simple function, the MATLAB® function file must be in the current working folder or on the MATLAB path.

    The barrier function must take the current state values as the first input argument and return the computed constraint values. For example:

    c = myBarrierFcn(x)

    Here:

    • x is a column vector of state values with length equal to NumOfStates.

    • c is a column vector of computed constraint values with length equal to NumOfConstraints.

    If your barrier function has only one input argument, you can specify BarrierFcn as the function name.

    cbf.Constraints.BarrierFcn = "myBarrierFcn";

    If your barrier function has additional parameters as input arguments, you can specify BarrierFcn using an anonymous function handle.

    cbf.Constraints.BarrierFcn = @(x) myBarrierFcn(x,P1,P2);

    Here, P1 and P2 are parameters that are required to compute the constraint values.

    Dependencies

    You must specify BarrierFcn before calling the generateLieDerivativeFcn or solve functions.

    Lie derivative function, specified as a function name. The specified function must be in the current working folder or on the MATLAB path. You can manually define your Lie derivative function or create one using the generateLieDerivativeFcn function.

    The Lie derivative function signature depends on the value of RelativeOrder.

    Dependencies

    • You must specify LieDerivativeFcn before calling the solve function.

    • LieDerivativeFcn is set by the generateLieDerivativeFcn function.

    Scaling factors γ applied to constraint terms, specified as a NumOfConstraints-by-RelativeOrder matrix of nonnegative values.

    Increasing the scaling factor generally makes the barrier function act earlier and more strongly. Decreasing the scaling factor allows more time for the nominal controller to act.

    Exponents β for constraint terms, specified as a NumOfConstraints-by-RelativeOrder matrix of positive odd integer values.

    An exponent of 1 produces roughly linear constraints. A larger exponent amplifies smaller violations and can produce more conservative and sharper interventions.

    Optimization configuration, specified as a control.cbf.Optimization object with these properties.

    This property is read-only.

    Optimization solver, stored as the string "quadprog". The ControlBarrierFunction object currently supports only the quadprog (Optimization Toolbox) solver.

    Solver options, specified as a optim.options.Quadprog object. You can modify solver options using dot notation. For example, set the maximum number of iterations to 50.

    cbf.Optimization.SolverOptions.MaxIterations = 50;

    For more information on configuring these options, see quadprog (Optimization Toolbox).

    Object Functions

    generateLieDerivativeFcnGenerate Lie derivative functions for control barrier function
    solveSolve for safe control action using control barrier function

    Examples

    collapse all

    Create a CBF object for a system with 2 states and 1 control input.

    Create a ControlBarrierFunction object with default settings (1 constraint, relative order 1).

    cbf = ControlBarrierFunction(2,1);

    View the object properties.

    cbf.NumOfStates
    cbf.NumOfActions
    cbf.Constraints.RelativeOrder
    ans =
         2
    
    ans =
         1
    
    ans =
         1

    Create a CBF object for a 4-state, 2-input system with 3 safety constraints and relative order 2.

    Create the object with custom constraint settings.

    cbf = ControlBarrierFunction(4,2, ...
        NumOfConstraints=3, ...
        RelativeOrder=2);

    Configure the barrier function and Lie derivative function.

    cbf.Constraints.BarrierFcn = "myBarrierFcn";
    cbf.Constraints.LieDerivativeFcn = "myLieDerivatives";

    Solve for a safe control action given a state and nominal input.

    x = [1; 0.5; -0.2; 0.1];
    u_nominal = [0.8; -0.3];
    [ustar,exitflag] = solve(cbf,x,u_nominal);

    Version History

    Introduced in R2026b