Required Python Skills: Creating and running a program; importing a library; printing text to the screen; accepting user input and storing it in a variable
Resources available for teachers. Login/Get Access
This Finch is a small robot designed 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!
The picture below shows the features of the Finch robot. In this lesson, you will learn to make the Finch move forward and backward. Future lessons will introduce more features of the Finch.
To use the Finch in Python, you must import the relevant library and declare an object that represents the Finch. This is shown in the sample code below. In addition, you should import the time module. You will use the sleep() function in this module to pause the program to give the Finch time to move.
The Finch object contains the methods that interact with the Finch. In this activity, you will use the wheels() method to make the Finch move. This method requires two parameters. The first parameter controls the speed of the left wheel of the Finch, and the second controls the speed of the right wheel. Both parameters must be between -1 and 1. For example, the method call below sets both wheels to move forward at full speed.
To move the Finch forward, you must turn the wheels on, pause the program, and then turn the wheels off. An example program is shown below. The sleep() function takes a single parameter that is a number of seconds. To stop the Finch, you set the speed of both wheels to 0.
At the end of every Finch program, you must call the close() method to close the USB connection to the Finch. Otherwise, you will not be able to connect to the Finch the next time you run a program.
Create a new file named “FinchForward.py” and try out the program shown above. It should make the Finch move forward for 1 second.
Try changing the time that the Finch should move. Can you make the Finch move forward for 5 seconds?
Write a program that makes the Finch move forward, then backward, then forward, and then backward again. The robot should pause for half a second between each movement.
Write a program that moves the Finch at five different speeds. The Finch should move for 4 seconds total.
Write a program that asks the user for the Finch speed and then moves the Finch at that speed.
Write a program that asks the user how many seconds the Finch should move and then moves the Finch forward for that number of seconds.