The theory of canonical perturbations applied to attitude dynamics and to the Earth rotation. Osculating and nonosculating Andoyer variables