The Research Experience for Teachers Program http://www.cs

The Research Experience for Teachers Program
http://www.cs.appstate.edu/ret
Activity Title: Laser Tag With Finches
Time Required: 90min
Recommended Group Size: 1-2
Materials List: Tape, Flashlights, Finch Robots w/ USB connector Cable, Laptops w/ BirdBrain
installed (Download here: http://www.finchrobot.com/software/snap), Arena materials (detailed
below).
Introduction/Motivation: You will be using Snap, an application created from the well-known
Scratch. Snap is functionally the same as Scratch, except made directly for Finch robots. You
will be reviewing prewritten code, adding in some additional code of your own, and then using
the code you wrote to compete in laser tag against other Finch Robots.
Before the Activity: Learn about Snap!/Scratch and the Finch
Background: The Finch Robot has several different features, including obstacle
sensors, light sensors, temperature sensors, an accelerometer (to sense the Finch motion),
LEDs on the nose of the Finch, as well as an internal buzzer. Figure (1) details the location of
these features.
Figure 1
Using some creativity and logical thinking, we can use Snap to program the Finch to
follow commands based on what the Finch “senses”.
Problem: Some code has been removed from the completed program! Following the
criteria detailed below, place your own code into the program. Remember, your teacher will
check your code to make sure it works using the criteria, so don’t try and cheat!
Criteria:






Must “stop” and stay stopped for 3 seconds when tagged, regardless of
light or no light
Must react to light being shined on it
Must demonstrate that it has been tagged, whether by LED or sound
Must keep a counter of how many times it’s been tagged
Must have a “buffer period” after being tagged where it cannot be tagged
again
Must be able to move again after being tagged
Following these will make sure that your robot behaves accurately when
competing, and you won’t be disqualified.
Preparation: Make sure that BirdBrainRobotSoftware is installed on your computer. If not,
the download can be found here: http://www.finchrobot.com/software/snap. If the
BirdBrainRobotSoftware is not open, and the Finch is plugged in, the Finch’s nose should be
glowing. If BirdBrainRobotSoftware is open, it should tell you that the Finch is connected.
Figure 2
Snap Introduction:
Snap uses simplified programming tools, in order to allow ease of use and clarity.
One of these simplified tools are called “blocks”. To use these blocks, you drag them
from the area on the left side of the screen, and release them into the “building field” in
the center.
Let’s open Snap. On the BirdBrainSoftWare window shown above, click the “Open
Snap!” button. A window with 4 options should pop up: select the “Level 4, Regular
Snap! ” option, and click on “Open Snap!” This should open a page in your web browser
similar to what is shown below (Figure (3)).
Figure 3
Now let’s take a look around! As you can see, there’s a program that’s been premade. To test
whether your Finch works correctly, hit the Space bar followed by the “X” key. Now try slowly
waving your hand in front of the two black tubes on the Finch, one tube at time. Your hand should
be about 4 inches away. The Finch’s left tube will cause the Finch to light up, while the other tube
will turn off the light.
Once these two tests are complete, you are ready to move on to the next step: building your
own program!
Figure 4
Programming With Snap: An Introduction
Step 1: Adding a Control Block
Control blocks are the foundation for Snap programs; every Snap
project will have at least one control block. Control blocks can be found by
clicking on the ‘Control’ tab found in the top left corner. Under this tab
there are blocks that make up the “top” of the code. In other words, they are the blocks that mark
the beginning of the code.
Also under this tab are blocks that “control” the code. While they lack the ability to “start”
the code, they control the code that they encompass. For example, the “Broadcast” block is Figure 5
extremely important for this lab, and will be detailed later.
Step 2: Adding a Sensor Block
Sensor Blocks, found in the “Sensing” tab, allow some of the Control blocks
to be most effective. For example, if you look at the “If” Control block, you will notice
the hexagonal shape. Many of the blocks in the “Sensing” category fit into this notch,
allowing the “If” statement to work. Take a look at this example:
Here (Figure 6), we see that IF the space key is pressed down, then the
Finch robot will move forward. Otherwise, it will go backwards. The
reason a “Forever” block surrounds it is because otherwise, the program
will ONLY check if the space key is being pressed RIGHT when the flag is
clicked. With the “Forever” block, however, the program will check until
you stop it.
This is a simple example of what we will call an IF -- ELSE block.
Figure 6
NOTE: If you want to terminate a program, hit the Stop Sign at the top right corner of the
window. Generally, Finch will continue doing whatever it was last told to do, so make sure you have
a way to make it return to its normal state e.g. the “Stop Finch” block found under the Motion tab.
Step 3: Filler Blocks
See the blue blocks in Figure (6)? Those are what we will call “Filler” Blocks. They are the
blocks that make things happen, more or less. They will generally be found under the “Motion” tab.
Add these blocks in where they’re necessary to start commanding your Finch. In this lab, the
prewritten code will contain some examples for how to move your Finch using the arrow keys, but
feel free to create your own ideas, as long as they follow the criteria!
Step 4: The Technical Blocks
This program goes far beyond just a few blocks: it uses some of the more technical blocks
that Snap! has to offer. For example, “broadcast” – related blocks, variable comparison blocks, and
others.
Let’s talk about “Broadcast.” Broadcast blocks change something called the “Message.” Look
under the “Control” tab, and you’ll see this (Figure (7)). Checking the box
beside the “message” block shows what the most recent broadcast was,
which helps keep track of your program. There can only be one message
at a time. Broadcast will be very useful in this program because if you
create a program that will broadcast when the Finch senses light, or is
Figure 7
“tagged,” it can let the rest of the program know about it.
Another important set of blocks are the various “variable” blocks. These blocks help
manipulate any numbers you might have, such as for the light sensors, or to help create accurate
IF-- else statements. They will also be used to count the number of times your Finch is tagged.
Procedure:
You now know how to use Snap to some degree, but most of what you’ll learn will
simply come from using it. Feel free to experiment with Snap, and try to get an idea of how Snap
works. Keep in mind, however, what you need to do with this program in order to make it work.
Let’s open up the document. Make your way to the link where you downloaded this file
(http://www.cs.appstate.edu/ret/labs/finch/studentindex.html).
Download the .XML file under Laser Tag. Once you’ve
downloaded the document, click on “Import…” under the
Figure 8
“Page” tab on the top right (Figure 8). From there, navigate to where you downloaded the .XML
file to and click on the file.
Once you’ve done that, your screen should look similar to this:
Figure 9
Time to get started. The program you’ve been provided with has some code already on it.
Your job is to build on this code, and, when you’re done, check it. To help you get started, here’s
a list of what currently exists in the program, and what’s left that you need to do.
In the Program:




An unfinished block that will turn the Finch to the right when not tagged.
The “Detector” block: it reacts when light is shined on it, and should let
the other blocks know.
Unfinished Broadcast system.
Unfinished “Tag Counter” system
You need to:





Fill in all the green hexagon blocks that are missing information.
Create blocks that will turn the Finch
Create the necessary variables.
Create the necessary broadcast messages
Set up the light detector for the Finch Right Light Sensor.
Error Testing
So you’ve typed up some numbers and dragged some blocks. Good work!
However, you need to be sure your Finch will operate correctly no matter the
circumstances. Let’s run the Finch through a few tests to test this.
First off, make sure your Finch can turn in every direction easily. In a dark room,
click whatever keys you assigned in your program to move your Finch. If you find
something that isn’t to your liking, try to connect it to what you think might be the
problem in the code. For example, if your Finch isn’t turning fast enough, considering
changing the numbers in the “Move Finch Left: () Right: ()” block.
Secondly, check that the light sensors are working properly. There are several
aspects of this where the code could be faulty. The first test will be to test if the light
sensors work properly. Under the “Control” tab, make sure
that “Message” is checked. This will show, in real time,
what the most recent Broadcast message was. Using this,
check if the program is operating correctly when it detects
light by shining a flashlight into its sensors. Also, the “Tag Counter” should increase by
one, and shouldn’t increase multiple times in one time.
Another part of checking your sensors involves making sure your Finch doesn’t
move when tagged. This is fairly easy to check: simply shine the sensors with a light in a
dark room, and then attempt to move the Finch with the program. If your program is
working properly, it shouldn’t move, and should show that it’s been tagged. Now, test if
it moves when you “tag” it, and then immediately take the light away. If your Finch is
able to move immediately, there is a flaw in the program.
Repeat the steps above to find errors every time you change code: you don’t know
how exactly the whole program will be affected by one small change. Finding errors and
bugs can be a slow process, and the best trait you can possess for it is patience. If the first
fix doesn’t work, try again until you get the results you’re looking for. Remember, your
Finch must also follow the criteria previously stated.
Assessment:



What did you find the most interesting regarding this activity?
Would you be interested in exploring similar programming activities?
Were the Finch Robots interesting and useful?
Lab designed by Grayson Fenwick