I implemented an algorithm for my robot that performs this basic task, although
it's probably not 100% accurate. I have a narrow-beam Maxbotix EZ4 sonar mounted
on a panning servo. I sweep the sonar and take a series of distance measurements
with pan angles spaced 10 degrees or so apart.
If you think about it, walls, corners, and objects have characteristic geometries.
You can plot the angles and trigonometry out on a piece of paper. I forget the
exact ratios I used, but basically to detect a wall, I look for adjacent readings to
be within about 15-20% of each other. With a corner, adjacent readings will
fall off much faster, maybe 30% or so. With a size-limited object, there will
be a much larger falloff in distance at the edges of the object.
___________
/ \
/ \
|^^^|
__| |__