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 is to:
- Start at the checkpoint
- Identify whether the waste is biodegradable or non-biodegradable waste
- Follow the line to move forward,
- Stop at the checkpoints, and detect the number of cards to check whether it has reached the correct destination for dumping.
- Update the status of the dumping by lighting up the LEDs on it when reached.
The robot will start 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 learned 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:
- Open a new project in the PictoBlox app.
- Add a when flag clicked block from the Events palette into the scripting area.
- Next, tap the purple-colored Add Extension button in the screen’s bottom-left corner. Then, select the Machine Learning extension to add it to your palette.
- Click the Load Model button.
- A model will open. Paste the link and click the Upload button.
- The relevant blocks will appear in the palette when the model is loaded successfully.
- 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.
- Add a wait for () seconds block from the Control palette.
- Next, add a wait until () block. Add a not () block from the Operators palette inside the white space.
- 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.
- 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.
- 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.
- To check if the waste detected is paper, add an if block from the Control palette below the set () to () block.
- 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. Add a (Paper) block from the Machine Learning palette inside the second space. 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.
- Below the if arm, add a display matrix as () block and fill the matrix with green color.
- Now to check whether the waste is a battery a.k.a the e-waste, then duplicate the above if arm.
- Select Battery from the drop-down into the if arm.
- And set the color in the display matrix as () block as blue.
Check the script till now:
- Paper Waste:
- E-Waste: