Undershooting of motor despite the same number of ticks

Hi , i am currently working with arduino uno, motor shield and two Dc motor with encoders (Quardracture encoder). My aim apart from making the motors travel straight is to cover accurate distance and rotation,(moving them is 10cm movement and turning 90 degree).

In the above code i am taking my faster(tick5) motor as the reference and adjusting the speed of the slower motor(tick13) using only P and I. through this code i am able to move the motors is a straight line, however i am having problem with accuracy.
As stated in the codes, through trail and error i figure out the no of encoder tick needed to reach 10cm and rotate 90 degree however it only works once after that it will undershoot (10 cm will be around 9 cm) and (90 degree will be 85). i tried printing the ticks and they are stopping at the desired ticks but somehow the distance is not the same.

Some things, i have tried. declaring “ticks5” and “ticks13” as global variable with volatile. Tried to diable and enable interrupt e.g

But I am still encountering the same problem. I also checked the program multiple times, and the logic seems to be okay. I am using software interrupt as the hardware interrupt pin on the arduino uno pin is not available.

I need urgent assistance on why the distance is undershooting despite getting the same number of ticks. I had been trying it for days and not able to resolve the issue.

Thank you!



Just for added clarification, when you say “it only works once”, are you saying that your motors traverse and rotate the correct distance and angle, respectively, in the first iteration of your program?

Can you provide more details about your application (e.g. drawing a square) and how you are taking the measurements for each iteration? Or, if possible, can you post a video showing the behavior? Also, can you post your entire code?

- Amanda