rubiks cube solver

10

Click here to load reader

Upload: brizmar07

Post on 19-Jan-2016

74 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Food      Living       Outside        Play        Technology       Workshop

Rubik's Cube Solverby matt2uy on June 14, 2014

Table of Contents

Rubik's Cube Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro:   Rubik's Cube Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1:   Materials (take picture) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2:   Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 3:   Mechanical Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 4:   Arduino Sketch - Cube Solving Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Step 5:   Python GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 6:   Connecting it all - Serial Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Step 7:   How To Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

Page 2: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Intro:  Rubik's Cube Solver

[Play Video]

So here is a project I've been working on for a while...

This robot that can solve a Rubik's cube using Arduino.

I learned how to solve a Rubiks cube last year, and I was also into Arduino, so eventually I ended up with an idea to make my own Rubiks cube solver.

A lot of people have probably seen the tilted twister design by Hans Andersson:

[Play Video]

I looked around at the existing Rubik's cube solvers, and I liked that design, so I built a similar version of it with (mostly) popsicle sticks, using an Arduino and 2 servos.

My robot takes 20 minutes to enter the cube state and solve.

Step 1: Materials (take picture)Electronics:

- Arduino UNO R3

- 2 servos (I used Hitec HS-311's)

- wires

- USB cable

You can get all of these parts from any robotics store. I got them from canadarobotix.com

Hardware:

- popsicle sticks

- wooden skewers

- thin plywood

- wooden wheel (skewer must fit inside the hole)

- hot glue

- paper towel roll

Software:

- Arduino IDE - (Algorithms in C++)

- Python 2.7+ and Tkinter - (GUI)

- Pyserial

Page 3: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Step 2: ElectronicsWiring up the servos to the Arduino was pretty simple.

- Connect the yellow (signal) wires for the push and rotation servo to pin 6 and 9, respectively.

- Connect the positive and negative wires to the 5v power source and ground. Sometimes the servos had jitters, so I think capacitors could have smoothed out thesignals.

Step 3: Mechanical DesignI looked at a few designs but settled on the Tilted Twister because it only required 2 servos to operate, which wasn't as complex mechanically as other robots such as theCubestormer.

So here's how the mechanism basically works:

1. A platform holds and rotates the cube.

2. The arm pushes and holds the cube.

When I first tried to build the solver, I tried to follow building instructions here:

But I was pretty lazy and didn't follow the instructions, so I made a wooden replica with a few tweaks.

I haven't documented every step of the build process, but I think you can reproduce the tilted twister design with a few tweaks:

1. Slanted sticks to prevent the cube from snagging.

2. To build the arm joints,

- I drilled a hole into ends of the popsicle sticks.

- I cut out 2 cm of a wooden skewer.

- I inserted the skewer into the sticks

- Glued wooden wheels that act as washers on each end.

Honestly building the physical solver was a lot harder and complex than I expected, so if you have any questions on how I built the solver, just ask.

Page 4: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Image Notes1. Side View

Image Notes1. Slants to prevent snagging

Page 5: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Image Notes1. Popsicle stick joint

Page 6: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Image Notes1. Back View

Image Notes1. Front View

Step 4: Arduino Sketch - Cube Solving Algorithm[Code: https://github.com/matt2uy/Cube-Solver]

So basically the code I wrote uses combinations of pushes, holds and platform rotations to apply algorithms to the cube.

There are 3 main parts of my code: the algortihm, GUI (enter cube state) and the serial communications

Let's start with the Arduino sketch. It basically uses algorithms to manipulate the cube colours:

1. There are 6 char arrays represent each face of the cube.

2. Using a basic layer by layer method of solving the Rubik's cube, I made a function, cube_decide(), that goes through each stage or the cube solving process.

3. Within each stage, such as cube_decide_cross() (solving the cross), the program would check for specific locations of colours in the cube, and if an algorithm wasmatched with the condition, cube notation like 'U' (Up) or entire algorithms, like fix_cross_instance_1() would be run.

4. The cube notation and algorithms control the servo functions, such as push_cube() or rotate_one().

Here's a basic overview of the code structure (layers of abstraction):

Cube Decide functions < Cube Algorithms < Cube Move functions < Servo functions < Move Function

One major breakthrough I had was that I actually simulated the cube's movements in the program. The program reassigns the values in the arrays to simulate and cuberotation. This way, the program can simulate the cube move before it physically executes it.

Page 7: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Image Notes1. Main loop

Image Notes1. Cube notation used in the program

Image Notes1. Code structure

Page 8: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Step 5: Python GUII needed a better way of entering the cube state than directly typing them into the Arduino sketch, so I got the idea of creating a GUI from this robot:

Because I'm new to making Tkinter GUI's (Graphical user interface) and didn't want to make one from scratch, I found a tic tac toe GUI here.

Then I turned the 3x3 array of buttons into something resembling a cube and added a few buttons. I also added buttons that would change colour each time they wereclicked. Finally I made 5 more windows that would pop up one after the other, and transfer the colours entered into a local array in the script.

However, I really slapped the code together in a mess, since I simply copy and pasted 6 separate windows, with almost identical functions. Any suggestions on how Icould clean up the code is welcome!

Step 6: Connecting it all - Serial CommunicationsOnce the algorithm in the Arduino sketch and the python GUI were ready, I needed something something that would use the cube state collected from the GUI andtransfer it to the Arduino sketch. After the sketch receives the data, it can put the cube state through the algorithms and physically solve the cube.

To do that, I used a library called Pyserial, which helps my python script communicate with the Arduino over a serial interface.

Basically, this is how I coded the the serial communication:

1. After the cube colours were entered in the GUI in Send_Cube_State.py, I converted the data into a string

2. Used a 'handshake', which in this case the Arduino tells the computer it's ready, then the computer transfers the data to the robot.

3. The Arduino converts the string received into chars, which are assigned to arrays in the sketch.

4. Now that the cube colours have been successfully transferred from the computer to the Arduino, the cube colours can be put through the algorithms and solve theRubiks cube.

Page 9: Rubiks Cube Solver

http://www.instructables.com/id/Rubiks-Cube-Solver/

Step 7: How To UseAfter downloading the project files here: https://github.com/matt2uy/Cube-Solver

1. Plug the Arduino into usb slot.

2. Flash Cube_Solver.cpp to Arduino using the Arduino IDE.

3. Run Send_Cube_State.py on the terminal/command line.

4. Enter the cube orientation as instructed in the GUI.

5. Put the cube in the robot, with the yellow face in front and blue on top, as shown in the picture above.

6. Click 'Send Cube'.

7. Watch:

Related Instructables

Building robotswith RaspberryPi and Pythonby ZRob314

Brain-ControlledWheelchair byjerkey

Raspberry PiRobotcontrolled overBluetooth byZRob314

GUI ControlledLED Matrix byben_k

Rubik's CubeTricks-centerpiece. byPettrocity

Rubik's CubeMania! (Photos)by RadioactvBiohazard

Advertisements

Comments

4 comments Add Comment

 pablo de paris says:  Jun 21, 2014. 2:51 PM  REPLYThis is genious. Not only it works, but it is elegant!

 matt2uy says:  Jun 21, 2014. 7:32 PM  REPLYThank you! Though I don't think it's as elegant as some of the other solvers out there.

 doodlecraft says:  Jun 21, 2014. 10:42 AM  REPLYAmazing, I couldn't do a rubik's cube if you paid me a million dollars and I had years to do it! Haha, great job!