Controlling and learning motor functions