Gait optimization for multi-legged walking robots, with application to a lunar hexapod