### 6-1 Introduction to Finch Robots

Lesson 6.1: Introduction to Finch Robots

Learning Objectives:

The Finch robot is a powerful tool for computer science education. It is the product of a four-year study at Carnegie Mellon University’s CREATE lab and is designed to support an engaging introduction to the art of programming.
• Students will learn what Finch Robots are.
• Students will learn how to program Finch Robots with Scratch.
• Students will create algorithms to solve certain kinds of logic puzzles.

Do Now:
Watch:

Programming Finch Robots with Scratch

The Finch robot is a powerful tool for computer science education. It is the product of a four-year study at Carnegie Mellon University’s CREATE lab and is designed to support an engaging introduction to the art of programming.

We will be using Scratch to program the Finch robot and learn about its various features. We will write interactive programs making use of the Finch’s ability to move and sense its environment (obstacles, light, and temperature).

Getting Started with Finch (slides)

Go to “More Blocks”

Control Blocks

 MovementSets the power to the left and right wheels. The range is -100 to 100. LightSets the color of the Finch’s beak. The R, G, and B arguments control the intensity of the red, green, and blue elements in the Finch’s beak. The range is 0 to 100 for each color. Buzz SoundPlay’s the Finch’s buzzer with a sound of the frequency specified for the time specified. Range is 20 to 20,000 for frequency.Note: 1,000 ms is equal to 1 second SpeakSoftware that comes with the Finch also allows the programmer to control computer speakers so as to play synthesized speech, wav files, or musical notes.

Sensor Blocks

A SENSOR is a device that detects and responds to some type of input from the physical environment.

 TemperatureReturns the value of the finch’s temperature sensor in Celcius Obstacle DetectionThese are boolean or predicate blocks, returning true if an object i s 1” to 4” from the sensor and false otherwise Light DetectionReturns the intensity of light hitting the left or right light sensor. The values are in a range from 0 to 100 where 0 is total darkness and 100 is saturation of the sensor. AccelerometerReturns the Finch’s acceleration values. The primary use of the accelerometer is to detect the direction of gravity, so as to know how the Finch is oriented (flat on the ground, upright, etc). It is also possible to detect spikes in acceleration caused by tapping or shaking the Finch. OrientationReturns the current orientation of the Finch. Possible values are: Level, Beak_Up, Beak_Down, In_Between, Left_Wing_Down, Right_Wing_Down

Activity Part 1: I’m the Finch. Explore What I Can Do!

In this activity we will explore various features including movement, obstacle detection, beak coloring, and temperature and orientation status.

Emergency Stop

Before running a new script, you will want to press the “space bar” to stop the previous script execution.
 Most  industrial equipment will incorporate an emergency STOP button for SAFETY.  Press “space bar”  to stop all scripts immediately.Safety first!!

Subroutine Next

Create subroutines to re-use code and avoid repeating yourself.

 A SUBROUTINE is a program script that you plan on using over and over.  The subroutine script  is assigned to a single block and given a name likeNEXT.  Anytime you use the block NEXT the full subroutine will run in in its place. Tips: Under “More Blocks” click “Make Block” to create your “define” block

Variable

Use variables to store values that you are going to refer to more than once or that you might want to vary the value of.
 Variables can be set to specific values anywhere in your project.  When that variable NAME (ex: SPEED) is used in your script the NAME is replaced by the variable’s CURRENT VALUE (ex: 75).You will use these blocks later in scripts you write for your program. Tips: Under “Data” click “Make a Variable” and create the following variables: Here’s a close-up of the CURRENT VALUE for the TEMP variable:

Move Feature

Make the finch move!

What is the difference between the “Speak” and “Say” commands?

What happens if you change wait to 2?

Now try removing the SPEED variable and put in different values for the left and right wheels:

 left right 0 100 50 100 -100 100 -100 -25

Obstacle Detection Feature and Boolean Functions

Program the finch to detect obstacles!
 A SENSOR is a device that detects and responds to some type of input from the physical environment. The specific input could be light, heat, motion, moisture, pressure, or any one of a great number of other environmental phenomena.  The Finch has a left and right infrared sensor for “eyes”.  The Finch left or right obstacle sensor “returns” a value of 1 for “true or yes” and a value of 0 for “false or no” Examine the WAIT command block.  If the Finch does NOT sense a left OR right obstacle what is theBOOLEAN value “returned to” the WAIT command?  What is the value needed by the WAIT command to move to the next step of the script?Are you still glad you created the NEXT subroutine?  This is a GLOBAL subroutine since it works in any script that uses it within the whole project.Is SPEED a GLOBAL variable?

Beak Coloring Feature

Make the beak change colors!
 Tri Color LED’s have three LED’s in one housing.  RED -GREEN and BLUE.  The input for each LED can range from 0 (no brightness) to 100 (full brightness)How did we generate what appears to be YELLOW?Where did the RED and GREEN get mixed to appearYELLOW?What color will  RED and  BLUE appear to be?  Go ahead and try it out.Now GREEN and BLUE?Now RED - GREEN and BLUE? Looking back, do you see an opportunity to create another subroutine to clean up your code? Perhaps try the following:

Temperature & Orientation Status Feature

Check the status of the Finch’s temperature and orientation.
 Two more sensors on the Finch are the ones for temperature and one orientation.To sense temperature the Finch uses a Thermistor.  A Thermistor is a resistor that changes its resistance depending on how hot or cold it is.  This change in resistance is converted by the Finch microcontroller into a value representing degrees centigrade °C.To sense orientation the Finch uses an Accelerometer.  The Finch accelerometer senses the pull or force of gravity along the 3 axes of the Finch’s body.  Top to Bottom, Front to Back and Left to Right.  The Finch microcontroller converts the 3 accelerometer signals into 7 different output values representing  the orientation of the Finch.  The control block Finch Orientation is set to:LEVEL, UPSIDE_DOWN, BEAK_UP, BEAK_DOWN, RIGHT_WING_DOWN, LEFT_WING_DOWN and IN_BETWEEN.  NOTE: The ( _ ) symbol is written as or pronounced UNDERSCORE.  Try moving the Finch around and see if you can find the right position for each of the 7 Finch Orientation values.

Congratulations!! You now know FINCH basics.

Activity Part 2: Detect Light

In this activity, the finch’s beak will turn red if its left light sensor is sensing the flashlight, else,

if it’s right light sensor is sensing the flashlight, its beak will turn green, if neither light sensor senses the flashlight, it will turn blue.
 #1 If Finch left light detects the flash light, its beak turns red. This conditional logic is implemented with an if-else block. The ifcondition is a comparison expression       Finch left light > 25which evaluates to either true or false, depending on what the sensor reading is.Note that the numerical value 25 was chosen to be bigger than what the Finch currently sees: 11 with its left eye and 9 with its right eye. Depending on where your Finch is right now, these readings could be different.#2 Now, it’s your turn to write the rest of the program!On the else branch, write code to test the Finch’s right eye.What you want to accomplish is another conditional! In simple words, the logic goes like this:If  the Finch right light is sensing the flashlight, then  turn its beak green; else, make it blue.

Solution code:

Activity Part 3: Teach Scratch About Finch Orientation

In this activity, the finch will light up different colors depending on its orientation.

# Start with an if-else block.Get this block from the Operators category. This is a test for equality or comparison block. If we plug 2 numbers in it, it will tell us true if the numbers are equal ORfalse if the numbers are not equal.All hexagon shaped blocks will evaluate to a boolean value: true or false.From the More category, get the Finch Orientation block and snap it into the first plug of <[] =[]>. In the second plug type in Level.When is this comparison true? When is it false?Let’s command the Finch to turn its beak green if its orientation is level. And let’s command our Scratch sprite to set its color effect to Green (use 50 to get a green color effect). Finally,  point the Scratch sprite to right (direction 90).Place the if-else into forever and attach forever to when green flag clicked. Add the when space key pressed event handler to stop the program for the Finch.Test out the program!Next step is to program the else branch. We want this time to test if the Finch orientation is Beak_Up. If it is, we’ll do something very similar. Instead of green, let’s use red to signal this orientation. And the sprite will point in the up direction.Now’s it’s your turn!Add one more if-else block to programIf Beak_Down then program similar behavior as before.Else … choose to do whatever you want. Your creativity has no limits! Notice that if you are here, the choices left for the Finch orientation are: In_Between,Right_Wing_Down, and Left_Wing_Down.

Activity 4: Detect Obstacles and Count Steps

This code has two if blocks. The first if block reports true if there is no obstacle. In that case, the Finch moves forward for one tenth of the second. The Sprite copies what the Finch does and makes 2 steps.

The second if block reports true if there is an obstacle. In that case, the Finch stops, buzzes for half a second and waits for half of the tenth of a second and moves backwards for 1 second. The Sprite copies what the Finch does and makes 20 steps backwards.

These two tests and their actions repeat forever.

# Apply what you’ve learned so far! Write a scratch script that makes your finch do something whenever it encounters another finch (say a greeting, flash a color, do a dance, it’s up to you). Since finches can’t differentiate between obstacles and other finches, using the left/right obstacle block is alright. Program keyboard controls for your finch (ex. forward arrow to move forward, right arrow to turn) so you can manually control your finch on the “dance floor”.The only requirement is that the finch should keep count of how many obstacles/finches it encounters. At the end of the project period, we will place all finches in a circle and watch them interact. Have fun!

Ċ
Michelle Cernuto,
28/04/2016, 11:16