Recently, we made a all-metal Raspberry Pi robot car integrates mecanum wheels chassis and 5DOF visual robotic arm. We innovate some interesting applications based on Raspberry Pi’s AI power. Introducing MasterPi by Hiwonder.

MasterPi’s chassis is composed of mecanum wheels and driven by four TT motors. Ingenious design of mecanum wheel allows MasterPi to move in all directions and make cool “drifting”. Above the chassis are Raspberry Pi and our developed Raspberry Pi expansion board. For better heat dissipation, we reserve a hole on the chassis for installing the fan and customize hollowed-out covers.

RGB ultrasonic sensor is installed on the front of the chassis, which enables MasterPi to avoid the obstacle smartly. Above the ultrasonic sensor is 5DOF robotic arm with monocular camera and a gripper. MatserPi utilizes OpenCV as vision recognition containing color recognition, object picking and placing after recognition.

To prove the astonishing performance of MasterPi’s synthetic ability,now I will explain the details of how MasterPi fulfill the task of sorting colored blocks while tracking lines.

The whole procedure is recognizing the color of the block and picking up, then call the corresponding position code. Next, it continues detecting the color of line. When first black transverse line is detected, MasterPi will count the number of transverse lines which each one is corresponding to a specific color of blocks. MasterPi will adjust its posture and place the block in designated position. After that, it will switch the vision to move along the line and loop.

The whole program named IntelligentSort has been uploaded on GitHub. Below is the realization logic of program. Firstly, after connecting MasterPi through VNC, copy program to the path /home/pi/MasterPi/Functions. Next, open terminal and enter command “cd MasterPi/Functions/”.

Enter command “sudo python3” and press “Enter” to start.

1.Color Recognition

MasterPi recognizes the color of block.

  • Gaussian filter

Before converting the color space of image from RGB to LAB, reduce the noise of image first. The GaussianBlur() function in the cv2 library is used here for Gaussian filtering of the image.

The meaning of parameters in parentheses is as follow:

The first parameter “frame_resize” is the input image.

The second parameter “(3, 3)” the size of Gaussian kernel.

The third parameter “3” is the amount of variance allowed around its mean value in Gaussian filtering. The larger the value, the larger the allowed variance around the mean; the smaller the value, the smaller the allowed variance around the mean.

  • Binarization processing  

Use inRange() function in cv2 library to binary image.

Take “lab_data[color]['min'][0]” as example. The first parameter “lab_data[color]” in parentheses is the input image. The second parameter “min” and the third parameter “0” are the upper limit and lower limit of the threshold individually. When the color value of pixel point RGB is between the upper and lower limit, the pixel point is assigned a value of 1, otherwise, it is 0. 

  • Erosion and dilation processing

In order to reduce the interference and make the image smoother, process the image with open and close operation.

open() function will erode the image first, and then dilate.

Take the code “eroded = cv2.erode(frame_mask, cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3)))” as example. The meaning of parameters in parentheses is as follow:

The first parameter “frame_mask” is the input image.

The second parameter “cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))” is the structure element or kernel that determines the nature...

Read more »