Rubik's cube Robot solver

I feel now pretty confident to finish this project ;)

Should I succeed, my long range plan is to remove the webcam and PC and use a single Android phone as both a camera and a computing device This will then become a 100% autonomous machine

**It’s python’s time folks ** :slight_smile:
Python is a nice language when it’s comes to produce small utilities and middlewares
For the moment, I just implemented the “Arduino side”

this program accepts a string and transmit it to Arduino, through the serial port
in same way as Arduino Serial Monitor in Post #18

This is Rubik kasBot V1.13 (May 2017: change software versioning )

## Rubik kasBot             @ kas 2014

## V1.13  changed windows position
## V1.12  removed delayB4scan
## V1.11  slow/fast cube moves
## V1.1   communication error management
## V1.0   initial release, serial communication with Arduino only

from tkinter import *
import serial, time
from serial import SerialException
import atexit
import subprocess

defaultPortNumber = '3'                     ##  default Serial port

root =Tk()
root.title('Rubik kasBot')
root.geometry('325x335+1000+100')    # window size + position

vSolve = StringVar()
comVar = IntVar()
speedVar = IntVar()
comSent = StringVar()
comIn = StringVar()
vErrror = StringVar()
vComPort = StringVar()
vComPort.set(defaultPortNumber)

comSent.set("")
comIn.set("")

def bSolve_CallB():
  arduino.write(b"x02" + str.encode(vSolve.get() + 'T') + b"x03") 

def speed_CallB():
  if speedVar.get():
    arduino.write(b"x02 S2 x03")        ## slow moves
  else:
    arduino.write(b"x02 S1 x03")        ## fast moves
      
def com_CallB():
  if comVar.get():
    root.update()
    global arduino
    try:
      arduino = serial.Serial('COM' + vComPort.get(), 57600, timeout=15)
      time.sleep(1.25)                    ## give time to settle
      sComPort.config(state = DISABLED)
      print("COM  <ON>")
      comSent.set("COM  <ON>")
      EnableButtons(True)
      speedVar.set(True)
    except SerialException:
      EnableButtons(False)
      comVar.set(False)
      displayComError('COM' + vComPort.get() +" not available")
  else:
    speedVar.set(False)
    EnableButtons(False)
    arduino.close()
    sComPort.config(state = NORMAL)
    print("COM  <OFF>")
    comSent.set("COM  <OFF>")
    comIn.set("")

## utilities ------------------------------------
def displayComError(message):
  vErrror.set(message)
  root.update()
  print(message)
  time.sleep(2)
  vErrror.set("")
   
def EnableButtons(flag):
  if flag == True:
    aspect = NORMAL
  else:
    aspect = DISABLED
  bSolve.config(state=aspect)
  eSolve.config(state=aspect)
  checkSpeed.config(state=aspect)
  
def cleanup():  ## Exit Cube Explorer and close COM port
  if comVar.get():
    arduino.close()

atexit.register(cleanup)

## UI elements --------------------------
eSolve = Entry(textvariable = vSolve, width = 60, fg="Blue", bd = 2, font=('arial', 6))
eSolve.place(x=20, y=135, height=20, width=285)

bSolve = Button(padx=59, pady=0, bd=3, text="Solve cube ", fg="black", font=('arial', 16), command = bSolve_CallB)
bSolve.place(x=20, y=160, height=55, width=285)

checkSpeed = Checkbutton(text = "High speed", variable = speedVar, command = speed_CallB)
checkSpeed.place(x=20, y=255)

tError = Label(textvariable = vErrror, fg = "red", bd = 3, font=('arial', 8))
tError.place(x=160, y=260)

checkCom = Checkbutton(text = "COM", variable = comVar, command = com_CallB)
checkCom.place(x=20, y=287)

tComOut = Label(textvariable = comSent, bd = 3, font=('arial', 8))
tComOut.place(x=140, y=278)

tComIn = Label(textvariable = comIn, bd = 3, font=('arial', 8))
tComIn.place(x=140, y=297)

sComPort = Spinbox(from_=1, to=9, width = 1, textvariable=vComPort)
sComPort.place(x=80, y=289)

checkCom.invoke()
root.mainloop()

To run or modify this code, please download Python 3.4.2
(available for Windows, Mac OS, Linux and others)

As for previous test, I shuffled the cube using < D B2 R2 U’ F’ L F2 R D2 R B2 R’ > moves
and entered < R B2 R’ D2 R’ F2 L’ F U R2 B2 D’> to solve it
Same result as above video, trust me on this one :wink:
Next steps:

  • install a Webcam on the robot, to allow color recognition by Cube Explorer
  • probably also install a LED lighting to overcome possible white balance variations

EDIT: getting started (April 2017) ---------------------------------------------------

install Python 3.xx
install tkinter (graphical UI)
install pyserial (Serial comm)

now… do your home work :wink: (this thread is not a Python tutorial)
… and run this basic “hello World” test program:

## Rubik (Hello, World)             @ kas 2017

from tkinter import *
import serial, time
from serial import SerialException
import atexit
import subprocess

root =Tk()
root.title('Hello, World')
root.geometry('300x300+200+200')          ## window size + position

root.mainloop()

See the window ?? you are all set

The final bot, with led's and webcam:

Now let's do the final Python coding to transmit color information to Cube Explorer, and obtain the magic formula to solve the cube ;)

Hey! I am building the same project and wanted to know how u automated the scanning of the each 9 tiles of a face and the entire cube using this setup.

Hey! I am building the same project and wanted to know how u automated the scanning of the each 9 tiles of a face and the entire cube using this setup.

Hi dd5665, As mentioned, I use Cube Explorer (CE)

Cube explorer has a built in webserver The robot has to move the cube and expose each face to the webcam, while sending IP queries to CE Cube Explorer will insure facelets color recognition and will finally compute the solution

This is an excerpt from CE manual:

You can control the process of scanning the cube with the webcam interface by sending some strings to the webserver. Position the Back face of the cube in front of the webcam with your robot (as you would do it manually) and send the string " http://127.0.0.1:8081/?scanB" to the webserver to scan the back face of the cube. Then you position the Left face and send the string "http://127.0.0.1:8081/?scanL". Proceed in this way, using the strings "?scanF", "?scanR", "?scanU" and "?scanD". The webserver will respond with a "Done!" in all cases.

When the 6 faces have been scanned, you send the string "http://127.0.0.1:8081/?transfer". If all facelets are ok, the scanned cube is transferred to the Main Window and the solving maneuver is computed. The webserver will respond with a "Done!".

Finally, with the string " http://127.0.0.1:8081/?getLast" the webserver will respond with the last computed solving maneuver in the Main Window of Cube Explorer. Process this string with your robot to solve the cube.

I am busy coding this feature, using Python :-\

:-) Thanks! I have read the Cube explorer manual!

Your documentation is very informative. Can u give more insights onto how I can build the gripper using ply board. Do you have any drawings of all the parts needed to build the gripper. I do not know how to use Solid works or any such CAD softwares. ( Electronics student :-( ).

Thanx in advance!

Hey Kas, amazing design man! I would love to get started also and maybe you can upload the paperscan of the wood grippers so i can print it and also make the grippers. Looking forward to your reply!

Hi guys,

Too many relatives at home for the moment :stuck_out_tongue:
Will be back in a few days

I do not know how to use Solid works or any such CAD softwares. ( Electronics student :frowning: )

This is a nice opportunity to get your hands dirty :wink:
You will definitely have to use these softs in your future jobs

Vectric Vcarve Pro cutting simulation:

The assembly Video (reply #15) has been created using Autodesk Inventor

For dd5665, arduino5 and others, I attach to this post the gripper parts in pdf format
Not sure, you may have to login/register to see the file

Let me know if you need more info

Servo_gripper7(2).pdf (10.7 KB)

Reviewed it, looks really great! What a nice job. When i get my servo's i will test it out. (Should take some more days/weeks)

Meanwhile i will test with cardboard :P

Timing is of the essence! TO THE BATCAVE!

@arduino5

When i get my servo's i will test it out

Make sure that the rotation (wrist) servo can perform at least a full 180° move Some servo's just can't ::)

For this project I used 5mm (.2") plywood and 3mm (1/8") screws How will you cut the parts ??

Hey kas!

Thanx for the layout! Its amazing! I havn't worked with servos before although I know the principles and theory related to it, I am really confused how you interfaced 4 servos (2 for each gripper) to the arduino. Which motor driver are you using? Is it a custom made driver or ready-made one? I am really confused!!!

I havn't worked with servos before although I know the principles and theory related to it

Great 8) 8) 8)

Which motor driver are you using? Is it a custom made driver or ready-made one? I am really confused!!!

:astonished: :astonished: :astonished: dd5665, I suggest you get really familiar with servo motors before tackling this project No need for motor drivers, just one digital output (PWM) per Servo

Look for the sweep.ino sketch in the Aduino IDE Example You may also look here and here

Happy New Year to you and all the Community

:-)

Thanx kas!! I interfaced 2 servos today. It was a silly question indeed! :-P

I went to fabricate the grippers on plyboard today. Since I stay in a pretty backward area :-( ... there is only one place which has a CNC router. They told me that they can only fabricate the pieces on metal sheet or Acrilic sheet. Plus, they are charging Rs . 15000 per gripper for metal sheet and Rs. 4000 per gripper for acrillic sheet!!!!

Both of these options is way beyond my budget.

With no options to cut these parts without a CNC router...I purchased some cardboard and tried cutting the pieces manuallly by hand... I'll let you know if it works. :-((

I purchased some cardboard and tried cutting the pieces manuallly by hand...

I guess it won't be an easy task ::) Let us know

Cool. I tested the card-board version. Its awesome. Now i will make it from plywood when i get the time.

I do have one more request, the length of the bolts and screws, cause i have no idea which to purchase :o?

I tested the card-board version. Its awesome

Please let us have a photo of this card-board version

I do have one more request, the length of the bolts and screws,

I will prepare a list for the additional, non wooden, parts

Just sandwiched the layers without servo. (Its fully working, except it cannot grip anything ofcourse. Just testing the mechanics. Its very well build i must mention (your design!))

I guess if you had this cut from Acrylic or maybe wood even, you could sell it as a low-budget kit. Like, most grippers are way overpriced. This is a very good solution. Now i just need to find a good sheet. But i may make the wood version instead. Acrylic tends to be more expensive.

dd5665:
I went to fabricate the grippers on plyboard today. Since I stay in a pretty backward area :frowning: … there is only one place which has a CNC router. They told me that they can only fabricate the pieces on metal sheet or Acrilic sheet. Plus, they are charging Rs . 15000 per gripper for metal sheet and Rs. 4000 per gripper for acrillic sheet!!!

Both of these options is way beyond my budget.

With no options to cut these parts without a CNC router…I purchased some cardboard and tried cutting the pieces manuallly by hand…
I’ll let you know if it works. :-((

Cardboard: Use exacto knive + Patience. For holes: Cut a cross, then use a screwdriver the size of the hole, and force it through the cross-cut. This will open it up as if it was drilled. = Very easy todo.

Plywood: Use a figure-saw + drill holls. I plan todo that.

Acrylic. Sounds like it has to be lasercut. I wouldnt know how to cut shapes manualy? Streight pieces, sure, but all those corners and teeth? So for solid material maybe your best bet is with wood, like Kas has done.

Just sandwiched the layers without servo. (Its fully working, except it cannot grip anything ofcourse. Just testing the mechanics

Impressive :o :o Care to show the gear parts ??