Tutorial: HuskyLens + micro: Maqueen Lite (4.0) Intelligent Transportation Project Based on Makecode
In this project, I intend to combine HuskyLens with the micro: Maqueen Lite (4.0) to simulate the situation of intelligent transportation(innovative services relating to different modes of transport and traffic management and enable users to be better informed and make safer, more coordinated, and 'smarter' use of transport networks), therefore to show how the AI vision sensor could make the robot car ‘intelligent’ based on micro: bit, which is a great extension example of the micro: Maqueen Lite (4.0) for you to refer. In this project, the robot car could make different responses when recognizing tag and color. The program platform will be Makecode.
However, micro: Maqueen Lite (4.0) still has limitations in this project while micro: Maqueen Plus doesn’t. For instance, there is no original metal platform to hold HuskyLens, and the battery consumes quite fast when HuskyLens is combined and so on. So although I’ve used Lite here to experience how it can spark with artificial intelligence, I still recommend using micro: Maqueen Plus for a better experience.
Program Effect: The robot car keeps line tracking to imitate the car driving on certain roads in the real world. In reality, the car needs to stop, slow down, and do other different actions when meeting signs and traffic lights. Thus, in the project, the robot car could be designed to make different actions when recognizing tags and colors. For this project, when HuskyLens detects the tag, the robot car will stop, then start line tracking again at the same speed. After that when HuskyLens detects the color, the robot car will slow down to half speed then restore. This flow will continue forever and you could change actions if you want.
Bill of Materials
1 x micro: bit
1 x Metal Mount Platform(optional)
1 x CR123A rechargeable Li-ion battery - 3.6v
1 x Pure Color Block
1 x Printing QR Code Tag (examples are as below)
Note: At the very beginning, being compatible with HuskyLens seems not the main concern for micro: Maqueen Lite (4.0), therefore in this project, HuskyLens tends to have high battery consumption thus the robot car would have a short running endurance around 10 minutes. So I’m very happy to witness DFRobot iterating Lite into Plus. Hence, if you do have a running time required for this project, you might want to replace micro: Maqueen Lite (4.0) with micro: Maqueen Plus. Meanwhile, you could also try 3xAAA Battery Holder which could extend the running time a little bit.
Step 1: Hardware Settings
To start with, we need to set the hardware at their right conditions therefore for us to run the program once coding finished. For this project, HuskyLens and micro: Maqueen Lite (4.0) should be set, connected, and assembled. Remember to set your HuskyLens’ protocol type as I2C(HuskyLens settings option), otherwise, the robot car couldn’t do line tracking even though you have the right program. The HuskyLens Firmware Version supporting this project should be above 0.4.6 (except 0.4.9). For connecting and assembling HuskyLens and micro: Maqueen Lite (4.0), please view below.
Connection Diagram: HuskyLens sensor uses the I2C connector. Please pay attention to the cable sequence. Do not connect it wrongly or reversely.
Part 1: micro: Maqueen Lite (4.0) Assembly
You could view the ‘Easy to Build in 60s’ part on the official product page for micro: Maqueen Lite (4.0) assembly here.
Part 2: HuskyLens Assembly
HuskyLens sensor has its bracket structure, you could use 2 screws to assemble HuskyLens and its bracket.
Part 3: Metal Mount Platform Assembly
Before assembling HuskyLens with micro: Maqueen Lite (4.0) together, you need a platform like the one in micro: Maqueen Plus to hold HuskyLens steady on the robot car. Thus, you need to purchase additionally 2 x M3 * 50 Hexagonal Standoffs, 2 screws, and a metal mount platform from micro: Maqueen Mechanic as shown in the image below,
However, there are two choices instead of purchasing a metal mount platform:
1. 3D print or laser cut one metal mount platform, the drawing is attached below,
2. Use HuskyLens' brackets together with 2 M3 * 50 Hexagonal Standoffs to directly install it on the robot car as below. Attention should be paid to connect HuskyLens' sensor cable first, otherwise it will be difficult to put in later.
However, there are 2 possible limitations with this approach:
(1) HuskyLens' camera angle will be much higher compared to using a metal mount platform, therefore there will be a further distance against the object, which will make it harder for recognition.
(2) The space between micro: bit and HuskyLens' brackets will be quite narrow so the sensor cable must be connected first, and it will be entwined.
Step 4: Fix HuskyLens to micro: Maqueen Lite (4.0)
Now only 2 screws are needed to fix HuskyLens to micro: Maqueen Lite (4.0), and HuskyLens can adjust various angles.
Step 2: Learning and Recognition
After settings, because we want the robot car to respond to color and tag in the project, so we need HuskyLens to learn one color and one tag and recognize them first.
For tag learning: Switch HuskyLens to tag recognition function to learn the tag as ID 1.
For color learning: Switch HuskyLens to color recognition function to learn the color as ID 1.
Notice: although both of the tag and color are learned as ID 1, they correspond to different functions, so there are no worries for repetition. The expected results should be the same as above.
Step 3: Software Settings
After done with hardware, we need to have the right program for the hardware to realize the project effect. Before coding, plug-ins of HuskyLens and micro: Maqueen Lite (4.0) should be inserted first so we could directly code them to respond in the project. Open Makecode, and choose ‘Extensions’ on the left side to enter the search interface.
For HuskyLens: Copy and paste https://github.com/tangjie133/pxt-huskylens, then click to search and add.
For micro: Maqueen Lite (4.0):
Type ‘Maqueen’ directly, then click to search and add.
Step 4: Program Design
Finally, we could start to design the program. First, the whole program link and graphical blocks are listed in the program example below for you to have a general idea and reference.
Now let’s do the coding step by step by following the two steps below.
4.1 Line Tracking Function Coding
Because we need the robot car to do line tracking in the project multiple times, therefore for convenience, we could set line tracking as a function. The idea is to use micro: Maqueen Lite (4.0)’s line-tracking sensor to detect the black line therefore realizing car turning and going straight line. ‘0’ means black line detected, ‘1’ means not.
The logic flow is below,
The details of the program are as below,
The completed line tracking function is shown below,
Note: The reason why we need to use micro: Maqueen Lite (4.0)’s line-tracking sensor to realize line-tracking instead of using HuskyLens’ line-tracking function is because, in the program effect, we need the robot car to keep line tracking all the time while HuskyLens switches to different functions after detecting the tag or color. If we use HuskyLens’ line-tracking function to do line tracking, the robot car would just keep line tracking because HuskyLens could only use one function at a time, thus it couldn’t switch to either tag recognition nor color recognition.
4.2 HuskyLens Recognition Program Coding
Flow Chart Analysis
And now we could start coding the main program. The logic flow is below,
1.First to start, set HuskyLens as I2C to enable line tracking and recognition functions to go together as mentioned before. In this project, tag recognition goes first rather than color recognition, you can change the order if you want. Two variables, ‘TIME’ and ‘SPEED’ are needed for micro: Maqueen Lite (4.0) responding to color recognition and changing the speed of line tracking respectively.
2.Second is designing the response to tag recognition. The robot car should stop for 1 second when detecting the tag and HuskyLens should switch to color recognition. Otherwise, the robot car should keep line tracking. Details could be viewed below,
3.After finishing the part for tag recognition, the other part of the program could be designed, which is the response to color recognition. In this part, the robot car should slow down to half of its speed for 1 second(still keep line tracking) when detects the color, and HuskyLens should switch to tag recognition. Otherwise, the robot car should keep line tracking at the original speed. Details could be viewed below,
Note: For the criteria of color judging condition of width>40 pixels in the program, I’d like to briefly explain it.
I want HuskyLens to detect the color block and make the robot car responds until it gets closer enough to the block, instead of detecting and responding immediately when the color appears in the screen, therefore I need to have statistic criteria for HuskyLens to judge the distance between it and the color block. HuskyLens’ screen resolution is 320*240 as the picture above, width 40 pixel is the width of the recognition box in the center of the screen, which is about one six of the screen width. The bigger the width, the smaller the distance between HuskyLens and the color block. And when the width is bigger than 40, I find it’s bigger enough to show the response effect.
The completed main program flow is shown below,
Step 5: Execution Result
Get a micro: Maqueen line-tracking map, and witness your intelligent transportation robot car comes true! If you don’t have a map, you can make one using black adhesive tape. If your code and settings are right, the HuskyLens+micro: Maqueen Lite (4.0) intelligent robot car will act as what has been mentioned in the program example.
Picture 1: HuskyLens detects the tag ID 1, robot car stops 1s and HuskyLens switches to color recognition
Picture 2: Robot car continues line tracking at the normal speed
Picture 3: HuskyLens detects the color ID 1, robot car slows down its speed to a half(continuous line tracking) for 1s then restores to the normal speed, while HuskyLens switches to tag recognition.
Note: You might find that the robot car seems not doing line tracking when slows down its speed in the 1s after detecting the color block, this is because micro: Maqueen Lite (4.0)’s line tracking sensor is not insensitive at low speeds. So I suggest you use micro: Maqueen Plus instead which has PID regulating to make sure there is still a large torque at low speed to keep the car stable.
Picture 4: Robot car returns to the normal speed and continues line tracking.
The whole Makecode program and demo video examples are attached.
If your programs do not work properly, please check the following points:
(1)Whether you have set your HuskyLens’ protocol type as I2C;
(2)Whether your HuskyLens Firmware Version is proper;
(3)Whether your HuskyLens have learned and recognized the tag and color successfully.
(4)micro: Maqueen Plus is still recommended for this project, I’ve made a comparison table of these two products below for you to refer,
Website sources in this project:
1. micro: Maqueen Plus product webpage:
2. micro: Maqueen Lite product webpage:
3. Program Link: