The averaging theory for computing periodic orbits