A modular robot has a distributed mechanical composition which can make various configurations and also make locomotion in a wide variety of configurations. Modular robots are thought to be useful in extreme or unknown environments by adaptively changing their shape and locomotion patterns. As for locomotion, two types can be used; one is whole-body fixed-configuration locomotion and the other is locomotion by self-reconfiguration. In this paper we deal with the former type of locomotion which is realized by coordinated joint actuation. So far, proposed control methods for whole-body locomotion by modular robots have been based on predefined locomotion sequences. However, locomotion based on predefined sequences cannot adapt to changing terrain conditions such as uphill, downhill, slippery and sticky grounds. To solve such problems, we propose a distributed control mechanism using a CPG controller which enables adaptive locomotion by modular robots. Besides the real-time CPG control we introduce a decentralized control mechanism for detecting the situation that the robot is stuck and initiating transformation to another shape for recovering the situation. The results of various hardware experiments by 4-Iegged structure prove the feasibility of the method for adaptive locomotion and transformation by our M-TRAN II modules.