Moving object with distance

Hello everyone,
so i have this idea and i'm really stuck i need some help.
Ehm, let's take for a example an object attached to a motor.
To move this object forward i've to type with a keyboard: "15 cm forward" and the object should go forward for 15 cm and then stops.
To move the object backwards i've to type "15 cm backwards" and so on.
I just need a program like that or an example i'm kinda stuck and which sensor should i use? SR-05 is kinda big to get attached to the object is there any other solution?

Thanks in advance.

Attach the object to a linear actuator, controlled by a motor driver.

I'm sure you can find linear actuators that can given an absolute positioning, like servos. Makes it even easier. The first image of #1 looks like they may have this built in.

The second image looks like it's using stepper motors, and the number of steps taken tells you how much you moved (but not where you are! You have to zero the thing, normally using a limit switch, then count from there). Otherwise a DC motor with encoder, same idea: count encoder pulses to tell you how much you moved.