Do the DC Motors get Powers or are the driver shields broken ? Is the sonar reading correctly? Maybe do some Serial.println statements in front of the condition to be at least sure the Sensor is reading correct values and then put some Serial.println in the functions that are supposed to be called so you can see if the function actually gets called and it's just a hardware error or if something is the wrong software wise