Find out whether the bot is rotating left or right

The most logical thing to do is to set the flag at the moment when you directly rotate the bot. If this is not possible, then you need to compare the bot’s rotation from the previous frame with the current one, and accordingly, if the angle is greater/less, then the rotation will be left/right (or vice versa).