Here's a video of a "Candy Hunting" robot I built.
The three NXT motors are used for the tracks and rotating the arm that holds the ultrasonic sensor. A power functions motor is used to raise and lower the arm that holds the ultrasonic sensor. A second power functions motor is used to open/close the gripper and raise it slightly when it has hold of a cut down pop can. A HiTecnic IR Link is used to control the power functions motors.
The basic mission is to scan for the closest object, move to that object, collect it, return to the starting point. Deposit the object and then return to the starting orientation.
To find the closest object I do two scans. One close to the ground. The second with the sensor raised up. The intention is that if I see something when the scanner is close to the ground that isn't there higher up, it is something I'm interested in. If the object is seen in both the lower and upper scans, I assume a wall and ignore it. This works sometimes. With a sensor that has a smaller angular spread, I expect this would work better.
I also found that the sensing wasn't as accurate as I needed it to be to collect objects more than 40 cm away. To minimize this problem, the robot moves to within 20cm of where it things the object is and then does a second scan to refine the objects location.
I keep track of total distance and angle travelled and then do some simple math to find the return vector.
The robot is programmed in LeJOS.
The tracks are almost directly from the Technic Bulldozer. The rest is my design, build and code.
The LeJOS class to drive the power functions motors is checked out from the LeJOS repository and