programming of 4wd robot using ping sensor

Looking at the AFMotor source and header file, it appears that pins 3, 4, 5, 6, 7, 8, 11, and 12 are used by the shield.

It appears that you are trying to use pin 8 for your sensor, too.