Obstacle Avoidance Robot Code

Firstly the ultrasonic sensor is not detecting any obstacles

How do you know? The statement to print the measured distance is commented out.

Secondly the Gear Motor does not function properly but stops randomly for a prolonged period of time without any scope.

What does "without any scope" mean?