CBF Config
CBF Configuration class
Defining the problem:
CBFs have two primary implementation requirements: the dynamics functions, and the barrier function(s).
These can be specified through the f
, g
, and h
methods, respectively. Note that the main requirements
for these functions are that (1) the dynamics are control-affine, and (2) the barrier function(s) are "zeroing"
barriers, as opposed to "reciprocal" barriers. A zeroing barrier is one which is positive in the interior of the
safe set, and zero on the boundary.
Depending on the relative degree of your barrier function(s), you should implement the h_1
method
(for a relative-degree-1 barrier), and/or the h_2
method (for a relative-degree-2 barrier).
Tuning the CBF:
The CBF config provides a default implementation of the CBF "gain" function alpha
, and alpha_2
for
relative-degree-2 barriers. To change the sensitivity of the CBF, these functions can be modified to
increase or decrease the effect of the barrier(s). For instance, alpha(h) = h
is the default implementation,
but to increase the sensitivity of the CBF, one could use alpha(h) = 2 * h
. The only requirements for these
functions are that they are monotonically increasing and pass through the origin (class Kappa functions).
The CBFConfig also provides a default implementation of the CBF QP objective function, which is to minimize
the norm of the difference between the safe control input and the desired control input. This can also be modified
through the P
and q
methods, which define the quadratic and linear terms in the QP objective, respectively. This
does require that P is positive semi-definite.
Relaxation:
Depending on the construction of the barrier functions and if control limits are provided, the CBF QP may not always be feasible. If allowing for relaxation in the CBFConfig, a slack variable will be introduced to ensure that the problem is always feasible, with a high penalty on any infeasibility. This is generally useful for controller robustness, but means that safety is not guaranteed.
If strict enforcement of the CBF is desired, your higest-level controller should handle the case where the QP is infeasible.
CBFConfig
Bases: ABC
Control Barrier Function (CBF) configuration class.
This is an abstract class which requires implementation of the following methods:
f(z)
: The uncontrolled dynamics functiong(z)
: The control affine dynamics functionh_1(z)
and/orh_2(z)
: The barrier function(s), of relative degree 1 and/or 2
For finer-grained control over the CBF, the following methods may be updated from their defaults:
alpha(h)
: "Gain" of the CBFalpha_2(h_2)
: "Gain" of the relative-degree-2 CBFs, if applicableP(z, u_des)
: Quadratic term in the CBF QP objectiveq(z, u_des)
: Linear term in the CBF QP objective
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n |
int
|
State dimension |
required |
m |
int
|
Control dimension |
required |
u_min |
ArrayLike
|
Minimum control input, shape (m,). Defaults to None (Unconstrained). |
None
|
u_max |
ArrayLike
|
Maximum control input, shape (m,). Defaults to None (Unconstrained). |
None
|
relax_cbf |
bool
|
Whether to allow for relaxation in the CBF QP. Defaults to True. |
True
|
cbf_relaxation_penalty |
float
|
Penalty on the slack variable in the relaxed CBF QP. Defaults to 1e3. Note: only applies if relax_cbf is True. |
1000.0
|
solver_tol |
float
|
Tolerance for the QP solver. Defaults to 1e-3. |
0.001
|
init_args |
tuple
|
If your barrier function relies on additional arguments other than just the state, include an initial seed for these arguments here. This is to help test the output of the barrier function. Defaults to (). |
()
|
Source code in cbfpy/config/cbf_config.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 |
|
f(z)
abstractmethod
The uncontrolled dynamics function. Possibly nonlinear, and locally Lipschitz
i.e. the function f, such that z_dot = f(z) + g(z) u
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
The state, shape (n,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Uncontrolled state derivative component, shape (n,) |
Source code in cbfpy/config/cbf_config.py
202 203 204 205 206 207 208 209 210 211 212 213 214 |
|
g(z)
abstractmethod
The control affine dynamics function. Locally Lipschitz.
i.e. the function g, such that z_dot = f(z) + g(z) u
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
The state, shape (n,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Control matrix, shape (n, m) |
Source code in cbfpy/config/cbf_config.py
216 217 218 219 220 221 222 223 224 225 226 227 228 |
|
h_1(z, *h_args)
Relative-degree-1 barrier function(s).
A (zeroing) CBF is a continuously-differentiable function h, such that for any state z in the interior of the safe set, h(z) should be > 0, and h(z) = 0 on the boundary. When in the unsafe set, h(z) < 0.
Relative degree can generally be thought of as the number of integrations required between the input and output of the system. For instance, a (relative-degree-1) CBF based on velocities, with acceleration inputs, will be directly modified on the next timestep.
If your barrier function is relative-degree-2, or if you would like to enforce additional barriers
which are relative-degree-2, use the h_2
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. Note: If using additional args with your barrier, these must be a static shape/type, or else this will trigger a recompilation in Jax. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Barrier function(s), shape (num_rd1_barr,) |
Source code in cbfpy/config/cbf_config.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
|
h_2(z, *h_args)
Relative-degree-2 (high-order) barrier function(s).
A (zeroing) CBF is a continuously-differentiable function h, such that for any state z in the interior of the safe set, h(z) should be > 0, and h(z) = 0 on the boundary. When in the unsafe set, h(z) < 0.
Relative degree can generally be thought of as the number of integrations required between the input and output of the system. For instance, a (relative-degree-2) CBF based on position, with acceleration inputs, will be modified in two timesteps: the acceleration changes the velocity, which then changes the position.
If your barrier function is relative-degree-1, or if you would like to enforce additional barriers
which are relative-degree-1, use the h_1
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. Note: If using additional args with your barrier, these must be a static shape/type, or else this will trigger a recompilation in Jax. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Barrier function(s), shape (num_rd2_barr,) |
Source code in cbfpy/config/cbf_config.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
alpha(h)
A class Kappa function, dictating the "gain" of the barrier function(s)
For reference, a class Kappa function is a monotonically increasing function which passes through the origin. A simple example is alpha(h) = h
The default implementation can be overridden for more fine-grained control over the CBF
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h |
ArrayLike
|
Evaluation of the barrier function(s) at the current state, shape (num_cbf,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
alpha(h(z)), shape (num_cbf,) |
Source code in cbfpy/config/cbf_config.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
alpha_2(h_2)
A second class Kappa function which dictactes the "gain" associated with the relative-degree-2 barrier functions
For reference, a class Kappa function is a monotonically increasing function which passes through the origin. A simple example is alpha_2(h_2) = h_2
The default implementation can be overridden for more fine-grained control over the CBF
Parameters:
Name | Type | Description | Default |
---|---|---|---|
h_2 |
ArrayLike
|
Evaluation of the RD2 barrier function(s) at the current state, shape (num_rd2_cbf,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
alpha_2(h_2(z)), shape (num_rd2_cbf,). |
Source code in cbfpy/config/cbf_config.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
P(z, u_des, *h_args)
Quadratic term in the CBF QP objective (minimize 0.5 * x^T P x + q^T x)
This defaults to 2 * I, which is the value of P when minimizing the standard CBF objective, ||u - u_des||_{2}^{2}
To change the objective, override this method. Note that P must be PSD
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
u_des |
Array
|
Desired control input, shape (m,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
P matrix, shape (m, m) |
Source code in cbfpy/config/cbf_config.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
q(z, u_des, *h_args)
Linear term in the CBF QP objective (minimize 0.5 * x^T P x + q^T x)
This defaults to -2 * u_des, which is the value of q when minimizing the standard CBF objective, ||u - u_des||_{2}^{2}
To change the objective, override this method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
u_des |
Array
|
Desired control input, shape (m,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
q vector, shape (m,) |
Source code in cbfpy/config/cbf_config.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|