Lesson 1 – Moving and Turning

Python Concepts

Importing a library, declaring an object, using object methods

Teacher Materials

Get Access

The Finch is a robot designed specifically for students learning computer science. You can write programs to move and turn the Finch, light up its beak, and collect information with its sensors. As you write programs, you will be able to test your programs with the Finch in the real world!

Finch robot 2.0 with 7 output features highlighted: the wheels, the beak LED, the tail LEDs, the LED array, the buzzer, the marker holder, and the plastic brick adapter.

Importing the Finch Library and Declaring a Finch

First, connect to the Finch in the BlueBird Connector, and then open a new file in Python. Make sure that this file is inside the BirdBrainPython folder that contains BirdBrain.py. To use the Finch in Python, you must import the Finch class from the BirdBrain library. A library in Python is a collection of Python code that you can use in your program, and the Finch class contains the methods that you will use to write programs that use the Finch.

from BirdBrain import Finch

Next, declare an object that represents the Finch. This line of code gives your Finch a name, in this case “bird,” and tells the program that it is Finch.

bird = Finch()

Moving Forward and Backward

Once you have declared a Finch object, you can use methods to make the Finch do different things. For example, the setMove() method makes the Finch move forward or backward. This method takes three parameters, or pieces of information, that you will put inside the parentheses.

bird.setMove('F',10,50) 'F' is the direction parameter, which can be 'F' or 'B'. 10 is the distance parameter, which is in centimeters. 50 is the speed parameter, which must be between 0 and 100.

All of these parts are shown together in the sample program below. This sample program will move the Finch forward 10 cm at 50% of maximum speed. You can use the # sign to add comments to your program. Comments do not affect how your program works, but they make it easier for other people to use your code (and for you to remember what it does).

from BirdBrain import Finch # Import Finch library 
bird = Finch() # Declare Finch object 
bird.setMove('F',10,50) # Move forward 10 cm at 50% speed

Exercise 1

Name your file FinchMoveTurn.py and try out the sample code shown above (remember to save the file within the BirdBrainPython folder). Try out other values for the distance and speed parameters.

To add more movements to your program, just use setMove() again. In Python this is often referred to as calling the method. This program calls the method setMove() twice to make the robot move forward 25 cm quickly and then back 25 cm slowly.

from BirdBrain import Finch # Import Finch library bird = Finch() # Declare Finch object bird.setMove('F',25,100) # Forward 25 cm quickly bird.setMove('B',25,30) # Backward 25 cm slowly

Exercise 2

Write a program that makes the Finch move forward, then backward, then forward, and then backward again. The robot should end 15 cm behind where it started.

Turning the Finch

Turning the robot is very similar to moving the robot forward or backward. Use the setTurn() method to turn the Finch. 

bird.setTurn('R',90,50) 'R' is the direction parameter, which is 'R' or 'L'. 90 is the angle parameter, which is in degrees. 50 is the speed parameter, which must be between 0 and 100.

Exercise 3

Write a program that makes the robot turn left in a full circle and then right in a full circle. The two turns should be at different speeds.

Exercise 4

Write a program that makes the Finch move in a square and return to where it started. 

Exercise 5

Draw a simple picture with the Finch. You can place a marker through the hole in the Finch to draw your picture on a large sheet of paper. We highly recommend using a brush tip marker with the Finch. These markers work well. If you use a marker with a harder tip, the friction of the marker may make your drawing less accurate.

Exercise 6

Create a simple maze using cardboard or masking tape. Then program your Finch to move through the maze!

Back to Top