Application of Hamiltonian dynamics to manipulator control in constrained workspace