Optimal gaits generation of a 4-legged walking robot