Adding Touch & Light Sensors

In the last session, you learned how to wire up motors to the Handy Board. You also learned how to write, and download IC programs from your computer to the Handy Board. In this session, we will add two sensory capabilities to the robot, and explore some behaviors that can be modeled using these facilities.

Touch Sensors

Your LEGO Bug design already includes two touch sensors. These are simple momentary switches The switches remain closed only while the latch is pushed down. With an extended assembly (made out of LEGO beams or other similar objects) you can mount these on your robots so that they act as touch sensors. I.e., they can help detect if the robot has bumped into something.

Plug the handy board into the computer. Plug the switches into the Handy Board's digital ports (ports numbered 7 through 15). The IC command

digital(PORTNUMBER);

returns a 1 or a zero depending on the inputs to the port numbered PORTNUMBER. Issue the command several times to determine the values returned when the respective switches are open, as well as closed.

Exercise

Imagine your robot in an environment that has a 1.5 ft corridoor going around a 2 ft by 2 ft square box. Write a program that will enable the robot to go around this box. This time, as opposed to the exercise from last session, the robot will go in a strainght line until it bumps into a wall. After a bump it will proceed to make a 90 degree turn (you may need to have it go backwards a little to enable turning room) and then continue again in a straight line.

This task can ideally be accomplished using one touch sensor. But it will rely on being able to make perfect turns.

Can you circumvent the problem of perfect turns by using more than one touch sensor?

An alternative to the solution above would be to continuously touch the inner wall and follow it all the way around. Again a touch sensor could be used.

Try to think about an algorithm that will enable the robot to get out of a corral that has a 1-foot opening. The corral needn't be a perfect shape (rectangle/square/circle.

Other Possible Behaviors

Think of some other behaviors that could now be accomplished by using the touch sensors. Can you use it so that it detects the edge of a table, in order to avoid a fall?

Light Sensors

Today you will be handed two light sensors. The sensors are simple Cadmium Sulphide photoresistors. The resistance of the sensors changes when the amount of light it receives changes. Thus, when connected into the analog input ports of the Handy Board (ports 0 through 6), the change in resistance can be converted using the built-in analog to digital converters. Thus the values on these ports will vary between 0 and 255. The exact values you will receive from your light sensors will vary in that range. You will get lower values (close to zero) for bright light, and higher values (tytpically close to 255) for dark conditions. Thus, before you use the light sensor, you will have to caliberate them to get an idea of the sensitivity of your sensors.

The sensors themselves have been mounted on LEGO pieces so that you can easily make them a part of the assembly of your robot. You can use these light sensors to model several different behaviors: hiding in the dark, staying in the light, following a flashlight.

The next exercise is to learn the use of light sensors by interfacing them to your Handy Board. Also, you can start caliberating them.

Plug the handy board into the computer. Plug the light sensors into the Handy Board's analog ports (ports numbered 0 through 6). The IC command

analog(PORTNUMBER);

returns a number between 0 and 255 depending on the inputs to the port numbered PORTNUMBER. Issue the command several times, varying the amount of light incident on the sensor (your flashlight should come in handy here) to determine the response of the sensors.

You may find that it is important to caliberate your sensors relative to ambient light. The degree of variation used by your programs can be relative to ambient light rather than absolute values. Since ambient light varies from room to room, or even in the same room with different lighting conditions, it may be a good idea to make your robot adapt itself to any particular ambient light. This can easily be done by sensing ambient light at the begining of its operation. For instance, you may explicitly request the user to push the START button before the behavior is actually modeled. Then, prior to PUSHING the button, your program can sense the ambient light. This is called self caliberation or aclimatization. Of course, since the START button and the power ON switch are quite close to each other, and depending on your assembly the light sensors may also be close by, make sure that your hands are away from the sensors while doing the initial sensing!

Exercise

You can extend the behavior of your robot from the last exercise (corral exiting) by adding a light source to serve as a beacon for the exit of the corral. I.e., if, the exit to the corral were brighter than the rest of the area. Design an algorithm to make use of this new information so that your robot can find the exit more efficiently.

Other Possible Behaviors

Think of some other behaviors that could now be accomplished by using the light sensors. Can you use it so that it detects the edge of a table, in order to avoid a fall? Can you use these sensors to model line following behavior?

In the next lab session, you will be expected to demonstrate the corral exiting behavior. You should have two versions, one that uses onlty the touch sensors, and one that uses both types of sensors.


Next: A Sample Control Program

Previous: Handy Board & Interactive C

Back to Using Robots in an AI Course