First impression based on the description is that the motors disrupt the power supply for the sonars. Have you monitored the sonar supply while activating the motors to see? Can you post a schematic of your project? Include all components and power supplies.
You did not post all of your sketch. Where are the functions that read the sonars?