If you need extra help with the SONAR range finder you can take a look at the driver I
wrote. I found that the Vex Range Finder was generally a better product than the Parallax unit. Both are equally accurante but the Vex unit had a longer range. Since the Vex unit has the protective covering it's ready to be mounted on a robot.
I would watch out for your use of printfs while using a range finder. I would keep the printfs at about 1/second. Otherwise, I have experienced poor distance accuracy.