What pins is the motor shield using? Putting the Ping sensors on PWM pins doesn't make a lot of sense.
#define TRIGGER_PIN2 9
servo1.attach(9); // attaches the servo on pin 9 to the servo object
That doesn't look good.
for(pos = 45; pos < 135; pos += 1) // Servo goes from 45 degrees to 135 degrees in 1* steps
{
servo1.write(pos);
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 135; pos>=46; pos-=1) // Servo goes from 135 degrees to 46 degrees
{
servo1.write(pos);
servo2.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
Regardless of what you read from the sensors? Why?
What are these servos doing? servo1 and servo2 don't tell us squat.
int dist_R = sonar1.ping_cm(); //Ping the Right sensor
int dist_L = sonar2.ping_cm(); //Ping the Left sensor
Serial.print("Ping1: ");
Serial.print(dist_R);
Serial.println("cm 1");
Serial.print("Ping2: "); // These lines print ping results to serial monitor
Serial.print(dist_L);
Serial.println("cm 2");
What values are you seeing?