Generalized canonical systems with first integrals