Trajectory tracking control of Hamiltonian and hybrid control systems