CLF-CBF
Control Lyapunov Function / Control Barrier Functions (CLF-CBFs)
Whereas a CBF acts as a safety filter on top of a nominal controller, a CLF-CBF acts as a safe controller itself, based on a control objective defined by the CLF and a safety constraint defined by the CBF. Note that the CLF objective should be quadratic and positive-definite to fit in this QP framework.
The CLF-CBF optimizes the following:
minimize ||u||_{2}^{2} # CLF Objective (Example)
subject to LfV(z) + LgV(z)u <= -gamma(V(z)) # CLF Constraint
Lfh(z) + Lgh(z)u >= -alpha(h(z)) # CBF Constraint
As with the CBF, if this is a relative-degree-2 system, we update the constraints:
minimize ||u||_{2}^{2} # CLF Objective (Example)
subject to LfV_2(z) + LgV_2(z)u <= -gamma_2(V_2(z)) # RD2 CLF Constraint
Lfh_2(z) + Lgh_2(z)u >= -alpha_2(h_2(z)) # RD2 CBF Constraint
If there are constraints on the control input, we also enforce another constraint:
u_min <= u <= u_max # Control constraint
However, in general the CLF constraint and the CBF constraint cannot be strictly enforced together. We then need to introduce a slack variable to relax the CLF constraint, ensuring that the CBF safety condition takes priority over the CLF objective.
The optimization problem then becomes:
minimize ||u||_{2}^{2} + p * delta^2 # CLF Objective (Example)
subject to LfV(z) + LgV(z)u <= -gamma(V(z)) + delta # CLF Constraint
Lfh(z) + Lgh(z)u >= -alpha(h(z)) # CBF Constraint
p
is a large constant and delta
is the slack variable.
CLFCBF
Control Lyapunov Function / Control Barrier Function (CLF-CBF) class.
The main constructor for this class is via the from_config
method, which constructs a CLF-CBF instance
based on the provided CLFCBFConfig configuration object.
You can then use the CLF-CBF's controller
method to compute the optimal control input
Examples:
# Construct a CLFCBFConfig for your problem
config = DroneConfig()
# Construct a CBF instance based on the config
clf_cbf = CLFCBF.from_config(config)
# Compute the safe control input
safe_control = clf_cbf.controller(current_state, desired_state)
Source code in cbfpy/cbfs/clf_cbf.py
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 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
from_config(config)
classmethod
Construct a CLF-CBF based on the provided configuration
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
CLFCBFConfig
|
Config object for the CLF-CBF. Contains info on the system dynamics, barrier function, Lyapunov function, etc. |
required |
Returns:
Name | Type | Description |
---|---|---|
CLFCBF |
CLFCBF
|
Control Lyapunov Function / Control Barrier Function instance |
Source code in cbfpy/cbfs/clf_cbf.py
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 |
|
controller(z, z_des, *h_args)
Compute the CLF-CBF optimal control input, optimizing for the CLF objective while satisfying the CBF safety constraint.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Safe control input, shape (m,) |
Source code in cbfpy/cbfs/clf_cbf.py
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 |
|
h(z, *h_args)
Barrier function(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Barrier function evaluation, shape (num_barr,) |
Source code in cbfpy/cbfs/clf_cbf.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
h_and_Lfh(z, *h_args)
Lie derivative of the barrier function(s) wrt the autonomous dynamics f(z)
The evaluation of the barrier function is also returned "for free", a byproduct of the jacobian-vector-product
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
h |
Array
|
Barrier function evaluation, shape (num_barr,) |
Lfh |
Array
|
Lie derivative of |
Source code in cbfpy/cbfs/clf_cbf.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
Lgh(z, *h_args)
Lie derivative of the barrier function(s) wrt the control dynamics g(z)u
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Lgh, shape (num_barr, m) |
Source code in cbfpy/cbfs/clf_cbf.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
V(z)
Control Lyapunov Function(s)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
CLF evaluation, shape (num_clf,) |
Source code in cbfpy/cbfs/clf_cbf.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
V_and_LfV(z)
Lie derivative of the CLF wrt the autonomous dynamics f(z)
The evaluation of the CLF is also returned "for free", a byproduct of the jacobian-vector-product
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
Returns:
Name | Type | Description |
---|---|---|
V |
Array
|
CLF evaluation, shape (1,) |
LfV |
Array
|
Lie derivative of |
Source code in cbfpy/cbfs/clf_cbf.py
320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
LgV(z)
Lie derivative of the CLF wrt the control dynamics g(z)u
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
ArrayLike
|
State, shape (n,) |
required |
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
LgV, shape (m,) |
Source code in cbfpy/cbfs/clf_cbf.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
P_qp(z, z_des, *h_args)
Quadratic term in the QP objective (minimize 0.5 * x^T P x + q^T x
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
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/cbfs/clf_cbf.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
|
q_qp(z, z_des, *h_args)
Linear term in the QP objective (minimize 0.5 * x^T P x + q^T x
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
Q vector, shape (m,) |
Source code in cbfpy/cbfs/clf_cbf.py
371 372 373 374 375 376 377 378 379 380 381 382 |
|
G_qp(z, z_des, *h_args)
Inequality constraint matrix for the QP (Gx <= h
)
Note
The number of constraints depends on if we have control constraints or not.
Without control constraints, num_constraints == num_barriers
.
With control constraints, num_constraints == num_barriers + 2*m
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
G matrix, shape (num_constraints, m) |
Source code in cbfpy/cbfs/clf_cbf.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
h_qp(z, z_des, *h_args)
Upper bound on constraints for the QP (Gx <= h
)
Note
The number of constraints depends on if we have control constraints or not.
Without control constraints, num_constraints == num_barriers
.
With control constraints, num_constraints == num_barriers + 2*m
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
Array |
Array
|
h vector, shape (num_constraints,) |
Source code in cbfpy/cbfs/clf_cbf.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
|
qp_data(z, z_des, *h_args)
Constructs the QP matrices based on the current state and desired control
i.e. the matrices/vectors (P, q, A, b, G, h) for the optimization problem:
minimize 0.5 * x^T P x + q^T x
subject to A x == b
G x <= h
Note
- CBFs do not rely on equality constraints, so
A
andb
are empty. - The number of constraints depends on if we have control constraints or not.
Without control constraints,
num_constraints == num_barriers
. With control constraints,num_constraints == num_barriers + 2*m
Parameters:
Name | Type | Description | Default |
---|---|---|---|
z |
Array
|
State, shape (n,) |
required |
z_des |
Array
|
Desired state, shape (n,) |
required |
*h_args |
Optional additional arguments for the barrier function. |
()
|
Returns:
Name | Type | Description |
---|---|---|
P |
Array
|
Quadratic term in the QP objective, shape (m + 1, m + 1) |
q |
Array
|
Linear term in the QP objective, shape (m + 1,) |
A |
Array
|
Equality constraint matrix, shape (0, m + 1) |
b |
Array
|
Equality constraint vector, shape (0,) |
G |
Array
|
Inequality constraint matrix, shape (num_constraints, m + 1) |
h |
Array
|
Upper bound on constraints, shape (num_constraints,) |
Source code in cbfpy/cbfs/clf_cbf.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|