MASS STEM WEEK 2020
How to Train Your Robot
Programming Activity Guide
TABLE OF CONTENTS
PROGRAMMING GUIDE
How to Train Your Robot
Intro to Robot
INTRO TO ROBOT
Get to know your robot’s features.
INTRO TO ROBOT
Driving
To have the robot move forward or backward,
Turning
To have the robot turn, use the turn blocks. The amount of turning that it takes to turn 90 degrees depends on the surface your robot is on.
Challenge #1: Use the move and turn blocks to have the robot drive across the floor.
Go Further: Figure out how to make the robot drive in a shape. Can you make a square? What about your favorite shape?
INTRO TO ROBOT
Forever Loop
In the Control category you have blocks that can make your robot repeat things. To repeat something forever, place code inside the forever block.
Green Flag and Red Stop
Use the green flag and red stop sign above the stage to start and stop your program.
The when green flag hat block in Events detects when the green flag is clicked.
Challenge #2: Use a forever loop to make the robot dance around the floor
Go Further: Add in sound and music blocks to make it more fun! What sounds go with your robot’s shape driving?
INTRO TO ROBOT
Conditionals
Conditionals allow you to run one set of code if something is true, and another set otherwise. Put the conditional in a forever loop to check it continuously.
Sensor Blocks
Our robot can detect when it is on a dark surface and when objects are in front of its distance sensor.
Challenge #3: Use a conditional and a sensor block to keep the robot on its driving mat.
Go Further: Use the headlights to have the robot signal what it is going to do. (Green = go and red = stop?)
To avoid something, try moving backward.
INTRO TO ROBOT
Buttons
You can also use the ‘when button pressed’ hat blocks to make the robot respond to having its buttons pressed.
INTRO TO ROBOT
Repeat Loops
In choreography, sometimes you want something to happen a certain number of times, you can use repeat loop to set a specific number for loops.
Pump Up the Music
What’s dancing without a little music? Switch to the ‘Sounds’ tab to record a sound to play while the robot dances.
Challenge #4: Choreograph a robot dance.
Go Further: Use the ‘when button pressed’ block to trigger the robot to start dancing.
INTRO TO ROBOT
Challenge #5: Make a robot skit.
Robot Behavior
Check out this short robot skit. Then, use all of the different blocks you learned about to create your own skit.
PROGRAMMING GUIDE
How to Train Your Robot
Intro to Programming
(no robot)
INTRO TO PROGRAMMING
Moving a Sprite
To have the robot change its position, you can use the move blocks in the Motion category.
Turning a Sprite
To have a sprite turn, use the turn blocks. One block turns clockwise while the other turns counterclockwise. You can enter the number of degrees you would like your robot to turn.
Challenge #1: Use the move and turn blocks to have the robot sprite drive in a square.
Go Further: Figure out how to make the robot drive in another shape, like a hexagon. What shapes do you like?
INTRO TO PROGRAMMING
Forever Loop
In the Control category you have blocks that can make your robot repeat things. To repeat something forever, place code inside the forever block.
Green Flag and Red Stop
Use the green flag and red stop sign above the stage to start and stop your program.
The when green flag hat block in Events detects when the green flag is clicked.
Challenge #2: Use a forever loop to make the robot dance around the stage.
Go Further: Add in a play sound (Sound) or say text (Looks) block to make it more fun!
INTRO TO PROGRAMMING
Conditionals
Conditionals allow you to run one set of code if something is true, and another set otherwise. Put the conditional in a forever loop to check it continuously.
Sensing Blocks
Our robot sprite can tell if the mouse is touching it or not using the touching block.
Challenge #3: Use a conditional and Sensing block to have the robot avoid the mouse.
Go Further: What should the robot do when it’s near the mouse? Run away? Chase it?
Running Away
To avoid something, try moving backward.
INTRO TO PROGRAMMING
Repeat Loops
In choreography, sometimes you want something to happen a certain number of times, you can use repeat loop to set a specific number for loops.
Pump Up the Music
What’s dancing without a little music? Switch to the ‘Sounds’ tab to record a sound to play while the robot dances.
Challenge #4: Choreograph a robot dance.
Go Further: Mix up the dancing and moving blocks with a Sensing block. What should your robot dance to?
INTRO TO PROGRAMMING
Challenge #5: Make a robot skit.
Robot Behavior
Watch this short robot skit. Then, use all of the different blocks you learned about to create your own skit.
PROGRAMMING GUIDE
How to Train Your Robot
Animal Recognition Project
ANIMAL REC
Project Challenge: program your robot to respond to seeing images of cats or dogs.
One response could be having the robot sprite change into a cat or dog depending on which animal it sees.
ANIMAL REC
Getting Started
First, you need to train your Teachable Machine Image Project.
Go to the Teachable Machine website, click on ‘Get Started’ and begin a new Image Project.
ANIMAL REC
Training Your Model
Name your two classes ‘Cat’ and ‘Dog’ and add example images for the classes.
We’re using images from Google Drive, but you can also take images with your webcam.
Click on ‘Train Model’ button and remain on the page until the model is finished training.
ANIMAL REC
Exporting Your Model to Scratch
To add your model to a Scratch project, click the ‘Export Model’ button.
Click ‘Upload my model’ and copy the URL that’s created.
ANIMAL REC
Adding Your Model to Scratch
In Scratch, paste your model’s URL into the use model block.
Click the use model block once to load your model. When it’s ready, the status indicator should turn into a green checkmark.
Using Your Model in Scratch
When the model has loaded, the Teachable Machine blocks will update with the label names. Use the when blocks to program what happens when a cat or dog is seen.
ANIMAL REC
Camera Not Working?
You can also classify costume images on sprites or backgrounds.
You can draw or upload a new Sprite or Background to classify.
Just remember that if you want your model to recognize drawings of cats, you should train your model with drawings.
We removed this function so that students can use text, audio, and video TM models.
ANIMAL REC
Common Problems
Solution: Turn off your camera on Zoom and then refresh the Teachable Machine page.
ANIMAL REC
Common Problems
Solution: Change your site settings to allow use of your camera and mic on the website.
ANIMAL REC
Go Further:
PROGRAMMING GUIDE
How to Train Your Robot
Command Recognition Project
COMMAND REC
Getting Started
Open the Scratch website and scroll down to the Text Classification extension.
To create a new model, click on the ‘Edit Model’ button.
Click the ‘Add A Label’ button to create a new category. Name it ‘Drive’ and populate it with at least 5 examples. The more examples, the better.
COMMAND REC
Robot Commands
We’re going to start with three commands: Drive, Dance, and Speak. Drive will make the robot do a square, Dance will make the robot start dancing and playing music, with Speak the robot will greet you.
Use the text matches block to classify text that you type or input from a user.
The ask and answer blocks from the Sensing category can be used to get user input. Notice, they are both blue.
COMMAND REC
Hearing Your Program Speak
The Text Classification category also has blocks that allow you to transform text into speech that will come from your computer. The speak and ask blocks.
Having Your Program Listen
The ask block will speak a question and then listen for a response. Whatever you say will be saved in the answer block. Notice, they are both green.
If the ask block is empty it will listen without asking a question first.
COMMAND REC
Common Problems
Solution: Make sure the ask and answer blocks are properly paired. If you use the BLUE ‘ask’ block use the BLUE ‘answer’ block.
CORRECT
INCORRECT
COMMAND REC
Go Further:
PROGRAMMING GUIDE
How to Train Your Robot
Useful Scratch Tips
PROGRAMMING GUIDE
How to Train Your Robot
Middle School AI and Ethics
SAVING A PROJECT
As you are working on your incredible Scratch projects, it is important that you occasionally save your progress.
Click the “File” button at the top left of the page.
In the dropdown, click the “Save to your computer button”
Name your project and save it on your Desktop or somewhere you can find it later.
LOADING A PROJECT
You can pick up where you left off on your project by loading a Scratch project you saved to your computer or Google Drive.
Click the “File” button at the top left of the page.
In the dropdown, click the “Load to your computer button”
In the File Explorer that pops up, look for the .sb3 file that contains your project
Click ‘Open’ to load it into Scratch.
SAVING TO GOOGLE DRIVE
As you are working on your incredible Scratch projects, it is important that you occasionally save your progress.
Click the “File” button at the top left of the page.
In the dropdown, click the “Save project to Google Drive”.
If you are saving a new project, the page will prompt you to enter a project name.
AUTHORIZING AI BLOCKS
The first time you save or load to Google Drive, you gave to authorize AI Blocks
Note: this screen pops up because we cannot verify the AI Blocks page, but we want users to be able to open programs shared with their Google account.
Advanced
Go to mitmedialab.github.io (unsafe)
AUTHORIZING AI BLOCKS
Last step,
Check the boxes to give AI Blocks permission to:
Press ‘Continue’
LOAD FROM GOOGLE DRIVE
Click the “File” button at the top left of the page.
To pick up from where you started on a previous project…
In the dropdown, click the “Load project from Google Drive”
LOAD FROM GOOGLE DRIVE
All of your Scratch projects will show up in the file picker. Click on the project you want to open and press ‘Select’.
RECORDING THE STAGE
A great way to share the experience of your project is to make a video of it. You can easily record snapshots of your work.
Press the ‘Record’ button at the top of the stage to begin capturing video.
Execute your project as normal. When you are done, click the ‘Stop’ button to end the stage recording.
After you press ‘Stop’ you can save the video file (.webm) on your computer or Google Drive.
You can use a site like ezgif.com to turn your video into a GIF!
SPRITES
1
Add new sprites from the library or upload your own photos here.
Click on a sprite to edit its code.
Different sprites can add personality to your project.
BACKDROPS
3
Add new backdrops from the library or upload your own photos here.
Use Look blocks to change the backdrop in your code.
You can add new backgrounds to make your project more interesting.
COSTUMES
Use the costume editor to prepare your sprites to handle different situations.
2
Use Look blocks to change your sprites’ costumes in your code.
There are many tools that you can use to change the colors and shapes in a costume.
SOUNDS
1
Add new sounds from the library or record your own
Use Sound blocks to control sounds in your code.
Don’t forget to add sounds to make your project more engaging.
PROGRAMMING GUIDE
How to Train Your Robot
AI + Ethics Curriculum