Motion planning for legged locomotion systems on uneven terrain