Home Products Shop Articles Applications Learning Zone About Us

  • Up


















  • Rubik Cube Solving Robot

    Submitted by William M., Malta

    Introduction
       This robot was designed to solve the famous Rubik Cube using a number of PC Control boards and a large stepper motor, as well as a large number of LEGO parts, together with a software program that I wrote in Clarion.

    Facts about the Rubik Cube
         Erno Rubik invented the cube in the spring of 1974 in his home town of Budapest, Hungary. He was an inventor, architect and Professor of Architecture. He wanted a working model to help explain three-dimensional geometry, and ended up creating the world’s best selling toy.
       More than 300 million cubes have been sold worldwide. If all the cubes were placed on top of each other, it would be enough to reach the North Pole from the South Pole.

        In May 2007, Thibaut Jacquinot of France became the first person to complete the cube in under 10 seconds in open competition, setting a world record time of 9.86 seconds.
        The current world record for a single solve was set in June 2011 at the Melbourne Winter Open competition in Australia by Feliks Zemdegs with an incredible time of 5.66 seconds.
       The number of possible combinations of the Rubik Cube is 4.3 quintillion or 43,252,003,274,489,856,000 or 4.32520 x 1019.
        In 2010, Tomas Rokicki, Herbert Kociemba, Morley Davidson, and John Dethridge gave the final computer assisted proof that all cube positions could be solved with a maximum 20 face turns.

    Solving the Rubik Cube
        The Rubik Cube can be very frustrating and may seem next to impossible to restore to its original configuration. However, once you know a few algorithms, it is very easy to solve. The method described in this article is the layer method: we first solve one face of the cube, then the middle layer, and finally the last layer. I used Dan Brown’s algorithm (not of the book Da Vinci Code fame) to solve the cube.
    See YouTube videos of Dan Brown's solution:-
    Part 1 http://www.youtube.com/watch?v=HsQIoPyfQzM
    Part 2
    http://www.youtube.com/watch?v=IW_BBp3FPMQ

        It is a misconception of many that to solve the cube using a computer, one has to enter all the possible combinations. Imagine entering 4.3 quintillion combinations into the software code. Just to put you into the right frame of mind, if I had to do just that, entering one combination every second into my computer algorithm, it would take me 1.37 trillion years to do so.
        The solution to solving the Rubik Cube therefore is not to enter all possible combinations, but rather finding a solution that will solve the cube, irrespective of the combination generated. And such a solution exists; indeed there are a number of solutions. I chose to use Dan Brown’s algorithm, which is by far not the fastest method, but it gets me there.
        Dan Brown’s algorithm is not a computer algorithm; it is an algorithm to solve the cube in the physical world. In my project, I had to transcribe Dan Brown’s physical movements into computer code. It would be pertinent to note that the entire software algorithm I wrote in this project is self coded; not one line of code is borrowed/copied from any other algorithm. Indeed, my algorithm (based on the logic used by Dan Brown) to solve the cube alone is around 7000 lines of code, and that excludes the coding to translate the solution into actual singular robot moves in the physical world.

    Software

    The software part of this project can be broadly divided into four parts namely:-

    1. the part to create the visual images of the Rubik Cube on screen to enable me enter the randomized mix of the cube in the physical world into the computer program prior to finding the solution;
    2. the part to set default parameters to control all robot movements, as well as routines to test robot movements;
    3. the part to find the solution to the randomized combination;
    4. and finally, that part of the software to send out the signals to the robot in the physical world to turn the cube, or the bottom layer only, on its x- axis, and to flip the cube on it y-axis. These are the signals I am sending to the Stepper Bee to drive the stepper motor (x-axis rotation), to one Motor Bee to drive the servo motor (clamp), and to the two Motor Bees to drive the electric motors(y-axis flip).

    Hardware
    The parts purchased from PC Control Ltd in this project were:-

    1.   a Stepper Bee + board to control a stepper motor;
    2.  a large 12V 4-phase stepper motor with a holding torque of 5 Kg/cm, capable of turning in a clockwise or anti-clockwise direction, with up to 200 steps to complete one full revolution (360 degrees). I needed to use a high torque stepper motor to turn the Rubik Cube clockwise on its x-axis as my first attempt to use the smaller PC-Control stepper motor did not provide the necessary torque.
    3.   a Motor Bee board to control one LEGO servo motor that controls the clamp;
    4.   a Motor Bee board to control two LEGO electric motors needed to flip the Rubik Cube on its y-axis.

    Other parts used were:-

    1.   Two power supplies (6V to power the Motor Bees and 12V to power the Stepper Bee + board )
    2.   Numerous LEGO parts
    3.   LEGO Servo Motor to lift/release the clamp
    4.   Two LEGO electric motors to flip the cube

    Randomizing the cube in preparation for a solution
        In the image below I would have entered the colours of each of the six faces of the cube (Up, Front, Down, Back, Left and Right faces) after a randomized mix of the cube in the physical world. Once done, I can proceed to solving the cube using my software.


    Finding the solution
       The software solves the cube and writes each and every move to a ‘Solution File’ which is then used to send the signals to the robot to perform the necessary moves.

    In the image below is part of the solution as generated by the software.



                   All possible robot movements

    Outputting the signals to the robot
        To begin with, the possible robot movements are shown in the table above.  As you can see from the table, there are no Back face moves, ie. I am only using the Up, Front, Down, Left and Right faces. This is because in Dan Brown’s algorithm he omits Back face moves.

    The key robotic moves are:

    1. Clamp On/ClampOff (see images below). The clamp is part of the LEGO structure that is controlled by one of the two Motor Bees that drives the LEGO servo motor that lifts or lowers the clamp. Its function is to clamp (Clamp On) the cube’s top layer and middle layer to prevent them from turning when the stepper motor is activated to trigger a clockwork movement of the bottom layer only of the cube.
      It is lifted (Clamp Off) when the instruction given to the robot is to turn the entire cube (all three layers) clockwise together.
          

    2. Bottom layer only clockwise turn by the stepper motor, with Clamp On (see image on the right). Turns could be ¼ face turns, ½ face turns or ¾ face turns. This can only be achieved with the clamp lowered over the top and the middle layers, locking them in place to prevent them from turning with the bottom layer of the cube. All cube moves (R, RP, L, LP, U, UP, F, FP, D and DP) require that the face that had to be turned in a clockwise or anti-clockwise direction had to be in the bottom layer to enable the stepper motor to do the face turn. It is to be noted that a ¼ turn anti-clockwise direction is equivalent to a ¾ turn clockwise direction.
        This movement replicates the situation where I would be holding the top and middle layer of the cube with the fingers of my left hand, whilst turning the bottom layer with the fingers of my right hand.

    3. Full cube clockwise turn by the stepper motor, with Clamp Off (see image on the right). Again, as above, face turns could be ¼ face turns, ½ face turns or ¾ face turns. Unlike above, however, the clamp is lifted to enable the stepper motor to turn the cube completely (all three layers) in a clockwise direction.  Again, it is to be noted that a ¼ turn anti-clockwise direction is equivalent to a ¾ turn clockwise direction.

    4. Full cube Flip in a clockwise direction using two LEGO electric motors to perform the flip (see images below).

        You will notice that on either side of the Rubik Cube is an LEGO electric motor with a protruding armature. With the Clamp raised, the left LEGO Motor kicks in. The armature pushes the cube and tilts it in a clockwise direction. The left LEGO motor is set into rewind and reverses the armature to its starting position. Once done, the right LEGO motor kicks in. Its armature pushes back the tilted cube back into an upright position. The right LEGO motor is set into rewind and reverses the armature back to its starting position. The cube has been tilted into a 90 degrees clockwise direction. To tilt the cube into a 180 degrees direction, the flip must be done twice. To tilt the cube into a 270 degrees direction, the flip must be done three times.

    PC-Control Parts Used






    Conclusion
        I have been writing software since 1981. The Rubik Cube Solver was perhaps the most difficult and challenging software I ever wrote. As I said previously, my intention was not to write code to solve the cube in the lowest number of moves possible; I was just happy to be able to use my software to solve the cube.

    See my Rubik Cube robot on YouTube by clicking on this link
    http://www.youtube.com/watch?v=-oYLL6kr1nM

       The Rubik Cube Solver was also given coverage on the Maltese Television programme Gadgets. This is the link:-
    http://www.youtube.com/watch?v=5Su-I9oZHDg
        Unfortunately it is in Maltese, save for a few words in English here or there, but if you view this video you will get a very good idea of this project.

    I also invite you to see my other projects on YouTube. The following are the links:-
    Piano Robot at http://www.youtube.com/watch?v=FqA9s9MpU68
     
    Piano Robot on the Malta Television programme Gadgets at
    http://www.youtube.com/watch?v=X7QcGljX1X8

    Robot Realtime Weatherman at http://www.youtube.com/watch?v=tLrNp5sJBlo

    Solving 9-Letter Word at http://www.youtube.com/watch?v=nErjb7vO3cQ








    PC Control Ltd:  All articles are publish as submitted in good faith but we do not accept any responsibility for the authenticity or content of these articles. Any article breaching copyright will be removed from this website as soon as we are made aware.


    Featured
    Items

     
    Automator
    Lowest Cost
    Control Board


    ConText
    Control by Text


    Security Camera:
    A new article
    by Brian M



    Microscope Control:
    A new article
    by Harald K. A.



     Use our boards with
    Raspberry Pi.


    Pi-Mobile:
    A new article
    by Ava L (UK)