GETTING STARTED
ROBOTICS
TAKING LEARNING TO THE REAL WORLD
CAPSTONE PROJECT

ACTIVITY: Making a Waste Collector

Making a Waste Collector – Overview

It’s time to write the code for our waste-collecting bot. The waste-collecting robot should stop at a checkpoint, identify the type of waste, follow the path, check whether it has reached the correct destination or not without any crashes, and dump the waste.

Let’s set up your arena like this and place your recognition/number cards at the following places.

In this activity, the objective of our robot will be stopping at the checkpoint, identifying whether the waste is biodegradable or non-biodegradable waste, collect it, following the line to move forward, stopping at the checkpoints and detecting the number cards to check whether it has reached the correct destination for dumping and update the status of the dumping by lighting up the LEDs on it.

The robot will start from just before checkpoint 3, and then it will do line following until it reaches the following checkpoints.

We’re going to train our waste collector bot to differentiate between the two types of waste that we learnt about earlier in this chapter – biodegradable and non-biodegradable; we’re going to use paper as an example of biodegradable waste and a battery as e-waste or non-biodegradable waste.

Once it detects the type of waste, it should dump it at its designated place.

Now let’s write the code using this logic.

Let’s Code

We’re going to use the PictoBlox app to make this script.

Identifying the Type of Waste

Let’s first make the script for detecting the type of waste. Follow the steps below:

  1. Open a new project in the PictoBlox app.
  2. Add a when flag clicked block from the Events palette into the scripting area.
  3. Next, tap the purple-colored Add Extension button in the bottom-left corner of the screen. Then, select the Machine Learning extension to add it to your palette.
  4. Click the Load Model button.
    Load Model Button
  5. A model will open. Paste the link and click the Upload button.
    Load Model
  6. The relevant blocks will appear in the palette when the model is loaded successfully.
  7. Add a turn () video on stage with () transparency block from the Machine Learning palette below the when flag clicked block. on is the default option selected from the drop-down and 0 is the default transparency. We’re going to keep it that way. This block will turn on the camera of your Smartphone. 
  8. Add a wait for () seconds block from the Control palette.
  9. Next, add a wait until () block. Add a not () block from the Operators palette inside the white space.
  10. Add a is identified class from () is () ? block from the Machine Learning palette inside the not () block. The complete wait until () block will ensure that the robot doesn’t perform any action from the script if it doesn’t detect anything.
  11. Now, go to the Variables palette and make a variable named Waste. We’re going to use it to check the type of waste that Quarky detects.
  12. Add a set () to () block from the Variables palette. Waste is selected as the default option from the drop-down. Add a identify class from () block from the Machine Learning palette in the white space. This will set the value of the Waste variable as the ‘class’ of the waste detected by Quarky.

    Now, let’s check whether the waste detected is paper, i.e. biodegradable, or not.

  13. To check if the waste detected is paper, add an if block from the Control palette below the set () to () block.
  14. Add an () = () block from the Operators palette inside the diamond-shaped space of the if block.  Inside the first space, add the Waste variable block. Inside the second space, add a (Paper) block from the Machine Learning palette. This will check if the detected waste is paper or not. If it is paper, then the script will execute the blocks below the if arm.
  15. Below the if arm, add a display matrix as () block and fill the matrix with green colour.
  16. Now to check whether the waste is a battery a.k.a the e-waste, then duplicate the above if arm.
  17. Select Battery from the drop-down into the if arm.
  18. And set the color in the display matrix as () block as blue.
  19. Click the green flag to check the script.

Identifing type of Waste1

Script for the Waste Collector

Follow the steps below to make the script for making Quarky move:

  1. Add a when flag clicked block into the scripting area.
  2. Go to the Sensors palette and add two set () IR sensor threshold to () block below the when flag clicked block. IR-L, i.e. the left IR sensor is selected as default from the drop-down in both the blocks. Select IR-R from the drop-down in the second set () IR sensor threshold to () block and set the threshold value in both the blocks as 1500. The IR sensors will help Quarky to detect the path it is travelling on and plan its route based on the type of waste it detects.
  3.  Go to the Robot palette and add a set parameter F (), T1 (), T2 () block below the second set () IR sensor threshold to () block. Set F as 35, T1 as 35, and T2 as 0.
  4. Now, go to the My Blocks palette and create a block named Identify Waste.
  5. Take the Identify Waste stack block and place it below the set parameter F (), T1, T2 () block.
  6. Add a forever block from the Control palette below the Identify Waste stack block.
  7. Inside the forever block, add a do line following block from the Robot palette. 
  8. Inside the do line following block, add a stop robot block.

    Now, we’re going to define different actions for Quarky based on the type of waste it detects. If it detects paper, then we’ll make it dump it at the location numbered 1 on the track; however, if it detects battery, we’ll make it dump it at the location number 3.

  9. Add an if block below the stop robot block.
  10. Add an () = () block inside the diamond-shaped space of the if block.  Inside the first space, add the Waste variable block. Inside the second space, add a (Paper) block from the Machine Learning palette. This will check if the Waste variable block is paper.
  11. Go to the My Blocks palette and create two blocks names Biodegradable and Non Biodegradable.
  12. Take the Biodegradable stack block and place it below the if arm.
  13. Similarly, create the condition for the Non-biodegradable e-waste. Below is the complete script.

    Waste Collector

  14. Finally, take the Identify Waste hat block and add it in place of the when flag clicked block of the script we made for identifying the waste.

Identify Waste

Next, we’re going to make scripts for the Biodegradable and Non Biodegradable hat blocks.

Dumping the Biodegradable Waste

Follow the steps below:

  1. To detect numbers, we need the Autonomous Driving extension. Add the Autonomous Driving extension from the Extension palette.
  2. Then, Add blocks to turn on the video, setting the threshold, and analyzing the image from the camera from Autonomous Driving palette.
  3. Add an if-else block.
  4. Inside the diamond-shaped space of the if-else block, add an is number () detected ? block from the Autonomous Driving palette and select 1 from the drop-down.
  5. Add a display matrix as () block below the if arm of the if-else block and fill the matrix with white colour as shown.
  6. Below the display matrix as () block, add a stop () block from the Control palette. all is selected as the default from the drop-down. This will stop the entire code from running since Quarky will have reached its destination.
  7. Add a go () at () % speed for () seconds block from the Robot palette below the else arm. Change the speed to 30%.

Bio Degradable

Dumping the Non-Biodegradable Waste

Follow the steps below:

  1. Similarly, Let’s create a script under Non Biodegradable hat block.
  2. Add blocks to turn on the video, setting the threshold, and analyzing the image from the camera from Autonomous Driving palette.
  3. Add an if-else block and inside the diamond-shaped space of the if-else block, add an () and () block from the Operators palette. 
  4. Add two is number () detected ? block from the Autonomous Driving palette, one each in the spaces of the () and () block. Select 2 from the drop-down of the first is number () detected ? block and 1 in the second.
  5. Add a display matrix as () block below the if arm of the if-else block and fill the matrix with white colour as shown.
  6. Below the display matrix as () block, add a stop () block from the Control palette. all is selected as the default from the drop-down. 
  7. Add a go () at () % speed block from the Robot palette below the else arm. Change the speed to 30%.
  8. Finally, click the green flag and watch Quarky work its AI magic!

Non Bio Degradable

Assignment

Before you move on to the next lesson, a small assignment awaits you!

Make a video of the project you made in this activity and upload it to the website.

Submitting the assignment is a must in order to receive the certificate after completing the course.

Follow the steps below to upload your assignment:

  1. First, you need to choose the video file, thus click on Browse.
  2. Select your video file.
  3. And click the Upload button.

Good luck!

×
×

Cart