Sterotypy [ster-ee-uh-tahy-pee] is the formal word for it. Repetitive motion to offset anxiety from sensory overstimulation.
Quote:
..repetitive or ritualistic movement, posture, or utterance. Stereotypies may be simple movements such as body rocking, or complex, such as self-caressing, crossing and uncrossing of legs, and marching in place...stereotypy discharges tension or expresses frustration