PIPER MAKE

EDUCATOR GUIDES


YOU ARE HERE

Base expedition

Mission 14 of 13

Base expedition: Mission 14 of 14

Pose Detect


Advanced

1 hour

Grades 3 - 8

MISSION OBJECTIVE

Learn about Machine Learning (AI), a subset of AI focusing on machines and very specific tasks.

Now that Piperbot and Pip have PAL up and running, they are ready to explore. Surprisingly, they've discovered that the ship's controls are damaged and can't be used on the flight deck. PAL, however, has a new idea and suggests that using a camera as a sensor, he could steer the ship based on the movements of Piperbot's head so that they could get going using the principles of Machine Learning.

View student interface at make.playpiper.com
MISSION CHARACTERS

Piperbot

Pip

PAL
MISSION MATERIALS

Computer with USB port and Chrome or Edge browser
Piper Make Base Station or Starter Kit

MISSION RESOURCES

Learning Goals

  1. Students will understand the basic principles of ML.
  2. Students will gain a basic understanding of how ML works.
  3. Students will understand using the camera as a sensor.
  4. Students will build hardware that interacts with an existing ML model to track facial expressions.
I WILL BE ABLE TO...
  • Understand how machine learning algorithms train on data sets to recognize patterns
  • Use an ML algorithm to detect my pose from video input

Learning Activities

The following sections will contain step by step instructions for ELA and ELD extensions directly related to this Mission. Adjust the directions to fit your ELA and ELD standards.

Grades 3-5

ELA Extension: Recognizing Piperbot Display the three character images below (Piperbot, Pip, and a creeper from Minecraft).


Ask students to share how they recognize the difference between the characters. They may say, “I’ve seen them before” or “It looks like a mouse.”

Discuss how artificial intelligence would recognize the difference between the characters - it would learn from seeing multiple images of the same character, and look for patterns. Ask students what are the patterns that tell us whether it is a robot, mouse, or creeper? Students should be able to describe particulars including colors, and the specific grid position of features like eyes, nose, mouth. How is pattern recognition the same and different from how humans perceive?

Now, have students consider how these images are very simple (64 pixels) compared to say, a self-driving car recognizing a pedestrian or a cyclist. When asking a computer to perceive photos or even video, the model will need an immense amount of examples to learn from.

ELD Extension: Pose Estimation Person Keep the code and build for the Pose Detect mission open. Have students click on the Camera Icon to view the pose estimation overlaid onto the webcam. Students should back up and stand in front of the camera and watch which body parts map to each dot. Students can also reference the drop down menu from the “camera (nose) pose (X position)” block to see which body parts pose detection works with.

Students should use these resources to draw and label a person with pose detection dots mapped onto each body part, including the list below. Students can draw the person in any pose. (This page has an example image for multiple poses: https://www.tensorflow.org/lite/examples/pose_estimation/overview)

  • Nose
  • Left Eye
  • Right Eye
  • Left Ear
  • Right Ear
  • Left Shoulder
  • Right Shoulder
  • Left Elbow
  • Right Elbow
  • Left Wrist
  • Right Wrist
  • Left Hip
  • Right Hip
  • Left Knee
  • Right Knee
  • Left Ankle
  • Right Ankle

Grades 6-8
ELA Extension: COCO Animals COCO, or Common Objects in Context, is a large-scale object detection, segmentation, and captioning dataset. Students can browse the Coco image dataset at https://cocodataset.org/#explore

Choose 1 animal and click “Search” to view images tagged with that animal.

Students should answer the following questions about their animal search.

  • How many images did your search produce? (This will display right under the search bar.)
  • How many different poses or angles did you see of your animal? Describe at least 3 of the different poses (ie, a horse as a logo on a sign and a horse pulling a cart.)
  • If you were going to teach what a zebra is, do you think it would be easier to teach a human or to teach an artificial intelligence? Why?
  • This dataset has a total of 2.5 million labeled instances in 328,000 images. Why do you think a machine learning model needs so many images to be trained effectively?

ELD Adaptation: COCO Animals COCO, or Common Objects in Context, is a large-scale object detection, segmentation, and captioning dataset. Students can browse the Coco image dataset at https://cocodataset.org/#explore

Choose 1 animal and click “Search” to view images tagged with that animal.

Students should answer the following questions about their animal search.

  • How many images did your search produce?
  • What are the features of your animal:
    • How many legs?
    • What colors?
    • How do you recognize this animal?
  • What tells the computer which part of the images is an animal? (The outlines, or bounding boxes)

Career Connections

Software Developer: Salary $127,260/yr
Electrical Engineer: Salary $127,260/yr
Data Scientist: Salary $103,500/yr

Hardware Diagram




Code Diagram




Tutorial Steps

Pose Detect

We used up all of the buttons in our other adventures, and now only one button is left.

How will we fly the ship with only one button?
Maybe we can use a sensor already on the ship, like the camera!
Can we program PAL to read the camera?
Yes! If we do that, we could steer the ship with my face!
Your face? That's silly!
Yes, my face! PAL has a model called Pose Detect. The Pose Detect model can output the position of my eye or my nose or my elbow or my...
OK, OK, I get it! So, how do we start? And what is a model?
Click NEXT.

PAL, the ship's Artificial Intelligence (AI for short), can do some really smart things.

One thing that PAL has been trained to do is recognize a person in a video feed like the one from your computer's camera and find the position of your eyes, nose, ears, wrists, elbows, etc.

Cool, right?
How did PAL learn to do that?
PAL was trained to do that. How? One way that computer scientists train AI is by showing it A LOT of pictures that have been labeled.

During one training, PAL was shown pictures with each joint and body part labeled so PAL could learn to find them in any new picture or video feed.
AI's are smart, but that's because they are trained using pictures that are labeled by hundreds or even thousands of people!
When an AI can use its past training to understand where something is in a new picture or video that it's never seen before, that's called Machine Learning.

When the training is done, all of the AI's memories are downloaded and saved to a file. That file is called a model, and it can be used by many other computer AIs!
So PAL was trained on Earth, and all the ships exploring other planets use the same models?
Exactly! Our ships all have a PAL, and they all use the models that were trained back on Earth.
Click NEXT.

Hey Pip, do you want to see what happens when PAL uses the Pose Detect model?
Yeah! Of Course!
We'll have to build a little bit of code to see the Pose Detect model in action.

Using blocks from the Chip and Sensing menus, build the blocks below:
Wait a few seconds. Your computer might ask for permission to use your camera. If it does, then you'll have to give it permission for this to work.

You should see a red camera Icon in the top-right corner of your screen:
Go ahead and click on that red camera icon!

What do you see? Try moving around!

Not working? Try refreshing your browser and coming back to this tutorial.
That's so cool!
Click NEXT.

OK! I bet this will be close to the hardware we built last time when we got PAL working again.
Gather the parts listed below:
We will use the Red, White, and Green LEDs because they will match the navigation lights on our ship!
Click NEXT.

Let's start by building a basic LED circuit. Use the diagram below to get started.

Remember that you need to use a Resistor when you connect an LED and that the long lead (anode) should be connected to the GPIO pin - in this case, GP15:
Awesome, let's build the rest of the circuit! Red will represent the Port (left), white will be the Bow (center), and green will be the Starboard (right).
And since we have one button left, we can use that to make the ship go!
Use the diagram below to build the rest of the circuit:
When your circuit is finished, plug it into your computer and click NEXT.

How will we use the output from PAL?
Good question! Let's build a short program that we'll use to train a model for steering the ship.
PAL will be able to output a number based on where it thinks our nose is. We'll use the nose because it's in the middle of your face. ;)

We already have some blocks, so grab a few more blocks from the Loops, Chip, and Sensing menus to build the code you see below:
Once you build the code, try it out!

Click CONNECT, select your Pico, and then click START.

Next, click on the CONSOLE tab.
Nothing is happening.
Press the Pushbutton you added to the Breadboard.
OK - it's just a number. That's kind of boring.
5
Exactly! That's where your nose is! Hold down the button and slowly move your head from side to side!
Oh, I get it! Now what?
Click STOP. Then, click NEXT.

Now we need to collect a number that represents when we lean our face to the left, when our face is in the center, and when our face is leaning to the right.
A List is a good place to save our left, center, and right numbers. Since lists must be stored in a variable, let's create one!

Click the Variables menu, then click the Create variable button. Name your new variable "position list."

Once you create the variable, grab the set position list block and place it into your code:
Next, grab a create list with block from the Lists menu and place it into the set position list block. Then, fill your new block with "0"s using blocks from the Values menu:
Great! You're ready to train your ship steering model.
Click START. Make sure the CONSOLE is still open. Shift your head to the left and then press your button.
It's a negative number!
Type that number into the first value in the create list with block (your number might be different):
Should we do this with our face in the center?
Yes! For the middle number and with your face centered, press your button to see what it is, then record it as the middle number. It's probably a small number, maybe even zero.
One more! Shift to the right and press the button.
Remember, your numbers won't be exactly the same as Pip and Piperbot's, and that's okay. When you're finished, you should have three numbers in your list:
Once your three numbers are recorded, click STOP. Then click NEXT.

Now that you have trained your model, it's time to use it.

We are going to make one addition to our code to see how well it works.

We have our list, and when we move our nose, we want to find the closest number from our list to where our nose is.

In the Lists menu, find the in list find closest block. Drag it into the print block that's already in your code. Then add the position list block from the Variables menu:
Make sure the dropdown on the in list find closest block is set to "index," then try out your code by clicking START.
Now, when I move my head from side to side, the console only shows 1, 2, or 3.
Exactly! Our model reads an approximate value and outputs an exact value that we can use to steer our ship.
Great! So, how do we connect this to our steering? It says 1 when my head leans left, 2 when it's in the middle, and 3 when I lean right.
To connect this to our steering, we'll have to make some changes and add a few things to our code. We also need to turn on these LEDs using those numbers.
Click STOP, and then click NEXT.

First, we only want the ship to move when we press the button. So we need to change the wait block to an if...else block:
And instead of printing the number from the in list block, we need to save it to a new variable.

Open the Variables menu and click the Create variable button to make a new variable. Name it "steering". Then, use the set steering to block to capture the in list block's value:
Remember that the possible values of the "steering" variable are 1, 2, or 3. That means we can use an if _ = _ do block to choose what to do based on that value:

Click on the blue gear icon. Select the else if block and attach it under the if block on the right half of the bubble. Do this a second time. Now click the blue gear once more to hide the menu again.
Is that all we need to do?
Not quite. We have just a couple more steps, and then we're ready to roll! I mean, fly!
Right-click on the _ = _ block and choose Duplicate twice. Place each into the empty else if space.

Grab the "steering" variable and place it to the right of the equals sign in the _ = _ blocks. Don't forget the Duplicate trick!

Next, place the zero block in the Values menu to the right of the equals sign. Change the zeros to 1, 2, and 3 in that order.
This is starting to make sense! Let's make it light up those LEDs!
Click NEXT.

If we want only one LED to glow at a time, we need to turn one on and the other two off.
Could we do that in a function?
That's what I was thinking!
Grab a to do something block from the Functions menu. Rename it "turn to port". Then, place three turn pin blocks in it.

Remember that the Port is on the ship's Left side, and the Red LED represents it. The Red LED is connected to GP15:
Right-click the to turn to port block and select Duplicate to make a copy. Name the new copy "turn to center" and change the ON and OFF values so GP14 is ON.

Make another copy named "turn to starboard" and set GP13 to ON. Then make a final copy named "stop" that turns all the LEDs off:
We are so close!
Now, we need to call those functions at the right time. When our steering value is 1, the ship should turn to port, so add the turn to port block from the Functions menu into the if do block.

Then, add the rest of the functions for the 2 and 3 values.

Finally, add the stop block into the final else position:
One last thing - change the wait time on the repeat forever loop to 0.25 seconds:
Are we ready to fly this ship?!
Click START. Then, click the EXPLORE tab. Press the button and move your head from side to side to steer!

Once you can successfully fly the ship, click STOP and DISCONNECT. Then, click NEXT.

We did it! Now we can go to all the locations we planned to and install all those sensor modules!
Click EXIT to return to the menu and start your next coding challenge.

Blueprint

OPEN IN BLUEPRINT VIEWER  DOWNLOAD

Have an different version? Look for more information on the Support Page.

Troubleshooting Tips


Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly.
View Support Docs or Contact Support
EXPANDED RESOURCES

Term Glossary


Circuit A conductive path for the flow of current or electricity.

Power The current or flow of electric charge and voltage.

Microcontroller An integrated circuit containing a microprocessor with memory and associated circuits.

Variables A value that can change depending on conditions or information passed to the program. A storage location with a symbolic name used to keep track of a value that can change while a program is running (similar concept to using X and Y in an algebraic equation). Variables are not only numbers; they can also hold text, including whole sentences (strings) or logical values (true or false).

Input Device A hardware device that sends data to a computer, allowing interaction and control.

Output Device A piece of hardware that converts information into a form humans can sense and understand.

View Full Glossary

Standards Alignment