Mean motions and almost periodic functions