This article addresses the problem of how modular robotics systems, i.e. Systems composed of multiple modules that can be configured into different robotic structures, can learn to locomote. In particular, we tackle the problems of online learning, that is, learning while moving, and the problem of dealing with unknown arbitrary robotic structures. We propose a framework for learning locomotion controllers based on two components: a central pattern generator (cpg) and a gradient-free optimization algorithm referred to as powell's method. The cpg is implemented as a system of coupled nonlinear oscillators in our yamor modular robotic system, with one oscillator per module. The nonlinear oscillators are coupled together across modules using bluetooth communication to obtain specific gaits, i.e. Synchronized patterns of oscillations among modules. Online learning involves running the powell optimization algorithm in parallel with the cpg model, with the speed of locomotion being the criterion to be optimized. Interesting aspects of the optimization include the fact that it is carried out online, the robots do not require stopping or resetting and it is fast. We present results showing the interesting properties of this framework for a modular robotic system. In particular, our cpg model can readily be implemented in a distributed system, it is computationally cheap, it exhibits limit cycle behavior (temporary perturbations are rapidly forgotten), it produces smooth trajectories even when control parameters are abruptly changed and it is robust against imperfect communication among modules. We also present results of learning to move with three different robot structures. Interesting locomotion modes are obtained after running the optimization for less than 60 minutes.