Gravar-mail: Learning to stop: a unifying principle for legged locomotion in varying environments