Main Content

solve

R2026b

Solve for safe control action using control barrier function

Since R2026b

    Description

    [ustar,exitflag] = solve(cbf,x,u) finds the safe control action ustar that satisfies control barrier function safety constraints defined in cbf while minimizing the deviation from the nominal action u. The function defines linear inequality constraints by evaluating the control barrier function and its Lie derivatives at run time. It then constructs a quadratic programming problem and solves it using the quadprog function, which requires Optimization Toolbox™ software.

    This function requires Optimization Toolbox software.

    example

    [ustar,exitflag] = solve(cbf,x,u,Name=Value) additionally specifies options using one or more name-value arguments. For example, use ActionMin and ActionMax to impose bounds on the control action.

    example

    Examples

    collapse all

    Compute a safe control action for a system with 4 states and 2 control inputs using a configured control barrier function.

    Create and configure a ControlBarrierFunction object.

    cbf = ControlBarrierFunction(4,2,RelativeOrder=2);
    cbf.Constraints.BarrierFcn = "myBarrierFcn";
    cbf.Constraints.LieDerivativeFcn = "myLieDerivatives";

    Define the current state and nominal control action.

    x = [1; 0.5; -0.2; 0.1];
    u_nominal = [0.8; -0.3];

    Solve for the safe control action.

    [ustar, exitflag] = solve(cbf, x, u_nominal);

    Impose physical actuator limits on the safe control action.

    Create and configure a ControlBarrierFunction object.

    cbf = ControlBarrierFunction(2,1,RelativeOrder=1);
    cbf.Constraints.BarrierFcn = "safetyConstraint";
    cbf.Constraints.LieDerivativeFcn = "cbfLieDerivatives";

    Define state, nominal action, and actuator bounds.

    x = [1.5; 0.3];
    u_nominal = 2.0;
    uMin = -5;
    uMax = 5;

    Solve with action bounds.

    [ustar,exitflag] = solve(cbf,x,u_nominal, ...
        ActionMin=uMin, ...
        ActionMax=uMax);

    Input Arguments

    collapse all

    Control barrier function object, specified as a ControlBarrierFunction object. The object must have valid BarrierFcn and LieDerivativeFcn functions configured in cbf.Constraints before calling this method.

    Current state vector, specified as a real numeric column vector of length cbf.NumOfStates. The barrier function and Lie derivative function are evaluated at this state to construct the safety constraints.

    Nominal control action, specified as a real numeric column vector of length cbf.NumOfActions. The QP solver minimizes the squared deviation from this nominal action subject to the safety constraints. The nominal action represents the desired control input before safety filtering.

    Name-Value Arguments

    collapse 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: [ustar,exitflag] = solve(cbf,x,u,IntegrityChecks=false) disables input and function validation.

    Lower bound for the control action, specified as a real numeric column vector of length cbf.NumOfActions. Each element specifies the minimum allowable value for the corresponding control input. By default, no lower bound is imposed.

    Upper bound for the control action, specified as a real numeric column vector of length cbf.NumOfActions. Each element specifies the maximum allowable value for the corresponding control input. By default, no upper bound is imposed.

    Enable input and function validation, specified as a logical scalar. When true, the method validates the barrier function output dimensions and Lie derivative function output dimensions before solving the QP. Set to false to skip validation for improved performance in time-critical applications where the functions are known to be correctly configured.

    Output Arguments

    collapse all

    Safe control action, returned as a real numeric column vector of length cbf.NumOfActions. The value of ustar is the solution to the QP problem that minimizes ||ustar – u||2 subject to the safety constraints Au <= b and the specified action bounds defined in cbf. If the QP problem is infeasible, ustar may be empty or unreliable depending on the solver behavior.

    Solver exit flag, returned as an integer from the quadprog function. A value of 1 indicates that the function converged to a solution and a value of 0 indicates that the maximum number of iterations was reached without converging. Other values indicate issues such as infeasibility or solver failure. For a complete list of exit flag values, see quadprog (Optimization Toolbox).

    Algorithms

    The solve function uses a quadratic programming (QP) solver to find the control action u that minimizes the function |u−u0|2. Here, u0 is the unmodified control action.

    The solver applies the following constraints to the optimization problem.

    qxfx+qxgxu+γhxβ≥0umin≤u≤umax

    Here:

    • fx and gx are functions defined by the plant dynamics x˙=f(x)+g(x)u.

    • hx is the control barrier function defined in cbf.Constraints.BarrierFunction.

    • qx is the partial derivative of the control barrier function over states x.

    • γ is the constraint factor defined in cbf.Constraints.ConstraintFactor.

    • β is the constraint power defined in cbf.Constraints.ConstraintPower.

    • umin is a lower bound for the control action, which you specify using ActionMin.

    • umax is an upper bound for the control action, which you specify using ActionMax.

    Version History

    Introduced in R2026b