Robot will come exactly to the center of the line?

The expert, referring to the zumo-32u4-arduino-library provided a sample code on GitHub. In this code,

Link

I am referring to line number 152 and below. According to this code, when turning right, the robot rotates 45 degrees using the gyroscope, and the remaining 45 degrees are rotated using the motor speed set for turnsSpeed, and remenig degrees rotate until aboveline the code at line 172. Could you please explain how certain it is that, using this method, the middle sensor of the robot will come exactly to the center of the line?"

Thanks

Hello.

The Zumo 32U4 uses 5 line sensors; the outer 2 (sensors 0 and 4) are much wider than the middle 3 (sensors 1, 2, and 3). The way that code works is that it turns until the sensor specified by the sensorIndex variable sees the line. The sensorIndexvariable is different depending on if the robot is turning left or right, but in either case it is set to the first of the 3 “middle sensors” that will encounter the line (e.g. sensor 1 or 3, not the middle sensor, which is sensor 2). At that point, it switches back to the normal line following algorithm, which finishes centering the robot on the line using the PID controller.

Brandon