Part 1: Identify and Distinguish
The aspiration of many robot hobbyists is to create a machine that uses autonomous behavior to achieve a goal. Unfortunately, many roboticists assume that such goals are limited to simple tasks like avoiding objects or following a line. This article discusses how giving your robot even a rudimentary ability to identify objects can increase its ability to cope with more complex situations.
A typical hobby-level robot might avoid objects while it randomly roams around a room. Nearly all hobbyists have observed such a behavior, and only a novice will be overly impressed by the capabilities of such a robot. In actuality, the robot’s random movement is the source of discontent. The robot’s only goal is the avoidance of anything that gets in its way. If the robot could identify important objects, then its ability to react to its environment could be greatly improved.
If, for example, the robot could identify both a soccer ball and a goal, then it could be programmed to find the ball and deliver it to that goal. The task of avoiding other objects during this endeavor then becomes a means to an end, rather than a goal of its own.
Programming a robot to actually play soccer can be very ambitious, but a simplified version of this activity can help demonstrate how even just a hobby robot can identify objects within its environment.
The Needed Sensors
In order to achieve this task, our robot will need to have several types of sensors. The details of the algorithm we develop will depend heavily on the actual sensors used. So, we will use a modular approach to make it easy to implement the principles discussed here with sensors you might already have.
First, our robot will need a ranging sensor capable of measuring the distance to objects. We’ll use an ultrasonic sensor mounted with a forward orientation. The purpose of this sensor will be to locate objects that are reasonably close to the robot.
The robot will also require a beacon detector to easily identify the location of a specified target (a beacon will be mounted above the soccer goal). We will use a RobotBASIC IR beacon, but you could use a flashing light or a uniquely colored object. (A beacon can be almost anything, as long as you have a sensor that can detect it.)
We’ll mount a U-shaped trap to the front of the robot as shown in Figure 1.
This trap is made from craft sticks (like large Popsicle sticks) that make it easy for the robot to trap the ball and push it around.
The trap has three sensors of its own to help identify and maintain control of the ball. Our trap sensors are digital IR versions (Pololu #1134) with a fixed range of about four inches. Two are mounted on the tips of the trap — pointing forward — with the third mounted on the side pointing inward (refer again to Figure 1). We will see how these sensors are used shortly.
Figure 1 also shows a Parallax PING))) ranging sensor (part #28015) mounted on the very front of the robot, as well as a beacon detector which is a Vishay TSOP34156 with a short cardboard tube taped to the front of it to make it more directional.
Our robot is a Magician chassis (available from Zagros Robotics; an updated version is available here) controlled by the RobotBASIC Robot Operating System (RROS), along with a special printed circuit board (PCB) to make it easy to directly interface with all the sensors.
Once you understand the principles we’re using here, you can create a similar project with almost any hobby robot equipped with appropriate sensors.
Most sensors supported by the RROS plug directly into the PCB. As mentioned earlier, our soccer robot needs three sensors mounted on the ball trap. Figure 2 shows how easily this can be done.
We simply drill the appropriate holes for the IR sensors, then hold them in place with the female end of the cables that connect the sensors to the line sensor inputs on the PCB.
Figure 3 shows the robot approaching the target goal where the ball is to be deposited.
Notice the IR beacon mounted above and behind the goal. Complete information on how the RobotBASIC beacon system works can be found in the RROS manual which can be downloaded from www.RobotBASIC.com.
The ball we used has a nippled surface which prevents it from rolling away from the robot too quickly. This made development of the algorithm much easier. The soccer goal is made from foamboard panels; we often use this material to create walls and obstacles for our projects.
Implementing the Algorithm
We used RobotBASIC to implement the algorithm. Its easy-to-read syntax makes it simple to translate programs for use with other controllers. Figure 4 shows how quickly the algorithm can be implemented if it is assumed that all the details are handled by separate subroutines.
The first part of Figure 4 uses library routines to perform the initialization necessary for the RROS to control the Magician chassis and our chosen sensors. There is also a command to set an inverse mask. This is needed because we attached the trap sensors to the RROS line sensor inputs.
The line sensors report true when they see a black line (no reflection); we need to invert this logic with the trap sensors so they will report true when a reflection (from a ball or other object) is detected.
Inside the main program, the subroutine GetObject is used to find a ball. Once a ball is found, the subroutine MoveToBeacon will move the ball to the goal. Figure 5 shows how the ball is obtained. The outer repeat loop will continue looking until a ball is found.
Inside the loop, the speed is set to 25% of maximum to better locate objects. Also, the turn style is set to 100 so that the robot will rotate around its center when turning.
An inner repeat loop uses a for loop to rotate the robot left for a short time as it looks for a nearby object. You may need to adjust the for loop and the range distance to work for your particular situation.
If an object is not found, the robot turns a little and moves forward. This serves as a random movement to help the robot roam around until it “sees” an object to examine.
When the inner repeat loop terminates, it indicates an object has been found and a for loop moves the robot forward (for a short time) to see if it can find the object detected by the ranging sensor. The object is assumed to be found if any of the trap sensors detect it.
Identifying the Ball
Once an object is found, the program tries to identify it. Another for loop lets the robot briefly try to get the object into the trap. If it fits inside the trap, we will assume it is a ball.
This is a very simplistic way to distinguish the ball from other objects, but it serves to demonstrate the principle. A more robust algorithm could use a color sensor or other alternative approaches to help ensure that the desired object was found.
While trying to get the ball into the trap, the robot will attempt to adjust for situations it might encounter. If both of the front trap sensors are triggered, a large object (such as a wall or the goal) will be assumed, and the robot will back away and continue looking for the ball. If either of the front trap se
sors are triggered, the robot will turn left or right to try to center the object so it can fit into the trap as the robot moves forward.
There's an important aspect to this routine. The robot always uses for loops to limit the amount of time it tries to perform any given task. If the task being performed is not accomplished in a timely manner, the robot restarts the entire routine. While this may prevent the robot from occasionally obtaining a ball it has found, it also prevents the robot from getting stuck in a loop where the robot’s actions make no sense at all.
Moving to the Goal
Once the ball is in the trap, the subroutine in Figure 6 will find a beacon and move the robot toward it so that the ball can be deposited at the goal.
At the beginning of this routine, the speed is increased slightly to help the robot keep the ball in the trap as it turns to look for the beacon. The turn style is also changed to zero, which simply causes the robot to rotate around one wheel rather than around its center.
This motion helps keep the ball in the trap. The robot will turn left in this manner as it looks for the beacon located at the goal.
When the beacon is found, the robot turns back to the right slightly to ensure that it is aimed at the beacon or a little to the right of it. It then moves forward, turning to the left when the beacon is not seen, and to the right when it is. This action effectively lets the robot follow the beacon’s signal. It does so until one or more of the front trap sensors indicate that the goal has been reached.
We have provided an easy-to-understand example of how a robot can locate and identify a ball within its environment, and then move it to a goal. A more robust algorithm for obtaining the ball could certainly be implemented — especially if additional sensors are utilized.
The hardware requirements for this project are minimal, so you might find you can experiment with these principles using a different robot. Watching the robot seek out the ball, maneuver to trap it, and move it to the goal is definitely worth the effort.
Next time, we'll build on the ideas discussed here and show how a robot (see Figure 7) can find small objects, then retrieve them with an easy-to-build arm. SV