Geodesics with constraints on Heisenberg manifolds