The basic idea is to program the robot to respond a certain way to outside stimuli.
Most of them use stereo vision to see the world around them. Several Cameras give these robots depth perception, and image-recognition software gives them the ability to locate and classify various objects.
More advanced robots can analyze and adapt to unfamiliar environments, even to areas with rough terrain. These robots may associate certain terrain patterns with certain actions. A rover robot, for example, might construct a map of the land in front of it based on its visual sensors. If the map shows a very bumpy terrain pattern, the robot knows to travel another way.