LEGO Cube robot

Faster than peeling off stickers · January 2017

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?

How it works

Fair question. 2 LEGO Minstorms NXT modules, controlling 6 motors, a cheap webcam and a Java desktop application. And some programming skills.

  • Scan the cube
  • Build string of 54 characters representing the cube
  • Run string through solving algorithm
  • Convert solution to work with mechanical setup of our robot (4 sides instead of 6)
  • Convert further into seperate motor rotations
  • Send solution to the NXT modules

Which results in solving any cube in on average 12 seconds.

Scanning the cube

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!

Solution

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

Input: lbrdurdulffffrrblfbrdufubbrrrdldulfruflllbubuddfdbdulb

Output: U2 F' R2 U' D R U' L2 D2 L U' B U2 F L2 D2 L2 F' B2 R2

Conversion

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

Motor rotations

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

zmove 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
R2rotate right 180°
F'rotate front 90° counterclockwise → move front/back away → reallign front → move front/back to cube
xmove 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.