Zumo obstacle avoidance

I am building an obstacle avoidance robot but I have come across some issues. Im having issues combining the zumo chasis and working code to get distance and pan the servo. For some reason my loop gets stuck and it doesnt do what I thought it would do. Im working of the line follow code for error analysis and motor control. This is the obstacle avoidance code that Im trying to get to work. pastebin.com/xb3AFyZ7 which Im trying to combine with the Zumo. I am using the distance to lower the speed of the opposite motor to turn away from an obstacle.

The issue is that the servo pans once from right to left and then stops. The wheels keep turning and dont change as they should. I would have thought it would continue to pan back and forth providing the reading to feed into the controls. I dont really understand why it stops panning when its in the loop and why the wheels dont change their speeds. I have been going at this for about 2 nights now and its really bugging me.

Unfortunately you cannot use The Servo library with the Zumo Motors lib. Both use Timer1 for PWM control.

Instead use the servo code given by Pololu’s manual for Zumo: https://www.pololu.com/docs/0J57/8