Energy Harvest | BOSON AI Starter kit for microbit:bit

The Ant Forest in the Alipay app allows users to grow a virtual tree by collecting energy points. Different values of energy will be generated based on their real-life actions every day.

 

 

Can you guess what I am going to do now?

 

HuskyLens is really powerful, let’s use the tag recognition function of HuskyLens to make an energy harvest game!

 

Learning Objectives

 

1. Learn the working principle of tag recognition.

2. Learn to use the tag recognition function of HuskyLens

3. Learn what a random number is

4. Use HuskyLens to make an energy harvest project

 

Preparation

 

Learning Content

 

Principle of Tag Recognition

 

1. What is tag recognition?

 

Tag recognition refers to the technology of effective and standardized coding and recognition of items, which is the basics of informatization. With people's increasing awareness of health and safety, the food industry has increasingly higher requirements on the quality and safety of products (from raw materials, transportation, production, storage, traceability and management). Tag recognition also plays an important role in meeting the needs of companies for product tracking and tracing.

 

Tag recognition technology mainly includes barcode technology, IC card technology, radio-frequency recognition technology, optical symbol recognition technology, speech recognition technology, biometric recognition technology, remote sensing, robot intelligent perception and other technologies.

 

 

2. What is AprilTag?

 

AprilTags is a visual reference system from a UMich project team for AR, robotics and camera calibration. The tag acts as a barcode, storing a small amount of information (tag ID), while also providing a simple and accurate 6D (X, Y, Z, roll, pitch, yaw) pose estimation or the tag.

 

 

3. Differences between AprilTag, barcode and QR code

 

Compared with barcode and QR code, AprilTag is more useful in machine vision, because it can calculate the accurate relative 3D location, direction, and ID through AprilTag. The 3D location in reality world is very useful for machine! AprilTag is usually used in fields like AR, robot, and camera calibration.

 

4. Working principle of tag recognition

 

Edge detection: find out the edge contour in the image.

 

Quadrangle detection: find out the quadrangles in the contour

Decoding: match and check the quadrangles.

 

Demonstration of HuskyLens Tag Recognition Function

 

1. Tag detection

 

When HuskyLens detects a tag, the tag will be automatically selected by the white frame on the screen.

 

 

2. Tag learning

 

Point the "+" symbol at the tag, long or short press the "Learning button" to complete the first tag learning. After releasing the "Learning button", the screen will display: "Press the button again to continue! Press other buttons to end. " To continue learning the next tag, press the "Learning button" before the countdown ends. If you no longer need to learn other tags, press the "Function button" before the countdown ends, or do not operate and wait for the end of the countdown.

 

 

In this project, we are going to learn more tags, so press the "learning button" before the countdown ends, and then point the "+" in the center of the HuskyLens screen at the next tag that needs to be learned, short press or long press the "learning button" to complete the learning of the second tag. And so on.

 

The tag ID is consistent with the sequence of input, that is, the learned tags will be labeled as "tag: ID1", "tag: ID2", "tag: ID3", and so on, and the frame color corresponding to different tags is also different.

 

3. Tag recognition

 

When the HuskyLens encounters the learned tags, a colored frame with an ID will be automatically displayed on the screen. The size of the frame changes along with the size of the QR code tag and the frame will automatically track these QR code tags.

 

 

Project Practice

 

Next, the energy harvest game will be completed in two tasks. First, we must learn to use HuskyLens's tag recognition function, and output random numbers from the recognized results, and then determine whether the collected energy value can be used for energy synthesis by calculating the sum of the random numbers.

 

Task1: Generate energy

 

In the process of the game, the energy values collected are all randomly generated. Therefore, in this step, HuskyLens needs to recognize the AprilTag tag and generate a random number, also the collected energy value.

 

Task 2: Energy synthesis

 

Each AprilTag corresponds to a certain value. When the sum of all energy values is greater than 50, energy synthesis can be performed.

 

Task1: Generate energy

 

Hardware connection

 

 
Program design

 

Function instruction:

 

The HuskyLens sensor needs to learn multiple AprilTag tags and be able to display random numbers from 0 to 9 on the micro:bit matrix screen after the recognition is successful.

 

What is random number?

 

Therandom numberis thenumbertaken from therandom seed.

 

Next, we are going to use ansimpleexample—throwing dice, to understand what a random number is.

 

The dice have 6 sides, andeachside is marked with points: 1, 2, 3, 4, 5, 6. Suppose that we roll 6, then the number 6 is called a random number. The 6 numbers from 1 to 6 are called randomseeds.

There is a randomnumber block"" in MakeCode, where the range of 0~10 is the random number seed, and the number taken from 0~10 is the random number.

 

Flowchart Analysis

 

 

The Sample Program

 

As long as ID>=1, the statements in the loop are always executed; this makes the program moreconciseand avoid repeated judgments.

 

 
Operating Effect

 

In this project, at least one AprilTag needs to be learned, as long as HuskyLens recognizes the learned AprilTag, it will generate a random number ranging from 0 to 9. As shown in the figure, the random numbers generated by the same AprilTag tag are not the same.

 

Task2: Energy synthesis

 

Hardware connection

 

Program design

 

Function instruction:

 

On the basis of the previous project, the function of displaying the sum of energy (Sum of energy) has been added. When the sum of energy>=50, energy synthesis is performed. Meanwhile, the function of re-collecting is also added. Press button A on the micro:bit to clear the display and initialize the energy value and the total energy points.

 

Flowchart Analysis

 

 

The Sample Program

 

 
Operating Effect

 

Every time HuskyLens successfully recognizes a learned AprilTag tag, a random number will be generated and showed on the micro:bit dot matrix screen, and the sum of the calculated random numbers will be displayed on the HuskyLens screen; when the sum of random numbers is greater than 50, energy synthesis is performed, a "heart-shaped" pattern shows on the micro:bit, and the buzzer plays music "power up"; press button A to clear all the displays and start a new round of energy harvesting.

Project Review

 

This project mainly uses the tag recognition function of HUSKYLENNS. Each time HuskyLens recognizes a learned tag, a random number ranging from 0~9 will be generated, then judge the sum of the random number and perform corresponding operations. Do you know where random number is used in daily life?

 

Project Development

 

The energy harvest is just a little game, it is funny when playing with friends. Now, call on your friends and have a competition with them!

 

Game rules:

 

1. The one using the tag recognition function of HuskyLens fewer times wins.

2. The one spending less time wins when the number of times using HuskyLens are the same.

 

   

License
All Rights
Reserved
licensBg
Tags BOSONAI
0