Chapter    10

Seeing with Ultrasonics

The LEGO MINDSTORMS Ultrasonic sensor is another way to give your robot the gift of sight. Unlike the Light sensor, which detects reflected light, the Ultrasonic sensor works by sending out a sonic wave that reflects off objects in front of the sensor. The wave reflects back to the sensor, which determines its distance from the object based on the amount of time it took the sonic wave to return. This is similar to the way that animals such as bats see at night.

The sonic wave has a much longer range of detection than the Light sensor. But you need to be careful with the way you use the Ultrasonic sensor at robot events. Various factors affect how the sensor detects objects in its environment.

How It Works

Figure 10-1 shows the Configuration panel for the Ultrasonic sensor block. The panel settings are similar to the other sensors in that you need to select the port that the Ultrasonic sensor is connected to. Then you select the distance you wish to use for a comparison. You do this either with the slide bar or by typing in the value directly.

Note  The sensor can measure an object up to 100 inches (250 centimeters) away from the sensor.

9781430245360_Fig10-01.jpg

Figure 10-1.  Ultrasonic sensor Control panel settings

You also set the trigger to look for distances either less than or greater than the distance you have entered. The Show property allows you to select either inches or centimeters. When working with objects that are close to the sensor, centimeters will give better accuracy.

A simple program to write for the Ultrasonic sensor is one that displays the distance to an object. The idea is to show the current reading of the sensor on the screen of the NXT. You can use the program as a fancy measuring tape.

Figure 10-2 shows an example of such a program. Inside the control loop, an Ultrasonic sensor block passes the distance value to a Number to Text block. The converted value is then passed to the Display block. The value will be shown in either inches or centimeters on the Ultrasonic sensor block.

9781430245360_Fig10-02.jpg

Figure 10-2.  A digital tape measure program using the Ultrasonic sensor

Making It Work on the Game Field

The NXT Ultrasonic sensor can be very helpful in detecting large objects on the game field. The sensor should always be mounted in a horizontal position for accurate readings. Again, centimeters work better than inches when trying to detect close objects. Distances less than 3 millimeters cannot be read accurately by the sensor. Accuracy is decreased when objects are further than 25 centimeters from the sensor. The optimum range for the Ultrasonic sensor is between 3 centimeters and 25 centimeters. The receiver is located on the left side of the sensor, making the sensor stronger at detecting objects on the right side of it, where the sonic signal is transmitted.

The View tools built into the NXT brick are very helpful in calculating the distance of objects and the proper placement of the Ultrasonic sensor on your robot. Experiment with various locations to see which position gives you the most consistent measurement for detecting a particular object on the field.

When using the Ultrasonic sensor in a competition where other robots are running close by, it is a good idea to keep the sensor mounted lower than the walls on the game table. There is the possibility that another robot is also using an Ultrasonic sensor Your robot’s sensor can become confused if another robot’s sonic signals are detected. By keeping your sensor lower than the table walls, you will minimize the risk of confusion.

The Ultrasonic sensor works very well at detecting large, flat objects that are approximately perpendicular to the line between the sensor and the object. Objects that are smaller or rounded may not be accurately detected. In the 2009 FLL Smart Moves games, there were a series of “sensor walls” that the robots had to detect and either knock down or navigate around. If your strategy were to avoid the walls, then a Bumper or Touch sensor was not an ideal way to detect them. The Ultrasonic sensor was perfect for this task since the walls were rather large and flat; it had little trouble detecting them. Figure 10-3 illustrates a robot with an Ultrasonic sensor installed on its front. It is trying to detect a LEGO wall field object.

9781430245360_Fig10-03.jpg

Figure 10-3.  A robot with an Ultrasonic sensor that is detecting a sensor wall

Beware of unintended objects getting in the Ultrasonic sensor’s view path. During competitions, for example, referees or team members may have to reach onto the game field to remove a stray object, during which time their hands could get in the path of a robot’s sensor. Be careful not to allow your robot to detect a person reaching onto the field. Otherwise, thinking that it has encountered an obstacle, your robot could change its course.

Finding Nearby Objects

A simple task for the Ultrasonic sensor is to search for objects or obstacles in the area. Let’s say you’re participating in a LEGO Sumo Bot game in which two robots on a game field try to push each other out of bounds. Most of the time, these games are held on a circular black field with a white edge bordering the area. The robots start the game side by side in the middle of the field. The robots wait five seconds before trying to push each other out of the field. Figure 10-4 shows a simple Sumo Bot practice game.

9781430245360_Fig10-04.jpg

Figure 10-4.  A team practicing their Sumo Bots on the game field

You could simply have your robot travel randomly inside the boundary until it runs into the other robot, and then try to push the other robot out of bounds. With a Light sensor, your robot could detect the edge of the field and change direction when it finds the edge. The diagram in Figure 10-5 maps out this concept.

9781430245360_Fig10-05.jpg

Figure 10-5.  The robot starts in the middle, moves forward to detect the edge with a Light sensor, and backs up and turns when the edge is detected

This strategy will only get you so far before a smarter robot takes you out, but the program looks something like Figure 10-6.

9781430245360_Fig10-06.jpg

Figure 10-6.  A simple Sumo Bot program with edge detection

The smart approach would be for your robot to scan the game field for the other robot, and once it is located, try to push it out of limits, as shown in Figure 10-7.

9781430245360_Fig10-07.jpg

Figure 10-7.  The robot will scan with the Ultrasonic sensor, and once it finds the other robot, move forward to make contact

Take a look at the Wait block using the Ultrasonic sensor as the sensor type in Figure 10-8. The Until parameter uses Distance and waits until an object is detected within the given distance.

9781430245360_Fig10-08.jpg

Figure 10-8.  Ultrasonic sensor Wait block

Incorporating the Wait block with the Ultrasonic sensor for our sumo robot program is a simple process. If your robot is in scan mode, it simply sits in the middle of the game field and rotates 360 degrees until the Wait block detects the other robot within the given distance, as seen in Figure 10-9.

9781430245360_Fig10-09.jpg

Figure 10-9.  The robot turns in a circle looking for the other robot within 24 inches. It stops rotating once it finds the other robot

Once the Ultrasonic sensor detects the other robot, the Move blocks stops and the robot will move in the direction of the other robot (see Figure 10-10).

9781430245360_Fig10-10.jpg

Figure 10-10.  Now the robot moves forward as before, hoping to push the other robot while still seeking the edge of the table so that it doesn’t drive itself off the game field

Now you just need to wrap this program in a loop and you will have a simple Sumo Bot program (see Figure 10-11). Be sure to give the robot plenty of room to spin around when it finds the edge of the table. Back up a good distance from the table edge, or else your robot could put itself out of the event by driving off the sumo game table.

9781430245360_Fig10-11.jpg

Figure 10-11.  Adding the loop will allow the robot to try repeatedly until it finds the other robot

If you really wanted to get fancy, your robot could use multiple Ultrasonic sensors. The MINDSTORMS NXT has four sensor inputs, so you can actually connect three Ultrasonic sensors to the robot—on the front, right, and left sides—and a Light sensor on port 4. This would allow your robot to sit and wait for one of the three sensors to detect the location of the opposing robot. Note that the LEGO MINDSTORMS kit only includes a single Ultrasonic sensor, so the other sensors would have to be purchased separately.

The sensors feed into a Switch block. The direction your robot positions itself to move forward and make contact with the opposing robot is determined by the Ultrasonic sensor that detects the other robot. The flow diagram in Figure 10-12 maps out the logic for making this work.

9781430245360_Fig10-12.jpg

Figure 10-12.  A flow diagram mapping out the logic of using three Ultrasonic sensors for a Sumo Bot

Figure 10-13 shows the NXT-G code for making use of three Ultrasonic sensors. Don’t worry if you cannot read the details. You can download the code from the Apress web site (www.apress.com) to view the code in more detail.

9781430245360_Fig10-13.jpg

Figure 10-13.  A Sumo Bot program using three Ultrasonic sensors

Summary

Even though the Ultrasonic sensor is not one of the more popular sensors used in LEGO robotic events, it can be a very powerful tool. If used properly, it gives your robot the ability to detect and sense obstacles without having to make direct contact. This is not only effective in avoiding things, but at the same time it allows your robot to make decisions from a distance—saving you time that can be put to better use in accomplishing your goals.

Technical judges will be looking for teams that take advantage of all the sensors available, as long as using the sensor makes sense. Be sure that your team can explain not only why you are using an Ultrasonic sensor, but also make sure you understand how and why it works.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset