By "closing speed" I assume you mean that you want to measure how quickly the car is approaching the wall and adjust its velocity proportionally, (no wall = full speed, approaching wall = slower and slower speed), correct?
You could estimate the car's velocity by calculating the difference between subsequent sensor readings (or an average of multiple subsequent readings b/c of sensor noise) and dividing it by the time between readings. Essentially, you are finding the numerical derivative
of your position indicated by the sonar sensor readings. Then, you could increase or decrease the current to the car's motors based on how close you are to the wall.
To get the time between readings, try using the Time library
, or more directly the now() function. Not sure what the resolution of the time is -- might only give you integer seconds as opposed to fractions of a second via a double or float, but it's worth a shot!