Rubik’s Cube Robot
Origin of the project
This project originated one day when Soldier B came to the company with a magic cube and was bumped into by the boss.
"So you can turn magic cubes! Then making a magic cube robot should be a piece of cake for you!" The boss said, and Soldier B was assigned the project leader.
Feature description
This project uses 86Duino One、86Duino Enjoy and Maixduino to implement a Rubik's Cube robot.
Preparation materials
- One 86Duino One
- One Maixduino
- 8 RoBoard RS-1270 servos
- OV2640 camera module
- One magic cube (this project uses the Wild Goose Magic Cube)
- 2.4-inch TFT LCD screen (optional)
- WS2812 LED light bar (with 18 LEDs)
- 7.2V battery
- 3D printer
- Screws, nuts, and wires
Hardware setup
The project agency referred to OTVINTA's Magic Cube Robot, and the STL files of the required printing materials are as follows:
Cover Parts STL Download
It is recommended that cover parts be printed in white or black to avoid light issues affecting subsequent color recognition.
Please refer to the OTVINTA website for the detailed assembly steps of the robot, it should be noted that before installing the gripper, the motor position of the control gripper must be initialized to 1100us and the gripper must be installed vertically, and the motor controlling the rack must be initialized to 2100us and the slider should be attached to the edge of the robot's body, as shown in the figure:
— Server Initialization Program —
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Here's how to assemble the shelves that hold the 86Duino and Maixduino together from bottom to top:
First, fix the part plate_holder in the bottom motor position of the robot and lock the screws, and place the part plate_bottom on top, as shown in the figure:
Next, fix the 2 joint1 and joint2 parts at the four corners of the plate_bottom, pay special attention to whether the installation direction is consistent with the picture, and connect the 4 pillar_short:
Install the 4 joint3 parts on the pillar_short, and install the plate_86duino parts and lock the 86Duino, you can compare the position of the screw holes on the parts with the direction of the 86Duino is correct, it is recommended that the 86Duino green power terminal block is facing the right side of the picture, and the RC servo connector is facing the left side of the picture, and then connect the wiring of the servo and LED light strip, and install the 4 pillar parts, pay attention to the wiring as far as possible The left and right sides of the plate_86duino should not block the camera view.
Install joint1, joint2, joint4, join5 on the pillar and plate_maixduino on it, also pay attention to whether the orientation is consistent with the picture:
Lock the arm_left, arm_right and Maixduino, glue the LED strip along the two arm grooves, then embed the OV2640 camera into the plate_maixduino and connect the Maixduino's feet to the 86Duino, plate_maixduino have two holes cut for the wiring to pass through.
Cover the cover on top and glue the cover_lock to the cover in alignment, and finally lock it with the robot.
Next, the circuit connection method is introduced, as shown in the figure below.
The 86Duino shares the same power supply as the Maixduino, so it can be operated by powering the 86Duino with a 7.2V battery, but it is important to note that the LED strip and motor may generate large instantaneous currents, so make sure that the current on the power supply side can reach at least 10A.
Preferences
Please refer to the MaixPy tutorial website for detailed explanations of the environment settings of Maixduino.
Explanation of the program
Maixduino supports Micropython, which supports most of the Python 3 syntax and openMV libraries, and is used for color identification of magic blocks in this project, while 86Duino is used to calculate magic block solutions and motor control, the process flow is as follows:
— Identified the center of the three squares of a square—
From the perspective of mechanism design, the position of the magic cube is fixed, but in the actual installation, there will inevitably be errors that make the magic cube unable to face the center of the camera, and this function findCubeCenter() allows the magic cube to correct the position of the center block within a certain error.
— Exposure Compensation —
In order to perform color recognition, the camera must be able to take pictures with the same color information under any light source, in addition to the top cover to keep the light source fixed by the LED strip, the exposure compensation is also applied here, and the function exposure_compensation() automatically corrects the exposure time of the camera based on the brightness of the four red paws.
— Collect HSV color information on six sides of the square —
After extracting the six-sided image, the mode of the color information of each square is taken as the color representing the square, and the color information is transferred to the HSV color space for subsequent color identification. HSV stands for Hue, Saturation, and Value.
— Color Identification —
Since white (and black) are in different dimensions from other colors, they need to be identified first, in this case, the 9 squares with the lowest saturation are identified as white, and the rest of the colors are identified by hue order. Finally, the recognition results are sent back to 86Duino to calculate the process of solving the magic cubes.
— Rubik's Cube Move Symbols :
There are 6 types of faces in the magic square, which are above U (UP), D (DOWN), L (LEFT), R (RIGHT) to the right, F (FRONT) and B (BACK), and all faces are positive with a 90-degree clockwise rotation towards the face, so the following six moving symbols are defined as the rotation mode represented by:
U |
D |
L |
R |
F |
B |
You can turn it clockwise, of course, you can turn it counterclockwise, and the definition is 90 degrees counterclockwise with the apostrophe prime(').
U’ |
D’ |
L’ |
R’ |
F’ |
B’ |
Also, define the number 2 to represent a rotation of 180 degrees.
U2 |
D2 |
L2 |
R2 |
F2 |
B2 |
It is worth mentioning that since the mechanism only has four claws that can rotate U, D, R, L, if you want to rotate F and B, the program will first turn the entire surface of the magic cube up or down, so that the action F or B becomes U.
— God's Number —
For any random puzzle solving problem, if the algorithm must be able to find a solution less than a certain number of steps, the algorithm is called God's Algorithm, and the number of steps to solve the puzzle is called God's Number, and in 2010, it was proved that the God's Number of magic blocks is 20. The current God's algorithm is Kociemba Algorithm (or Two-Phase Algorithm), and the detailed algorithm steps can be described in Cube Explorer, and I will not repeat it here, this project uses the Kociemba algorithm implemented by the author Muodov, who also made his own magic cube robot Meccano Rubik's Shrine.
— Motor Parameter Adjustment —
Adjust the following parameters to make the Magic Block moving symbols rotate normally, namely:
1. DELAY_TIME: Waiting time for motor rotation (ms)
2. CLAMP_UPPER_BOUND: The gripper is turned to the PWM position of 90 degrees
3. CLAMP_LOWER_BOUND: The gripper is turned to the PWM position of 0 degrees (i.e., the initialization position)
4. SLIDE_UPPER_BOUND: The slider moves into the PWM position of the edge of the robot (i.e., the initialization position)
5. UD_SLIDE_LOWER_BOUND: The PWM position when the up and down sliders are moved to the clamping magic cube
6. RL_SLIDE_LOWER_BOUND: The left and right sliders are moved to the PWM position when the magic cube is clamped
1 2 3 4 5 6 |
|
If there is still a slight error in individual motors, you can use the setOffset() function to fine-tune it.
Presentation of results
— DEMO —
Related information
[1] This project Github
[2] STL Institutional Documents for this project
[3] OTVINTA
[4] Magic Robot Author: Muodov's Github
[5] Magic Block Algorithm Reference Site
The main page of the self-built amusement park
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.