Modular robots are built of many basic robotic modules that can be connected into robots of various shapes. These robots are able to recover from a failure by ejecting and replacing damaged modules. Although this type of failure recovery is usually suggested in literature, it may be precluded due inability of the broken modules to cooperate or if no spare modules are available. In such a case, locomotion of a damaged robot should be adapted to allow the robot to reach a repair station or even to finish its task without the need to exchange the broken modules. In this paper, we investigate how to adapt motions of modular robots with respect to failures using the concept of motion planning with motion primitives. The ability of the proposed system to recover from failures is verified in a simulation and also in a HW experiment.