Here Comes the Sun This activity requires ROBOLAB 2.0 or higher, the Infrared Transmitter and cable #9713, RCX #9709, elab sets #9680 and #9681. The Challenge Invent a car that finds the optimal light conditions for charging a capacitor from a solar panel. After the solar panel charges the capacitor, the capacitor must be able to run the car for a least a few seconds. Recharge the capacitor while the car is parked. How can you make sure the solar panel is facing the sun whenever it stops? What to Do Here is one way to solve the problem using a touch sensor and a light sensor. Program the car to drive forward until you press the touch sensor, indicating you wish to park. When the touch sensor is pressed, the car stops and rotates slowly as it searches for the brightest light. Once the car has found which direction has the brightest light, it turns facing that way, then halts. Building Ideas Turn your RCX into a car with each of the back wheels controlled by a different motor. Your car should be able to turn in a circle easily. Hint: Put the two front wheels on different axles so that they can turn at different speeds or use just one front wheel, like a tricycle. Mount the solar panel securely on top: Add a touch sensor to tell it when to park and a light sensor for finding the brightest light. Programming Ideas In your computer program, you will need to give your car a set of instructions for determining the direction with the brightest light and for stopping at the optimal light level. This set of instructions for doing a task is called an algorithm. Here is one possible algorithm: Make the car turn as long as the light sensor values are increasing (that is, the light is getting brighter). As soon as the light sensor values decrease, the car returns to its previous position and stops. The advantage of this algorithm is that it is fairly simple but it has disadvantages, too. Can you think of any? 1
What other algorithms can you think of for finding the brightest parking position? Before you start programming, brainstorm methods that you could use for determining the direction with the brightest light as your car rotates, then returning to this position after the rotation is complete. Choose the algorithm that you would like to use for your computer program. You may use the simple algorithm described above or your own idea. Journal Use Import JPEG to create a Journal page showing your solar panel car. Create a page using the Describe template and write an explanation of the algorithm you will use for finding the brightest parking position. Program Use Level 4 to write the program. You can use a container to store the value of the light sensor reading. To compare the current value of the light sensor to an earlier one, use the Light Sensor Fork, wiring the container holding the earlier value into Compare. Download the program to your car and run it. If your program did not work as you expected, modify it and try again. Upload Once your car and program are working to your satisfaction, upload the data to the computer. Program Write a simple Pilot program that takes a light sensor reading every hundredth of a second while the car turns a circle. Run the program to collect additional data. Upload Add a new page and upload the data from the Pilot program as well. Examining this data allows you to check that your car found the brightest light. Note: If you used an algorithm in which your car made a complete rotation, then returned to the brightest spot, you can just compare the data from your first and second rotations to see if your car found the brightest light. 2
View Use Compare in the View area to examine the data from your car and from the Pilot program. Look at the maximum value of each line. Did your car find the brightest spot? Journal Using the Describe template to write a conclusion to your experiment. Develop answers to these questions: 1) Did your system optimize the available light? 2) How could you improve your car and program if you had more time? Present Create a presentation of your experiment containing the following pages: Journal page describing the car and algorithm, Program page, Data page(s), Journal page of conclusions. 3
Teacher s Notes for Here Comes the Sun LEARNING OBJECTIVES Students will understand: How to write a computer program that includes sensors. What an algorithm is and why it is useful. That, through experimentation, a value (such as light intensity) can be optimized. That sensor readings provide feedback to control the behavior of a device. DISCUSSION This activity can be used in a number of different ways. For example, the students could be given plans for building the car and could concentrate on programming it. Or, students could be given one or more algorithms to program and test, rather than inventing their own. Building Ideas The car can be built using one or two motors. The student handout assumes that the students will build their own two-motor cars. Alternatively, they can be given building plans for single-motor cars. This design will allow the car to go forward or turn using just one motor. Sample building idea for a one-motor car: 4
If extra motors are available, the students can design their own two-motor cars. One possible car is shown below. Sample building idea for a two-motor car: Programming Ideas The simple algorithm outlined in the student worksheet should be relatively easy for students to understand and program. However, it may cause the car to stop in a bright area which is not the brightest possible position, because this algorithm has no way of checking whether the bright spot it has found is just a local maximum. Here is a more sophisticated algorithm: The car rotates 360 degrees, finding and storing the highest light value on its first rotation. Then it rotates a second time, stopping when the light sensor reaches this value again. If you choose to have students develop their own algorithms, you may want to brainstorm ideas as a class and discuss each algorithm s viability before the students begin programming. 5
Sample Programs Here is one possible solution for the simple algorithm: The car turns until the light dims. Then the car returns to the location of the previous reading. Here are two possible solutions for the more complex algorithm: The car rotates 360 degrees, finding and storing the highest light value. The car rotates a second time, stopping when the light sensor reaches this value. Version 1. This solution uses the Timer Fork which is only available in ROBOLAB 2.0 Investigator Program Level 5. 6
Version 2. This version uses a Loop instead of the Timer Fork. This program can be written in Level 4. This program is harder to understand and use than Version 1. The number of loops needed for the car to complete one rotation must be found by trial and error. Here is program for capturing light sensor readings every hundredth of one second. 7
Testing the cars The more complex algorithm works well in a wide range of settings as long as the light conditions remain constant while the car is turning. The simple algorithm, by it very nature, is much more sensitive to shadows, glare, and other problems with the lighting. It works best in a dim room with a single light source near the car, such as a reading lamp or a powerful flashlight. Extension The position of the sun changes during the day. Modify the car so that if the light shifts while it is parked, it will rotate to find the new brightest spot. Add just three commands to the original program for a solution to the extension At the end, right before Stop Data Logging, add a Wait for Dark icon followed by a Jump. Place the corresponding Land near the beginning, right after Start Data Logging. 8