120 likes | 225 Views
Using Events to Control Behavior. Developed by Lisa Marchitello. Using Events to Control Behavior.
E N D
Using Events to Control Behavior Developed by Lisa Marchitello
Using Events to Control Behavior An event can be programmed for the RCX to monitor. When the event occurs, then a portion of the program will be run. This would be useful when a pattern the robot should follow is not evenly spaced or predictable.
Event Sample • This program will watch for an event, wait for touch to occur, then stop. • Events act like a jump and land which is waiting for something to occur to activate. Event Landing: When the event is detected the earlier loop will end. The next task in the program will start. Robot Task: Motor A will stays on until event occurs. Event Setup: Watch for TouchSensor (attached to port 1) to bepushed in has been activated.
Finding Event Icons • The event sub-menu is located at the bottom of the Structures Menu.
Programming Events • Step 1: Set up the event: Choose the event you want to wait for. In the events sub palette there are many choices which relate to data connected from the robots sensors (such as light, touch, rotation and containers)
Step 2: Start monitoring event: Add this when you want the RCX to start waiting for the event. This can be added later in the program as needed.
Step 3: Event landing. This tells the RCX where to jump to when the event occurs. Any command prior to this point will be ignored.
Monitoring for events can be stopped during a program when needed but it is not necessary to do this to complete a program. • Events behave much like jumps and lands or wait-for loops. However, you can have several of them running at one time! • All events share a single event landing.
Setting up modifiers for events • Modifiers for events can be found in the regular modifier sub palette. • Use the port icons with a white background for the sensor event icons.
To modify the set-up event and start monitoring for event icons, a modifier that looks like a key needs to be used. This is a sub palette. • Remember to keep the key color the same as the color of the monitoring sensor. • Solid red background connects to the keys that have red in them. • The computer won’t let you wire the wrong type of key. • The keys in the first column attach to the event monitoring icon. • The rest of the keys in each row, depending on color, would be attached to the start monitoring icon.
Cockroach* • This program is set up to monitor for light. When the light value increases, the robot changes its behavior and moves quickly (like a cockroach would). Event Landing: When light is turned on, the RCX will skip to this par t of the program. Start monitoring for light to increase Tell RCX to begin monitoring This part of the program tells the robot to stop for one second, then turn on motors A & C at full speed for 4 seconds and then stop. The bug is trying to run and hide. Designate event with red key & add cut off value for light sensor using a numeric constant. This part of the program tells the robot to turn on motors A and C in random directions for 1 second. The red jump and land will have this take place forever or until the event occurs (light turned on). This is to imitate a wandering bug. *“Cockroach” is taken from Engineering with LEGO Bricks and ROBOLAB by Eric L. Wang
This program allows a robot to follow a line with gaps. Wait for darker event is set up. Program will jump to event line when robot detects dark. Robot travels straight and then turns right using only the C motor. This behavior will keep repeating indefinitely and was set up to find a dark line. Timer loop set up to run program for 20 seconds. Blue land Blue jump The program will return to the blue land at the beginning to repeat the process. However, if the timer has passed 200 tenths of a second or 20 seconds the program will stop. When the event occurs (robot detects a dark line) the program will jump to this point. This portion of the program is for writing a line tracker program using loops. Notice these loops only work for 6 clicks.