Method for Training a Robot or the Like, and Device for Implementing Said Method