The most famous and frustrating toy brought to you straight from the eighties, the Rubik's Cube. As meticulously peeling off 54 stickers is hard and takes a lot of time, I decided to build and program a robot that solves the cube instead. Much easier, right?
I was very wrong but that didn't stop me. As the Doc always says "If you put your mind to it, you can accomplish anything". I love Back to the Future and a challenge so I set to work! Building, rebuilding, coding and debugging.
And if I set out to do something, I'm pretty focused on succeeding. Which can be very frustrating at times but in the end well worth it. Who doesn't want a LEGO robot solving cubes?
Fair question. 2 LEGO Minstorms NXT modules, controlling 6 motors, a cheap webcam and a Java desktop application. And some programming skills.
Which results in solving any cube in on average 12 seconds.
After scrambling and inserting the cube, you press the big red button. The robot will grab the cube and take a picture of each side. At first I wanted to use some learning to recognize the colour on each sticker. Background lighting proved too much of a dealbreaker, making it impossible to always get a clear distinction between white/yellow or red/orange. So I ended up adding a calibrate button.
Put your robot somewhere, calibrate once and you are good to go until you move your robot to a different location. The parameters from the calibration are stored in a file so no need to recalibrate on every reboot. Great!
The 54 sticker colours are put into a string of 54 letters. This string is then run through the cube explorer algorithm to quickly produce a solution. For example
Output: U2 F' R2 U' D R U' L2 D2 L U' B U2 F L2 D2 L2 F' B2 R2
This solution assumes you can turn any side of the cube. Our robot sadly is limited to turning only 4 sides though, so we have to convert this solution to work with the mechanical setup of our robot.
Converted: z R2 F' x F2 R' L F R' B2 L2 B R' x F R2 B x F2 L2 F2 z L' R2 B2
This converted solution of length 25 results in 74 seperate motor rotations. The first few moves z R2 F' x look like this when broken down in seperate motor commands
|z||move right/left away → rotate front/back 90° clockwise → move right/left to cube → move front/back away → reallign front/back → move front/back to cube|
|R2||rotate right 180°|
|F'||rotate front 90° counterclockwise → move front/back away → reallign front → move front/back to cube|
|x||move right/left away → rotate front/back 90° clockwise → move right/left to cube|
This final conversion is then send to the NXT modules as a series of numbers and the solving can begin.