Optimal control of constrained hybrid dynamical systems: Theory, computation and applications