API Reference
CBF Classes
- class cbfpy.cbf.CBFBase[source]
Bases:
objectCBF base class
- The CBF optimization problem is formulated as:
minimize_{u} {objective function} subject to G*u + alpha(h) >= 0
- G
constraint matrix (=dh/dx)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.CircleCBF(center: ndarray[tuple[int, ...], dtype[_ScalarType_co]], radius: float, keep_inside: bool = True)[source]
Bases:
CBFBaseCBF for circular area constraint.
- center
center of circular area in world coordinate. shape=(2,)
- radius
radius of the circular area
- keep_inside
flag to prohibit going outside of the area
- G
constraint matrix (=dh/dx). shape=(2,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.GeneralCBF(G: ndarray[tuple[int, ...], dtype[_ScalarType_co]], h: float)[source]
Bases:
CBFBaseGeneral-purpose CBF with manually specified constraints.
- G
constraint matrix (=dh/dx). shape=(N,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.LiDARCBF(width: ndarray[tuple[int, ...], dtype[_ScalarType_co]], keep_upper: bool = True)[source]
Bases:
CBFBaseCBF for LiDAR-based obstacle avoidance.
- width
half length of the major and minor axis of ellipse that match the x and y axis in the agent coordinate. shape=(2,)
- keep_upper
flag to prohibit going lower of the limit
- G
constraint matrix (=dh/dx). shape=(2,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.Pnorm2dCBF(center: ndarray[tuple[int, ...], dtype[_ScalarType_co]], width: ndarray[tuple[int, ...], dtype[_ScalarType_co]], theta: float = 0.0, p: float = 2.0, keep_inside: bool = True)[source]
Bases:
CBFBaseCBF for p-norm shaped area constraint.
- center
center of area in world coordinate. shape=(2,)
- width
half length of the major and minor axis of ellipse that match the x and y axis in the area coordinate. shape=(2,)
- theta
rotation angle (rad) from world to area coordinate
- p
multiplier for p-norm
- keep_inside
flag to prohibit going outside of the area
- G
constraint matrix (=dh/dx). shape=(2,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.ScalarCBF(limit: float, keep_upper: bool = True)[source]
Bases:
CBFBaseCBF for scalar state variable.
If keep_upper is True, the safety set is x - limit >= 0.
- limit
limit for scalar state variable
- keep_upper
flag to prohibit going lower of the limit
- G
constraint matrix (=dh/dx). shape=(1,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.ScalarRangeCBF(a: float, b: float, keep_inside: bool = True)[source]
Bases:
CBFBaseCBF for scalar state variable with range constraint.
If keep_inside is True, the safety set is a <= x <= b.
- a
lower limit for scalar state variable
- b
upper limit for scalar state variable
- keep_inside
flag to prohibit going outside of the range
- G
constraint matrix (=dh/dx). shape=(1,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.UnicycleCircleCBF(center: ndarray[tuple[int, ...], dtype[_ScalarType_co]], radius: float, keep_inside: bool = True)[source]
Bases:
CircleCBFCBF for circular area constraint with unicycle model.
- center
center of circular area in world coordinate. shape=(2,)
- radius
radius of the circular area
- keep_inside
flag to prohibit going outside of the area
- G
constraint matrix (=dh/dx). shape=(2,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
- class cbfpy.cbf.UnicyclePnorm2dCBF(center: ndarray[tuple[int, ...], dtype[_ScalarType_co]], width: ndarray[tuple[int, ...], dtype[_ScalarType_co]], theta: float = 0.0, p: float = 2.0, keep_inside: bool = True)[source]
Bases:
Pnorm2dCBFCBF for p-norm shaped area constraint with unicycle model.
- center
center of area in world coordinate. shape=(2,)
- width
half length of the major and minor axis of ellipse that match the x and y axis in the area coordinate. shape=(2,)
- theta
rotation angle (rad) from world to area coordinate
- p
multiplier for p-norm
- keep_inside
flag to prohibit going outside of the area
- G
constraint matrix (=dh/dx). shape=(2,)
- Type:
numpy.ndarray[tuple[int, …], numpy.dtype[numpy._typing._array_like._ScalarType_co]]
- h
constraint value (=h(x))
- Type:
float
QP Solvers
- class cbfpy.cbf_qp_solver.CBFNomQPSolver[source]
Bases:
objectCBF-QP solver that tracks a nominal input.
- optimize(nominal_input: ndarray[tuple[int, ...], dtype[_ScalarType_co]], P: ndarray[tuple[int, ...], dtype[_ScalarType_co]], G_list: Sequence[ndarray[tuple[int, ...], dtype[_ScalarType_co]]], alpha_h_list: list[float]) tuple[str, ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]
Solve the CBF-QP optimization problem with nominal input tracking.
minimize_{u} (1/2) * (u-nominal_input)^T*P*(u-nominal_input) subject to G*u + alpha(h) >= 0
- Parameters:
nominal_input – nominal input. shape=(N,)
P – optimization weight matrix. shape=(N, N)
G_list – constraint matrix list. [(N,), (N,), …]
alpha_h_list – constraint value list
- Returns:
“optimal” on success optimal_input: optimal input. shape=(N,)
- Return type:
status
- class cbfpy.cbf_qp_solver.CBFQPSolver[source]
Bases:
objectCBF-QP solver for general quadratic cost.
- optimize(P: ndarray[tuple[int, ...], dtype[_ScalarType_co]], q: ndarray[tuple[int, ...], dtype[_ScalarType_co]], G_list: Sequence[ndarray[tuple[int, ...], dtype[_ScalarType_co]]], alpha_h_list: list[float]) tuple[str, ndarray[tuple[int, ...], dtype[_ScalarType_co]]][source]
Solve the CBF-QP optimization problem.
minimize_{u} (1/2) * u^T*P*u + q^T*u subject to G*u <= alpha(h)
- Parameters:
P – optimization weight matrix. shape=(N, N)
q – optimization weight vector. shape=(N,) or (N, 1)
G_list – constraint matrix list. [(N,), (N,), …]
alpha_h_list – constraint value list
- Returns:
“optimal” on success optimal_input: optimal input. shape=(N,)
- Return type:
status