Some people like crossword puzzles, some are serious sudoku ninjas, but [Andrea Favero] likes to keep himself sharp, by learning coding and solving control problems, and that is something we can definitely relate to. When learning a new platform, it’s a very good idea to have a substantial project or goal in mind, and learn what is needed on the way there. [Andrea] chose to build an autonomous Rubik’s cube solver, and was kind enough to document exactly how how to do it, and we’re glad of it!
Working in python with OpenCV, [Andrea] uses the methodology by [Oussama Barkouki] to process each face image and convert it into a table of the colours of individual facelets. The basics of that, are first to convert the image to grayscale, then use a gaussian blur to denoise the image. Edges are identified using the canny algorithm, the result of which is then dilated and passed into a contour detector. The contours are sent into a cunning filter that identifies square contours, and those the wrong size are filtered off. What you’re left with are the outlines of the actual coloured facelets. Once you have a list of squares, these can be used to form image masks, and thence select the average colour from each square. The colour is then quantised and stored as a labelled colour from the standard Western Rubik’s cube colour scheme. Finally, once all face images are captured and facelets colours identified, the data are passed into a Rubik’s cube solving algorithm developed by [Hegbert Kociemba,] a guide to which is available on the speedsolving site. The result of the solving step is a sequence of descrambling moves, in the move notation developed by [David Singmaster]. Fascinating stuff, if you ask us!
All of the above can be prototyped on a PC, but [Andrea] wanted to learn about Raspberry Pis. Part of the fun was installing and configuring a Pi4, with all the necessary dependencies. The hardware was constructed from plywood, and a load of 3D printing. (All STLs are available in the first link) Following the (incredibly detailed) build guide should be straightforward enough. A Pi4/2Gb model with PiCamera was found sufficient (good luck finding one! Maybe try rpilocator?) with a stepper motor for cube rotation, and a pair of servos, one for operating the lid/camera mount, and a second to kick the cube around a second axis. The beauty of this simple, elegant approach is that it can handle a standard unmodified cube (ok, a slightly sanded one) — unlike some of the crazy speed-solving builds we’ve seen — it isn’t the fastest cube solver we’ve seen, but it is one of the coolest.