An Analytical Dynamics Approach to the Control of Mechanical Systems