We derive an optimal control formulation for a nonholonomic mechanical system using the nonholonomic constraint itself as the control. We focus on Suslovs problem, which is defined as the motion of a rigid body with a vanishing projection of the body frame angular velocity on a given direction $boldsymbol{xi}$. We derive the optimal control formulation, first for an arbitrary group, and then in the classical realization of Suslovs problem for the rotation group $SO(3)$. We show that it is possible to control the system using the constraint $boldsymbol{xi}(t)$ and demonstrate numerical examples in which the system tracks quite complex trajectories such as a spiral.