i cant give you a circuit, but i would imagine that you would be monitoring the motor current. when you hit a wall, the motor will stall, at which point it will draw more current. when you get this current spike, you.... depending on configuration, but if using a relay to control direction, you would trip the relay to reverse direction. i imageing you would have to filter out the first spike after changing direction to avoid the starting current to the motor causing it to reverse again.
these are just whats bouncing around my head, and untested, so please go easy if ive made an obvious mistake.