Hexapods are widely used in the field of rescue robots that transport in complex terrains which are difficult for traditional wheeled robots to traverse. Currently, the method for hexapod gait control is often PID, a classical method that is universally exploited in all control systems in general. However, the fine-tuning of PID’s hyper-parameters(i.e. kp, ki and kd) mainly rely on chances and the experience of tuners. Therefore, it is both urgent and critical to find an automatic way to get through the tuning process and return optimal results. Aiming at this, this paper puts forward a novel approach to adjust these parameters with genetic algorithm. It first builds a computational model of the hexapod, then the terrain, then designates the input, output and constants of the system, builds the PID closed loop, and finally tunes it using genetic algorithm. The approach described in the paper leads to optimal results in a reasonable amount of time. This makes having hexapods walk on uneven terrain with ease and automacy an alluring possibility.