forked from matiyau/RuDe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cubeSlv_main.py
executable file
·66 lines (49 loc) · 1.6 KB
/
cubeSlv_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def steps() :
turns=["x", "x2", "x'", "y", "y2", "y'", "U", "U2", "U'", "R", "R2", "R'", "F", "F2", "F'", "RESET"]
print "SETTING UP ..."
import cubeCns
import cubeSlv_GraphIDA as IDA
from time import sleep
import serial
import pickle
#Arduino = serial.Serial("/dev/ttyUSB0", 115200)
try:
Arduino = serial.Serial("/dev/ttyACM0", 115200)
except:
try:
Arduino = serial.Serial("/dev/ttyUSB0", 115200)
except:
try:
Arduino = serial.Serial("/dev/ttyACM1", 115200)
except:
try:
Arduino = serial.Serial("/dev/ttyUSB1", 115200)
except:
print "Error Connecting Arduino"
Arduino=7
#return 0
sleep(4)
print "\nRESETTING GRIPPERS."
#Attach Servos and then Reset Grippers
Arduino.write("*<17<15#")
print "\nCONSTRUCTING CUBE ...\nCapturing Faces"
Cube = cubeCns.matrixForm(Arduino)
with open('Matrix', 'rb') as comb:
Cube=pickle.load(comb)
print Cube
print "\nCOMPUTING SOLUTION ..."
DB=IDA.setup()
Algo=IDA.main(Cube, DB)
print "\nBEST SOLUTION :"
print [turns[i] for i in Algo]
print "\nSOLVING CUBE ..."
solution="*"+"".join('<'+str(k) for k in Algo)+"<15#"
print solution
Arduino.write(solution)
if Arduino.read(1)!='N':
print "Cube not solved"
return 0
#Detach All Servos
Arduino.write("*16#")
print '\n*** Cube Solved ***'
steps()