1 of 47

MASS STEM WEEK 2020

How to Train Your Robot

Programming Activity Guide

2 of 47

TABLE OF CONTENTS

3 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Intro to Robot

4 of 47

INTRO TO ROBOT

Get to know your robot’s features.

5 of 47

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?

6 of 47

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?

7 of 47

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.

8 of 47

INTRO TO ROBOT

Buttons

You can also use the ‘when button pressed’ hat blocks to make the robot respond to having its buttons pressed.

9 of 47

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.

10 of 47

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.

11 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Intro to Programming

(no robot)

12 of 47

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?

13 of 47

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!

14 of 47

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.

15 of 47

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?

16 of 47

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.

17 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Animal Recognition Project

18 of 47

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.

19 of 47

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.

20 of 47

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.

21 of 47

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.

22 of 47

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.

23 of 47

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.

24 of 47

ANIMAL REC

Common Problems

  • There was an error opening camera in Teachable Machine

Solution: Turn off your camera on Zoom and then refresh the Teachable Machine page.

25 of 47

ANIMAL REC

Common Problems

  • Camera does not appear in Scratch.

Solution: Change your site settings to allow use of your camera and mic on the website.

26 of 47

ANIMAL REC

Go Further:

  • Add code to control your robot
  • Train your model to recognize more animals
  • Add sounds and animations to your project
  • Turn your project into an educational game to help kids learn their animals

27 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Command Recognition Project

28 of 47

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.

29 of 47

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.

30 of 47

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.

31 of 47

COMMAND REC

Common Problems

  • The robot doesn’t seem to be responding to user input (whether voice or text)

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

32 of 47

COMMAND REC

Go Further:

  • Add code to control your robot
  • Train your model to recognize more commands
  • Use nested if statements for a more complex interaction

33 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Useful Scratch Tips

34 of 47

PROGRAMMING GUIDE

How to Train Your Robot

Middle School AI and Ethics

35 of 47

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.

36 of 47

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.

37 of 47

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.

38 of 47

AUTHORIZING AI BLOCKS

The first time you save or load to Google Drive, you gave to authorize AI Blocks

  • Select the account you want to save projects too

  • On the warning pop up, click the “Advanced” link toward the bottom

  • Click ‘Go to mitmedialab.github.io’ to finish verifying the app

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)

39 of 47

AUTHORIZING AI BLOCKS

Last step,

Check the boxes to give AI Blocks permission to:

  • See Scratch projects shared with your Google Drive
  • Save Scratch projects to your Google Drive

Press ‘Continue’

40 of 47

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”

41 of 47

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’.

42 of 47

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!

43 of 47

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.

44 of 47

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.

45 of 47

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.

46 of 47

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.

47 of 47

PROGRAMMING GUIDE

How to Train Your Robot

AI + Ethics Curriculum