gembaknb:
I am using encoder motors. The encoder ticks count and it stored in a variable.
So, I need to stop the motor after the encoder rotates 750 ticks.
But it stops by rotating more distance, like about 1050 ticks. How can I stop the motor steadily at the exact encoder count?
Make the motor drive proportional to the error. it will slow down earlier and if overshoots will move back
automatically. This is how servomotors work (well a very simple one). Its also known as a proportional
controller.
Here your error term would be (position-750), which has a sign - you thus need to be able to drive
the motor in either direction dependent on the error sign.
On Sept 2, Robin2 asked you about the data sheets on the motor controller. You never bothered to respond, so I guess you are driving the motors without a motor controller. How, exactly, are you powering the motors and controlling the power on and off?
gembaknb:
I am using encoder motors. The encoder ticks count and it stored in a variable.
So, I need to stop the motor after the encoder rotates 750 ticks.
But it stops by rotating more distance, like about 1050 ticks. How can I stop the motor steadily at the exact encoder count?
Can your sketch sense and count each tick as it happens?
Almost certainly the running sketch can time how long between ticks.
We set an unsigned long variable = micros(); and it has marked a time. On the next tick, micros() - marked time = elapsed time.
The less elapsed time per tick, the faster it turns. As the number of ticks approaches the 750 limit, slow the motor down. Maybe start slowing at 700 ticks. You want that last turn to take seconds, then on with the brakes!