@daxster
If everything ok before and now it does not work.
As indicated by
@Matrix10 it looks like an engine problem.
Input if the motor has the option to send to 0, then make a reset to indicate that it is that point, then already calculates the position well.
Some engines do not have the option and reset when the power is turned on.
If the engine is not at 0, then all calculations of usals do them wrong.
Discuss the engine you have and review the manual to see this topic.
-------------
Si antes todo ok y ahora no funciona.
Como indica Matrix10 parece un problema del motor.
De entrada si el motor tiene la opcion de mandar a 0, luego hacer un reset para indicar que es ese punto, luego ya calcula bien la posicion.
Algunos motores no tienen la opcion y hacen un reset al conectar la alimentacion.
Si el motor no esta a 0, luego todos los calculos de usals los hace mal.
Comenta el motor que tienes y repasa el manual para ver este tema.