Main Content

generateLieDerivativeFcn

R2026b

Generate Lie derivative functions for control barrier function

Since R2026b

    Description

    The generateLieDerivativeFcn function generates MATLAB® functions that compute the Lie derivatives of a control barrier function represented by a ControlBarrierFunction object.

    You can programmatically define a control barrier function using a ControlBarrierFunction object and use the generateLieDreivativeFcn function to generate Lie derivatives using auto-differentiation. You can then solve for modified control actions using the solve function. For an example, see Safe PID Tracking and Obstacle Avoidance Using Control Barrier Function.

    Also, you can use the generateLieDerivativeFcn function to generate Lie derivatives for control barrier functions modeled in Simulink® using the Control Barrier Function or High-Order Control Barrier Function blocks. For an example, see Safe PID Controller for Two Link Robot using High-Order Control Barrier Function.

    cbfNew = generateLieDerivativeFcn(cbf,mdlFcn) generates MATLAB function files that compute the Lie derivative Jacobians of the barrier function defined in cbf with respect to the system dynamics specified by model function mdlFcn. The generated files are saved to the same directory as the model function file. The method updates cbf.Constraints.LieDerivativeFcn with the default output function name.

    The barrier function and model function must both use only supported auto-differentiation operations. For more information, see Supported Operations on Expressions.

    example

    cbfNew = generateLieDerivativeFcn(cbf,mdlFcn,OutputFcnName=outFcn) specifies the base name of the generated files.

    example

    Examples

    collapse all

    Generate Lie derivative functions for a control barrier function with relative order 2 and a user-defined system dynamics model.

    Create a ControlBarrierFunction object with 4 states and 2 control inputs, specifying relative order 2.

    cbf = ControlBarrierFunction(4,2,RelativeOrder=2);

    Set the barrier function. The barrier function must be defined in an M-file that accepts the state vector x.

    cbf.Constraints.BarrierFcn = "myBarrierFcn";

    Generate the Lie derivative functions using a system dynamics model function.

    cbf = generateLieDerivativeFcn(cbf,"myDynamicsModel");

    The method generates a package folder containing the Jacobian functions (cbfLieDerivatives_dhdx and cbfLieDerivatives_dLfhdx) and a top-level function (cbfLieDerivatives) that evaluates all Lie derivatives at a given state. The generated top-level function has the signature:

    [Lfh,Lf2h,LgLfh] = cbfLieDerivatives(x)

    Generate Lie derivative functions with a custom base name for the output files.

    Create and configure a CBF object.

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

    Generate Lie derivative functions with a custom output name.

    cbf = generateLieDerivativeFcn(cbf,"systemDynamics", ...
    OutputFcnName="mySafetyDerivatives");

    Verify the generated function is linked to the object.

    cbf.Constraints.LieDerivativeFcn
    ans =
        "mySafetyDerivatives"

    Input Arguments

    collapse all

    Control barrier function, specified as a ControlBarrierFunction object. The object must have a valid barrier function set in cbf.Constraints.BarrierFcn before the calling generateLieDerivativeFcn function. The cbf.Constraints.RelativeOrder property determines how many Lie derivative orders are generated.

    System dynamics function, specified as a function name, using a string scalar or character vector, or function handle. The function must be in the current working folder or on the MATLAB path.

    Use this function to define the plant dynamics x˙=f(x)+g(x)u.

    The function signature must be:

    [f,g] = mdlFcn(x)

    Here:

    • x is the current state.

    • f is the value of the state function dynamics f(x)

    • g is the value of the input function g(x)

    Base name for the generated function files, specified as a nonempty string or character vector. The generateLieDerivativeFcn function uses this name to create a package folder and individual Jacobian function files. For example, if OutputFcnName is "myLieDerivatives", the generated files include myLieDerivatives_dhdx, myLieDerivatives_dLfhdx, and so on depending on the relative order.

    The generateLieDerivativeFcn function also creates a top-level function named OutputFcnName which evaluates all Lie derivatives for a given state.

    Output Arguments

    collapse all

    Updated control barrier function, returned as a ControlBarrierFunction object. The cbf.Constraints.LieDerivativeFcn property is set to the value of OutputFcnName, linking the generated Lie derivative function to the object for use in subsequent calls to the solve function.

    Version History

    Introduced in R2026b