if(sonar[SONAR_NUM].ping_cm() <= 57)
There is no sonar[SONAR_NUM]. There are only sonar[0] to sonar[SONAR_NUM - 1]