M. Pathfinder (Modified Pathfinder) Before You Begin What’s the point? To help students understand that the behavior of a motor (e.g., which way it turns) can be controlled by switching wire connections or via a program. Instead of rewiring a device in order to change its behavior, we can use a set of instructions—a program—to do it. To help students analyze simple motion patterns for a two wheeled vehicle such as moving forward and backward or turning and to relate these patterns to motor operations and to programming commands. For example, students will observe a turning vehicle, realizing that one motor is turning. They will then represent this observation in a computer program. What you will need: For Part 2: For Part 1: For each group: • M. Pathfinder for demonstration • 2 wires, about 40 inches long, with ends stripped • 2 alligator clips • 1 C or 9 Volt battery • 2 intact long connector wires • • • • The Robotics Inventions System™ kit A disk A copy of the Technical Guide A copy of M. Pathfinder building instructions • A building bin (optional) • Student activity sheet For the class: • M. Pathfinder transparency # 1 Programs used: Roundtrip, TurnTurn, Long, Short, and Different © 2002 The LEGO Group. Used here with permission. 3-1 Prepare Ahead: 1. Make enough copies of the M. Pathfinder building instructions for each working group to have one. 2. Make enough copies of the Building and Programming M. Pathfinder student activity sheets for each student to have one. 3. Build M. Pathfinder following building directions provided with this manual. Do not attach the RCX to the base. 4. Prepare the stripped wires as described in (See Note on Materials box below). 5. Download programs Roundtrip and TurnTurn onto the RCX. H-9 Note on Materials There are several ways to connect Lego™ motors to a battery without connecting to the RCX. We will describe two: 1) using a stripped connector wire, and 2) using wires with alligator clips. Stripped connector wire: Since kits don’t come with extra connector wires, you will have to purchase an additional wire separately. (The Pitsco Lego Dacta online store—www.pldstore.com—offers small packages of connector wires (sometimes bundled with a touch sensor). To prepare the wire, cut the brick from one end of the wire, separate the wires along their midsection for a length of about 2 inches, and then strip about ½ inch of each wire (see first illustration below). Wires with alligator clips: Another way would be to obtain general purpose electrical wires and 2 alligator clips (Can be found in hobby or electronics stores.) You will need 2 wires, each about 1 ft. in length. Strip both ends of each of the wires. Connect an alligator clip to one end of each wire. Use the clips to connect to an intact Lego™ connector wire as illustrated below. Be sure to connect the clips on the bottom of the brick so that the clips touch the metal part of the brick and the clips don’t touch each other. It’s best to attach the clips on non-adjacent corners (on the diagonal). Running Lego motors without the RCX New commands introduced in this activity: Activity Overview Pathfinder is a two-wheeled, two-motor vehicle without any sensors attached. It is an easy-to-build, easy-to-fall-apart vehicle. We have included building instructions since it is no longer included in the Constructopedia. We suggest using it as a vehicle (no pun intended) for introducing RCX Code. This activity has two parts. Part 1 is designed as a transition between the Wall Hugging Mouse and programmable robots. In this part, you will demonstrate running M. Pathfinder’s base without the RCX, showing that the unit can run on batteries alone and does not have to be programmed to run. You will show students that M. Pathfinder can run with or without the RCX. When connected to batteries, it can run forward or backwards, turn right or left, all depending on wiring. You will then demonstrate how M. Pathfinder’s behavior can be controlled through a program rather than through wire switching. P-1 © 2002 The LEGO Group. Used here with permission. R/W-1 P-3 P-2 P-5 P-4 3-2 In Part 2, students build the modified Pathfinder, following the M. Pathfinder building instructions. They then run it using the program in slot #1. (This program is downloaded onto the RCX when firmware is installed.) Students will notice that M. Pathfinder goes forward, but doesn’t stop by itself. In order to stop it, they must catch it and turn it off. Next, students will follow the activity sheet to help them figure out how to make M. Pathfinder move and stop on its own, using the On, Wait for, Off, and On For command blocks. At this point students will be ready to use the newly acquired commands to write their own programs, instructing M. Pathfinder to move in a variety of ways (e.g., zigzag, go around a box). Finally, they will program M. Pathfinder to go towards a wall, hit it, and go backwards. It is important that all students solve this problem before they move on to work with touch sensors. Discussion Points Part 1: Running Lego Motors with and without the RCX Whole Class Activity Before students build M. Pathfinder: Show students the base of a pre-built M. Pathfinder without the RCX. Connect one end of a long connector wire to each motor and then connect the other ends to each other, stacked on top of one another. If you are using a stripped connector wire, connect it to the long connector wires on one end, with the stripped end free. If you are using wires with alligator clips, connect the clips to the long connector wires (see illustration on the previous page). Now, take one stripped wire and hold it to one end of a battery. Hold the second stripped wire to the other end of the battery. Point out that M. Pathfinder is running in one direction now. Then switch which wire is connected to which end of the battery. Have students observe that M. Pathfinder is running in the opposite direction. Ask students what they think you should do to make the base turn in place. If needed, remind them of how the Wall Hugging Mouse moved (one motor turned on at a time). Adding the RCX: Show students the RCX. Explain that it is a small computer that runs on batteries and can hold up to five programs. Remove the stripped wires and connect one end of a long connector wire to Port A and the other to Port C. (The other ends should remain attached to the motors.) Hold the RCX in your hand and show students the red on/off button, the gray program button, and the green run button. Point out that when a program (1-5) is selected, a number is displayed in the display window, indicating which program is running. In addition, an icon of a running person helps you tell whether or not a program is running. Now run the Roundtrip program and have students describe what M. Pathfinder is doing. Point out that this time you haven’t switched wiring. Then move to the TurnTurn program and run it. Emphasize that M. Pathfinder is displaying different behavior—moving forward, backward, turning one way and then the other way—but you haven’t changed the connector wires. The motors are turned on or off by commands that are coming from a program. Finally, attach the RCX to the base, using short connector wires, and let it run on its own. Tell students that they will build M. Pathfinder and program it in the next section (It may or may not be in the same lesson, depending on the time allocated for the activity.) Part 2: Building and Programming M. Pathfinder Small Group Activity Building M. Pathfinder: Have students work in small groups. Give each group a copy of M. Pathfinder building instructions and each student a copy of the activity sheet. As they build, talk to students in their groups, showing them the different buttons on the RCX and encouraging them to look up their function in the Technical Guide or to search the Help menu for RCX buttons and RCX display window. Make them aware of the running indicator on the display window and of how to move from one program to another. When they have finished building, if at all possible, allow students to run their vehicles in a hallway. 3-3 B-5 Beyond the Basics How can we explain. . . It sometimes happens that M. Pathfinder runs backwards or spins in place when using the program in slot #1(even though the program instruction is to turn on both motors). Just as in the Wall Hugging Mouse, the answer lies in wiring rather than in the program. If this happens, remind students of what happened when they switched the wire on the Wall Hugging Mouse and have them reposition the wires either on the RCX or to the motors. To reposition the wires students will have to rotate the bricks attached to the connector wires 90º or 180º. About running a program There are two ways to run a program—by pressing the Run (green) button on the RCX or by clicking the Run button on the screen. Pressing the Run button on the RCX runs the selected program. Pressing it once starts the program as indicated by the running person icon in the display window. Pressing the Run button again, stops the running program. Clicking the Run button on the screen starts the selected program. The RCX must be within communication range with the IR tower. This allows you to track the running program and to get information about the state of sensors and motors. (See the RCX Sensor Link Wizard section in the Help menu.) Students are now ready to program their RCX. Decide whether to have students follow the worksheet and refer to the Technical Guide or the Help menu on their own, or whether to introduce the IR (Infrared) tower and the download procedure to the class as a whole. H-9 3-4 Show the class (or small groups) the IR (infrared) tower. Demonstrate how to use it to download a program onto the RCX. Point out the part of the RCX that must face the IR tower. Explain that the IR tower and the RCX must be within communication distance, just over a hand-width apart. Programs transmitted from the computer to the RCX via IR can then be run by the RCX. Have students work on their own to solve the problem of making M. Pathfinder do things on its own— recreating a program, downloading, and running it. As they work, talk to them in small groups about the difference between downloading and saving (one goes to the RCX the other onto a disk). Programming Highlights The following section, Programming Highlights, discusses important learning points about programming that should be explored by the students. You may choose to discuss them with the whole class or group by group as they arise during students’ work. Downloading a program and setting the program slot For a program to run, it has to be downloaded to H-9 the RCX. The RCX can hold one program in each of its five program slots. Each time a program is downloaded into a slot, it overwrites the old program. Therefore, it is important to know which one is the active program slot. Use the Program Setting menu on the screen to check or change the program slot. Be on the lookout Many times beginners do not pay attention to which program slot a program is downloaded. By default, a program is sent to slot #5. If that is not changed, the next program is going to land in the same slot, erasing the older program. What you can do: Remind students to check the program slot before they download and to change it if needed. With practice, this will become a habit. The Wizard. Each programming block has a small tab on its right side. This is the wizard. When clicked, the wizard opens a dialog box, allowing you to observe, add or change information related to the block. For example, clicking on the tab on the On For block, opens the wizard that allows you to designate motors to be turned on and to specify the amount of time they should stay on. Tab © 2002 The LEGO Group. Used here with permission. Click Wizard In this dialog box, motors A and C are set to turn on for 3 seconds. 3-5 How is ON AC different from On AC for 1? The On AC block turns on the motors connected to output Ports A and C for an unspecified length of time. To turn them off, the block Off AC must be used. However, if the Off block is used immediately after the On block, the motors will turn on for a fraction of a second hardly noticeable and then immediately turn off. To have the motors run for a while, you must delay the onset of the Off command. This is done by inserting a Wait for block, which specifies the number of seconds before the program carries out the Off command. The On AC for 1 block actually combines three commands into one—On AC; Wait for 1; Off AC. That’s why there’s no need to turn the motors off after using this command. Be on the lookout P-1 P-3 What you can do: An analogy to plain R/W-1 P-2 then the program executes the Beep block. Here the observable behavior of motors turning and block execution time are of the same length—3 seconds. A simple way to put it: it takes “no time” to tell the motors to turn on, but the program has to stay there for 3 seconds in order to tell motors to turn off, only then it is free to focus its attention on the Beep block. 3-6 students what’s the difference between person to “walk for 2 minutes.” Point out that even though the word “stop” wasn’t used in the second request, a person will know to stop after 2 minutes, but will continue walking when a time is not specified. Note: The off block has two modes, the default mode Coast and an alternate mode Brake. In coast mode, motors come to a stop gradually. In brake mode they come to an abrupt stop. For demonstration purposes, Brake mode is more useful than coast mode. © 2002 The LEGO Group. Used here with permission. It takes 3 seconds to execute the first block. Only English commands might be helpful. Ask asking a person to “walk” and asking a Executing Blocks. Observing behavior. Consider a simple stack of blocks containing power commands such as On, On for, or Off. The blocks execute in a topdown fashion. When the first block finished executing, the program drops to the next block, and so on. Different blocks take different amounts of time to execute. For example, the On block, executes in a flash; the On AC for 3 block takes 3 seconds to execute. It is very important to make a distinction between the time it takes a block to execute and how long the resulting behavior lasts. In the above example, it takes a flash for the On block to execute, but the motors turned on by the block will stay on until another block turns them off. Here are some examples to illustrate this point: Because the command to turn off the motors is hidden in the On For block, beginners sometime do not realize that the motors must be turned ON again if they are to run. It takes “no time” to execute the On AC block because the program tells motors to turn on and has no further instructions in the block. Therefore, it is immediately free to move on to the next block, Beep. Note: You can find additional examples illustrating this point in Transparency #1. Be on the lookout What does the command Reverse Direction do? The Reverse Direction command is not a movement command (It does not turn on motors). It is an orientation command, pointing the motors to move in the opposite direction when they are turned on. Motors do not have to be turned on in order to reverse direction. If a motor is already turned on, it will run in the opposite direction as soon as the program carries out the reverse direction block. If a motor is not turned on, it is going to be prepared to move in the opposite direction, but it’s not going to actually move until it’s turned on. Here’s an illustration of this distinction: The programs Needed and NotNeeded relate to whether an On AC block is needed or is not needed for the motors to continue to run. Many students interpret the block Reverse Direction as a command to start moving in the opposite direction. Therefore, they expect a robot to continue to move when the Reverse Direction block is executed in a program such as in the program Needed. P-5 What you can do: Tell students that the Reverse Direction command is independent of turning on/off motors. It is not a movement command, but rather an orientation command (prepare to move in the opposite direction). Emphasize that motors will continue to do what they are commanded to. In the program NotNeeded, the motors will turn in one direction for 2 seconds, then reverse direction and continue In the program Needed, the motors will turn in one direction for 2 seconds, stop, and prepare to reverse direction. They won’t move in the opposite direction because the motors were turned off in the On For block. Therefore, for the motors to run, they must be turned on again. © 2002 The LEGO Group. Used here with permission. turning in the opposite direction. 3-7 How is Reverse Direction different from Set Direction? Reverse Direction changes the direction in which a motor is currently running to its opposite. Set Direction sets the direction a motor should turn in regardless of the direction it was turning prior to carrying out the Set Direction command. In other words, Reverse Direction is relative to a prior state, while Set Direction is absolute and does not depend on what was happening previously. Be on the lookout Here, too, some students may expect the motors to turn on when the Set Direction block is carried out. In addition, some may not distinguish between the Reverse Direction and Set Direction commands, using them interchangeably. P-5 What you can do: Have a student P-4 turn right then ask him or her to reverse direction and then reverse direction again. Ask students how it is that the same command—reverse direction— resulted in different behaviors, once a left turn, and once a right turn. For a helpful illustration, see Set Direction and Reverse Direction in the Help menu. Be on the lookout Wait for! The Wait for block delays the execution of the command block that follows it. It has no effect on any command block above it in the stack. On the flip side of the Wait for block, you can specify the number of seconds the onset of the next block should be delayed. (You can use whole numbers or decimals.) R/W-1 Here are two examples. on for an unlimited length of time. They’ll stay on while the program is waiting for 3 seconds and beeping sound #3 and then they’ll turn off. So the wait command delayed the execution of the rest of the stack. But things were happening during that delay (i.e., The motors were turning). © 2002 The LEGO Group. Used here with permission. In the program, Delay1, motors AC are turned When using the Wait command, students expect a pause in the program. Indeed, sometimes the resulting behavior looks like a pause—when the previous command ended and the execution of the command that follows is delayed. But other times, it looks like the program continues carrying out the previous command without pause. Note: It is important not to confuse the Wait for block with the Wait Until block. R/W-1 The Wait Until block is a Stack Decision Maker, working with sensor input. The Wait For block is not a decision maker and does not depend on sensor input. In the program, Delay2, motors A and C are turned on for 2 seconds. Then the program pauses for 3 seconds before it carries out the beep block. While this program is waiting the motors do not turn because they were turned off in the first block. If needed, have students evaluate short stacks to help them understand how commands relate to each other. Use Transparency #1 to help you guide the discussion. 3-8 SDM-1 Transparency # 1 Motors turn on and a beep sounds. Motors continue to run while beeping and continue after the beep Motors run for 2 seconds and stop, then beeps sounds. ends. There is no command that tells the motors to stop. Motors turn on and continue to run. While the Wait for command runs, there is no change in behavior. Note that there is no command that tells the motors to stop. Motors turn on and a beep sounds after 2 seconds. This is an example where the Wait For delays the beep. Note that there is no command that tells the motors to stop. Motors run for 2 seconds and stop. The program waits for 3 seconds, which has no effect on behavior. Note that the motors turn off in the first block. Motors run for 3 seconds and stop. The program waits 2 seconds before it beeps. This is an example of Wait for resulting in a pause. © 2002 The LEGO Group. Used here with permission. Going Independent This is a good time to have students use the newly acquired programming commands and concepts. We recommend allowing students to come up with their own problems to solve or to work on the challenges suggested in the student activity sheets. It is important for all the students to write a program, instructing M. Pathfinder to go toward a wall, hit it and go backwards (not necessarily back to the start line). This is going to help them understand the function and advantage of using a touch sensor in the following session. 3-9 RCXamples: Here are some sample solutions to some of the problems from the student activity sheets. Spin (Zero radius turn) Zig-Zag See the Repeat For section 8-1 for details. Turn in a small circle (Fixed radius turn) © 2002 The LEGO Group. Used here with permission. 3-10 Here are some sample solution programs instructing M. Pathfinder to move forward toward a wall, hit the wall and then move backward. The amount of time it has to move forward before it hits the wall has to be determined empirically. © 2002 The LEGO Group. Used here with permission. After this set of activities, students will build a new robot. Be sure to have at least one M. Pathfinder assembled for a demonstration in the “Working with Touch Sensors” activity. After the demonstration, you can take it apart. 3-11