Convex Synthesis of Control Barrier Functions Under Input Constraints

This letter presents a systematic method based on the sum of square (SOS) optimization to synthesize control barrier functions (CBFs) for nonlinear polynomial systems subject to input constraints. The approach consists of two design steps. In the first step, using a linear-like representation of the nonlinear dynamics, an SOS optimization problem is formulated to search for an initial CBF and controller jointly. In the second step, an iterative optimization procedure involving the solution of a series of SOS problems is proposed to alternatively update the CBF and the controller to increase the invariant set defined by the CBF. The efficacy of the proposed approach is validated using numerical examples.


I. INTRODUCTION
C ONTROL barrier functions (CBFs) have emerged as a practical tool for controlling nonlinear systems with safety constraints [1], [2]. CBFs can be used to synthesize control signals to enforce state constraints by ensuring set invariance, while not resorting to a specific control law [1]. On the other hand, input constraints exist in almost any realworld system. Consideration of input constraints in control design is therefore needed for practical implementation.
In most of the existing work on CBFs [1], [2], [3], [4], [5], a function is heuristically or intuitively selected and assumed to be a CBF. However, this heuristic or intuitive design procedure works only for naive scenarios, e.g., simple box constraints on position or velocity [1], [2], [3], [4], [5]. Given an intuitively designed candidate function, one still needs to verify that this function is indeed a CBF, which is particularly important in the presence of input constraints. Otherwise, the feasibility of the QP problem formulated to construct the control signal and safety of the system cannot be guaranteed.
Contributions: This letter presents a systematic method based on convex optimization (in particular, sum of squares (SOS) optimization [6]) for the synthesis of CBFs in the presence of input constraints for nonlinear polynomial systems. Our method consists of two design steps, each yielding a valid CBF. The initial design is to jointly search an initial CBF and a controller, using a state-dependent linear-like form of the nonlinear dynamics and SOS techniques, in which the volume of the CBF-defined invariant set is maximized. The second step is to alternatively update the CBF obtained from the first step and the controller while fixing the other using the original nonlinear dynamics. Numerical examples are included to validate the effectiveness of the proposed method.
Related Work: A closely related problem is Lyapunovbased nonlinear control synthesis using SOS optimization. Leveraging a linear-like representation, [7] proposed to search for a state-dependent Lyapunov function (LF) and a controller jointly using SOS programming. In [7], nonlinear terms involving the product of LF coefficients and controller gain are avoided by constraining the LF to depend on states whose derivatives are not directly affected by any control input. The result in [7] motivates our proposed approach to CBF synthesis (the first step). Finally, [8] proposed to iteratively search for control Lyapunov functions (CLFs) via SOS optimization without searching for a controller.
Convex optimization-based nonlinear control synthesis under input constraints has also been studied. The author of [9] introduced a polytope model to characterize the saturation and formulated the design problem as an SOS problem by extending the linear matrix inequality (LMI) approach for linear systems with input saturation. In [10], a system with saturating input was converted to a new system with unsaturated input and a vanishing disturbance input, to which a standard design method inspired by [7] can be applied. Also inspired by [7], the authors of [11] formulated an SOS optimization problem to compute the optimal feedback gain for predictive control of a nonlinear system subject to input constraints. This letter motivates the first step of our SOS-based method for CBF synthesis.
CBF synthesis has been explored recently based on SOS optimization [12], [13], [14], linearization [15], machine learning [16], [17] and Hamilton-Jacobi reachability analysis [18], [19]. In [12], the authors proposed to sequentially update a CBF and a controller while fixing the other using SOS optimization. However, the design procedure needs an LF to calculate an initial CBF, while how to obtain such an LF was not given. In [13], the author presented an SOS optimization-based method for CBF synthesis, which, unfortunately, is computationally heavy and does not guarantee the return of a valid CBF. Very few works considered CBF synthesis under input constraints. In [15], the authors proposed to synthesize CBFs for discrete-time nonlinear systems with input constraints, by first searching for a quadratic CBF for a linearized system and then refining it for the nonlinear systems. However, the limit to quadratic functions makes the design overly conservative. Additionally, the design procedure requires a global solution of nonlinear programming problems, which, by itself, is a challenging problem. Very recently, [14] proposed an SOS optimization-based method for CLF/CBF synthesis that both accounts for input constraints and explicitly avoids the construction of a nominal controller, potentially improving performance and reducing the computational cost. However, an initial valid LF is needed for the synthesis procedure.
Notations: Let R, R n , R m×n and S n denote the sets of real numbers, n-dimensional real vectors, m by n real matrices, and n × n real symmetric matrices, respectively. Z n 1 denotes the integer set {1, 2, . . . , n}. R[x] denotes the set of polynomials with real coefficients, while S n [x] and R m×n [x] denote the sets of n×n real symmetric polynomial matrices and of m × n real matrices, respectively, whose entries are polynomials of x with real coefficients. Finally, we let [x] denote the set of SOS polynomials of x.

II. PRELIMINARIES AND PROBLEM SETTING
Consider a nonlinear control-affine systeṁ where x(t) ∈ R n , u(t) ∈ R m , f : R n → R n and B : R n → R m are polynomial and locally Lipschitz continuous functions. The system (1) needs to satisfy state constraints given by for all t ≥ 0, where c i : R n → R is a polynomial function, and X is a compact set. Additionally, (1) is subject to input constraints of the form for all t ≥ 0, where D j ∈ R 1×m . Without loss of generality, we assume the interior of X contains the origin. If this assumption does not hold, one can possibly shift the system so that X defined using the shifted states contains the origin. Definition 1 (CBF [1]): A continuously differentiable function h : R n → R is a CBF for the system (1), if there exists an extended class K function α(·) such that for all x ∈ X , there exists a u ∈ R m satisfyinġ where . As noted in [1], h(x) being a CBF ensures the set is forward invariant: if x(0) ∈ X h , then there exists a control law u(t) ∈ U such that for all t ≥ 0, x(t) ∈ X h . Definition 1 allows us to consider all control signals for each x ∈ X and t ≥ 0 that render X h forward invariant: is a column vector whose entries are all monomials in x with degree up to d [6]. An SOS decomposition for a given l(x) can be computed using semidefinite programming (SDP) (by searching for a PSD matrix Q). When a polynomial l(x) is not exactly determined, but its coefficients are affinely parameterized in terms of some unknowns, the search for these unknowns which render l(x) an SOS can still be performed via SDP [7].

III. SOS OPTIMIZATION-BASED SYNTHESIS OF CBFS UNDER INPUT CONSTRAINTS
In this section, we first present an approach to synthesizing CBFs under input constraints using state-dependent linear-like forms and SOS optimization. We then introduce an iterative algorithm involving SOS optimization to further improve the CBFs from the initial design.

A. Initial CBF Synthesis Using Linear-Like Forms
Inspired by [7], [11], we make the following assumptions. Assumption 1: The nonlinear system (1) has a a statedependent linear-like representation [7]: where for some positive definite matrix P 0 , such that X ⊆X . Remark 1: Assumption 1 is not very restrictive as it can always be satisfied when f (x) is a polynomial and does not contain any constant terms, i.e., monomials of zero degrees. If the original state constraint set (X ) is compact, we can always find a setX (which will be an ellipsoid when z(x) = x) that is sufficiently large such that Assumption 2 holds. With z(x) in (7), we can introduce an inner approximation of X as where C i : R n → R 1×N is a vector-valued polynomial function. An illustration of different sets is given in Fig. 1.
Similarly, we introduce an inner approximation of U as Remark 2: Definition (9) captures a wide range of commonly seen geometric sets. For instance, the constraint |x i | ≤ a i (a i > 0) for defining a hypercube can be represented as | ≤ 1 with 1 i being a vector of appropriate dimension with all zero elements except the ith one equal to 1. An ellipsoid constraint x T Px ≤ 1 can be represented as In addition, we define M(x) to be an N × n polynomial matrix whose (i, j)-th entry is given by . . , j m } denote the row indices of B(x) whose corresponding row is equal to zero, and definex which includes all the states whose derivatives are not directly affected by control inputs.
The result is summarized in the following theorem. Theorem 1: Consider the system (7) subject to the input constraint (3) and state constraint (2). Suppose Assumption 2 hold, and the following optimization problem is feasible: where v ∈ R N and w ∈ R are introduced to convert a matrixvalued polynomial to a scalar polynomial so that an SOS constraint can be formulated, and we have omitted the dependence of most variables on x for brevity. Then, the following statements hold: (a) The function is a CBF for (7) according to Definition 1. Moreover, (4) is satisfied for all x ∈ X with a control signal from satisfying (4) for all x ∈ X . Moreover, X h ⊆ X , where X and X h are defined in (2), and (5), respectively.
Before proceeding to the proof, we first explain the purpose of constraints imposed in (10). Condition (11) ensuresḣ(x) ≥ 0 for any x ∈X with the control law (18), while (12), and (13) ensure X(x) ≥ X 0 and P 0 ≥ X(x), respectively, for any x ∈X . Condition (14) ensures C i (x)z(x) ≤ 1, i.e., the ith condition in definingX in (9) is satisfied, for any x ∈X , while (15) ensures D j u ≤ 1, i.e., the ith input constraint condition is satisfied, for any x ∈X with the control law (18).
Remark 3: Similar to [7], the matrix X depends only onx. If X depends on all the states, when computing dX −1 (x) dt to calculateḣ as in (22), we have ∂x j (A j z) currently used in (22). As a result, we could not obtain a convex SOS condition similar to (11) anymore.
Remark 4: Recall that the volume of a generalized ellipsoid E = {v| Qv ≤ 1} is proportional to det(Q −1 ) [20,Sec. 8.4]. We can think of the set X h with h(x) defined in (17) as an ellipsoid (although it is not unless X(x) is constant and z(x) = x). Therefore, maximizing log det X 0 in (10) is a proxy mechanism for maximizing the volume of X h .
Proof [Proof of (a)]: According to Proposition 2, (12) implies X(x) ≥ X 0 > 0, for all x ∈X . Also, (13) implies P 0 ≥ X(x) for all x ∈X , which further implies Therefore, we have X h ⊆X with the definitions ofX and X h in (8) and (5), respectively. On the other hand, for any x ∈ X h with h(x) given by (17) According to Proposition 2, (11) implies Under the dynamics (7) and the control law (18), the definition in (17) implieṡ Authorized licensed use limited to the terms of the applicable license agreement with IEEE. Restrictions apply.
for all x ∈X , where we have leveraged the fact thatż( Lemma 5] in deriving (23), and (24) is due to (21). As a result, condition (4) can always be satisfied for any x ∈X under the control law u(x) defined by (18). Therefore, h(x) is a valid CBF.
According to Proposition 2, (14) implies for all x ∈X , which, via Schur complement, further indicates X(x)C T i C i X(x) ≤ X(x) for all x ∈X . Multiplying the preceding inequality by z T (x)X −1 (x) and its transpose from the left and right, respectively, leads to |C i z(x)| 2 ≤ z T (x)X −1 (x)z(x), ∀x ∈X , ∀i ∈ Zp 1 , which, together with (20) and the fact that X h ⊆X , indicates |C i z(x)| ≤ 1 for all x ∈ X h and for all i ∈ Zp 1 . As a result, X h ⊆ X ⊆ X .
Proof of (b): According to Proposition 2, (15) implies for all x ∈X for all j ∈ Zq 1 . Multiplying the preceding inequality by z(x) and its transpose from the right and left, respectively, and considering the control law (18), we have |D j u| 2 ≤ z T (x)X −1 (x)z(x), which, together with (20), implies |D j u| ≤ 1 for all x ∈ X h for all j ∈ Zq 1 . As a result, the control law (18) satisfies u(x) ∈ U , for all x ∈ X h . If x(0) ∈ X h , by contradiction, it is easy to show that u(x(t)) ∈ U , h(x(t)) ≥ 0, and x(t) ∈ X h for all t ≥ 0. The proof is complete.
Problem (10) is a convex optimization problem, as the cost function to be maximized is concave, and all the constraints are SOS constraints with affine dependence on decision variables.
Remark 5: To reduce the conservatism of problem (10), a number of workarounds may be considered. First, one can replace h 0 (x) in any of (11)-(15) with −c i (x) (i ∈ Z p 1 ) to ensure that corresponding conditions hold in X instead of X to reduce the conservatism. This procedure will lead to increased computational cost since a multiplier needs to be introduced for each −c i (x) with i ∈ Z p 1 . As an example, one can replace l 0 h 0 (x) in (11) with i∈Z p 1 Second, one could try to increase the complexity of polynomial decision variables such as X(x) and Y(x) by increasing the degrees and/or states that the variables depend on.

B. Refining CBFs via Iterative SOS Optimization
The use of the (potentially non-unique) linear-like form (7) in Section III-A, the constraintḣ(x) ≥ 0 through (11) (which is more restrictive than needed by Definition 1), and/or the innerapproximation of X and U adopted in Theorem 1 can lead to conservative results. To reduce the conservatism, motivated by [12], we now present an iterative procedure, summarized in Algorithm 1, to alternatively update h(x) and u(x), as well as associated multipliers.
Remark 6: Since Y(x) is a polynomial matrix and z(x) is a polynomial vector, h(x) and u(x) from solving problem (10) Algorithm 1 Iterative SOS Optimization for Refining a CBF Input: Initial CBF h(x) and controller u(x) with a polynomial form from solving problem (10), an extended class K function α(·), MaxIter and Tol Step 0: With h(x) fixed, solve max where the dependence of h on x is omitted. If (25) is feasible, set k = 1, select a N-dimensional column vector, y(x), whose entries are all monomials in x such that h(x) = y T (x)Q 0 y(x) for some symmetric matrix Q 0 , and go to Iterative Update; otherwise, go to Output. Iterative Update: where , set k ← k + 1 and go to Step 2; otherwise, go to Output. (c) The function h(x) output by Algorithm 1 is a valid CBF according to Definition 1. Besides, X h ⊆ X with X h defined in (5). Moreover, if x(0) ∈ X h , under the controller u(x), we have u(t) ∈ U and x(t) ∈ X for all t ≥ 0.
Proof [Proof of (a)]: Let us first consider the optimization problem (29) in Step 1 for k = 1. Select the monomials for l i x so that l i0 x from Step 0 can be fully represented by those monomials. Then, by comparing the constraints of the optimization problems (25) and (29) and considering the fact for any β ≥ 0, one can see that the constraints of (29) can be satisfied with l i x (x) = l i0 x (x), Q = Q 0 , and μ 0 set to be the smallest eigenvalue of Q. Similarly, the optimized variables u(x), l h (x) and l j u (x) (j ∈ Z q 1 ) from Step 0 and h(x) from Step 1, together with ε = 0, satisfy all the constraints of (34).
Next, consider the case of k ≥ 2. For Step 1, by comparing the constraints of problems (34), and (29), one can see that all the constraints of (29) can be satisfied with μ 0 , Q and Step 2, the constraints of (34) can be satisfied with u(x), l h (x) and l j u (x) (j ∈ Z q 1 ) from Step 2 at iteration k −1 and h(x) from Step 1 at iteration k, together with ε = 0.
Proof of (c): If (25) in Step 0 is infeasible, the h(x) output by Algorithm 1 is exactly the one obtained from solving (10). Under such a case, (c) is the same as statement (b) of Theorem 1 and thus holds according to Theorem 1. Otherwise, the functions h(x) and u(x), produced as outputs by Algorithm 1, should satisfy the constraints (30)-(32) in problem (29). Notice that (30) for all x ∈X . Therefore, h(x) is a valid CBF according to Definition 1. Moreover, (31) implies that for any i ∈ Z p 1 , for all x satisfying c i (x) ≥ 0, we have −h(x) ≥ 0, which further suggests that X h ⊆ X , where X is defined in (2). Furthermore, (32) indicates that for all x ∈ X h , D j u(x) ≤ 1, ∀j ∈ Z q 1 . Thus, for any x ∈ X h , following the control law u(x) will ensure that the input constraints (3) and the CBF condition (4) are satisfied simultaneously. It is straightforward to show that if x(0) ∈ X h , then u(x(t)) ∈ U , h(x(t)) ≥ −α(h(x(t))), and x(t) ∈ X h for all t ≥ 0. Therefore, (c) is proved.
Remark 9: If we only consider that x(0) is in the CBFdefined set, we can replace h 0 (x) in (26), and (30) with h(x) so that CBF condition (4) only needs to hold in X h instead of X . This can possibly further improve the volume of X h .
From the proof of Theorem 1, we notice that h(x) and u(x) from solving (10) satisfẏ with X h ⊆ X . On the other hand, the constraints (26)-(28) of problem (25) in Step 0 aim to ensurė for some constant ε ≥ 0. By comparing the constraints (36) and (37) we conjecture that h(x) and u(x) from solving (10) have a high chance to satisfy (37).
Instead of using the controller u(x) output by Algorithm 1, we can alternatively compute the min-norm control signal at each time instant by solving a QP problem [1]: From the analysis in Theorem 2, we know that the optimization problem is always feasible as long as x(0) ∈ X h .

IV. SIMULATION RESULTS
We now test the proposed approach on two numerical examples. We used MATLAB with YALMIP [21] and Mosek [22] to solve all the optimization problems. All codes are available at https://github.com/boranzhao/cbf-sos.
Example 1: Consider a system with an unstable equilibrium at the origin: x 2 ] T ∈ R 2 and u ∈ R are the state and control vectors of the system. The state constraints are given by x ∈ X = {x|x 2 1 ≤ 1, x 2 2 ≤ 1}, illustrated by the red boxes in Fig. 2. The control input is constrained by |u| ≤ 1.
For applying Theorem 1 for initial CBF design, we tested both z(x) = x and z(x) = [x 1 x 2 x 3 2 ] T for obtaining the linearlike dynamics (7), and the degrees of X and Y to be 0 and 2, respectively, for both cases. Additionally, we selected P 0 (used in defining h 0 (x) via (8)) to be 2 and 3, respectively, for z(x) = x and z(x) = [x 1 x 2 x 3 2 ] T , to get the smallestX such that X ⊆X . To reduce the conservatism, we replaced the term dependent on h 0 (x) in each of (11)-(15) with a term dependent on c i (x) so that the corresponding condition holds in X instead ofX , as explained in Remark 5. For comparisons, we also included the CBFs obtained usingX . For refining the CBF via Algorithm 1, we chose the degrees of y(x) and u(x) to be 1 and 3, respectively, for z(x) = x, while they were selected to be 3 and 5, respectively, for z(x) = [x 1 x 2 x 3 2 ] T . The initial and refined CBFs obtained are depicted in Fig. 2. One can see that different linear-like representations led to different results.  Moreover, z(x) of a higher dimension tends to yield CBFs with larger invariant sets at the price of increased computational cost. Figure 2 also depicts state and input trajectories given an initial state. As expected, the states remained in X h and the input constraints were satisfied. Example 2: Consider a system borrowed from [12], where x = [x 1 , x 2 , x 3 ] T ∈ R 3 and u = [u 1 , u 2 ] T ∈ R 2 are the state and control vectors of the system. The unsafe regions are characterized by four spheres defined by q i (x) < 0 (i = 1, 2, 3, 4), where the expression of the polynomial function q i (x) is given in [12]. The safe region is therefore characterized by X = {x ∈ R 3 |c i (x) ≤ 0, i = 1, 2, 3, 4}, where c i (x) = −q i (x), i = 1, 2, 3, 4. The control inputs are constrained by |u i | ≤ 1 for i = 1, 2. For applying Theorem 1 for an initial CBF, we selected z(x) = x, and the degrees of X and Y to be 0 and 2, respectively. Additionally, we selected P 0 (used in defining h 0 (x) via (8)) to be 10. For the redesign via Algorithm 1, we chose the degrees of y(x) of u(x) to be 2 and 4, respectively. The initial and refined CBFs in the absence and presence of input constraints are depicted in Fig. 3.
To verify if the function h(x) from Algorithm 1 is indeed an CBF, we simulated the system under a few initial states in X h , and the min-norm control law in (38). As shown in Fig. 4, for all the tested initial states, the system states stayed in X h , and the control limits were respected.

V. CONCLUSION
This letter presents an SOS optimization-based method to synthesize CBFs for nonlinear polynomial systems with input constraints. The method consists of an initial design step that jointly searches for an initial CBF and a control law through SOS optimization based on a linear-like representation of the nonlinear dynamics, and an iterative redesign step that refines the initial CBF by alternatively updating it and the control law through SOS optimization. Numerical examples validate the effectiveness of the proposed approach.
Our future work includes extending the proposed method to synthesize CBFs under model uncertainties.