Robot makes a strange movement after turning

Hello.

Currently, I am programming an inertial program, where I use a PD turn algorithm and a time-based velocity driving algorithm.

However, the problem, when I run the code below, after the turn of 90 degrees, it decides to mess it up and turn 5 degrees wherever and then start moving.

I have tested the turn algorithm without any drive forward after. It doesn’t make that kind of movement. But when added back, it does it again.

I have also placed a wait block next to it. No results either.

Here is my turning code:


I have no idea what to do next. Please help.

2 Likes

The code all looks fine to me. The only thing code-wise I can think of that could cause a problem is that you don’t stop the motors at the end of the turn PID. Other then that, it could be a build problem causing one side of your drivetrain to start a little slower then the other side on the drive.