  This letter addresses the constraint compatibility problem of control barrier
functions (CBFs), which occurs when a safety-critical CBF requires a system to
apply more control effort than it is capable of generating. This inevitably
leads to a safety violation, which transitions the system to an unsafe (and
possibly dangerous) trajectory. We resolve the constraint compatibility problem
by constructing a control barrier function that maximizes the feasible action
space for first and second-order constraints, and we prove that the optimal CBF
encodes a dynamical motion primitive. Furthermore, we show that this dynamical
motion primitive contains an implicit model for the future trajectory for
time-varying components of the system. We validate our optimal CBF in
simulation, and compare its behavior with a linear CBF.
