Magic cube restoration algorithm learning notes

The Rubik's cube defined as random state or initial state, those states in special waters are called target state, and the destination is restore state

The initial state can be regarded as a combination of six basic rotations U, R, F, D, L and B. the group generated by these six rotations is marked as G = ⟨ U,R,F,D,L,B ⟩ G=\langle U,R,F,D,L,B \rangleG = ⟨ U,R,F,D,L,B ⟩
The target state is only generated by the six rotational combinations of U, D, L2, R2, F2 and B2, which are also recorded as G 1 = ⟨ U, D, L 2, R 2, F 2 and B 2 ⟩  

Nature of target state

There are two states of edges, 0 for flip and 1 for flip,   only   F,B   The rotation of the layer can change the direction

There are three states for corner blocks. Twist is represented by 0, clockwise twist is represented by 1, counterclockwise twist is represented by 2, and only   U,D   Layer rotation does not change corner block direction

The target state is generated by six kinds of rotation: U, D, L2, R2, F2 and B2, and these six kinds of rotation will not cause changes in the direction of corner blocks and edges. Because no matter how it rotates, the U-layer or D-Layer owned by the corner block is always in the U-layer or D-Layer, so the direction remains unchanged. It will not cause the change of the direction of the edge block, because only the rotation of F and B will cause the change of the direction of the edge block. If F2 rotates continuously for two times, turning over and then reversing the edge block is equivalent to not turning over, so the direction of the edge block will not change. These six kinds of rotations will not bring the middle-level blocks to layer U or layer D, so the blocks in the middle-level can only be in the middle-level
The direction of the corner block remains unchanged, that is, the sum of the respective direction values is 0

The middle layer block in the restored state is in the middle layer

The search algorithm used by kosumba's two-stage algorithm is IDA * algorithm, that is, iterative deepening search algorithm, and Ida * algorithm is used in both stages

#Optimization scheme:
#After rotating each face, the position of F layer will not be restored! After completing the task of this layer, the function returns 1. Current mechanical position 2. Gripper state (generally closed) 3. Current pose of the magic cube
#Each surface function accepts 1. Mechanical position 2. Gripper state 3. The current position and pose of the Rubik's cube, and carries out motion planning under the conditions of the current position and pose of the Rubik's cube and mechanical position by judging the above parameters
#******Consider the positive situation #(Rubik's cube pose relative to the mechanical body) 6 * 4 = 24 cases

#******Considering the wrist position, it is now specified that each wrist has (1) - 270 (2) - 180 (3) - 90 (4) 0 (5) 90 (6) 180 (7) 270, which can provide 270 delay, but the decision is complex
    #Alternative scheme: only judge the horizontal or vertical problem: it cannot provide an accurate delay solution for 270 degrees: after judging the horizontal or vertical, pre judge whether the rotation angle exceeds the software limit. If it exceeds the limit, delay compensation will be carried out

#******Considering the current regulation of finger state, each finger has (1) on (2) off

#******Considering that the list iteration is completed, it will not be reset at the end of execution, and AandBopen() will be executed directly

#Current idea: the program input is a large list, and the list is updated in the function
#Really learn object-oriented

Mechanical absolute position:

#Mechanical absolute position
A_angle = 0    #A wrist initialization 0 degrees
A_finger = 0    #A finger initialization close 1 open

B_angle = 0     #B wrist initialization 0 degrees
B_finger = 0    #B finger initialization close 1 open

Define other parts:

#level L  vertical V  #bool
A_L = (A_angle == 0 or A_angle == 180 or A_angle == -180 )
A_V = (A_angle == 90 or A_angle == -90 or A_angle == 270 or A_angle == -270)

B_L = (B_angle == 0 or B_angle == 180 or B_angle == -180 )
B_V = (B_angle == 90 or B_angle == -90 or B_angle == 270 or B_angle == -270)

Aopen = (A_finger == 1 )
Aclose = (A_finger == 0 )
Bopen = (B_finger == 1 )
Bclose = (A_finger == 0 )

Relative position:

#Relative position of Rubik's Cube
F_direction = 0 #Initialize F face orientation
U_direction = 3 #Initialize U face orientation

#machine_pos = [A_L, A_finger, B_L, B_finger]  #The mechanical absolute position is defined as A wrist absolute angle A finger opening and closing B wrist absolute angle B finger opening and closing

Relative pose:

cube_pos = [F_direction, U_direction]  #The relative pose of the cube is defined as that the front of the cube faces the element 1: F face and the element 2:U face

Exhaustive limit:

def B180():   #It's a little interesting. Exhaustive limit
    print('B180...')
    global B_angle
    B_angle = B_angle + 180   #Prediction
    
    #if(B_angle != 450 or B_angle != 360)
    #    time.sleep(0.001)
    #    ser.write("\x40".encode('utf-8'))     #B 180
    #    time.sleep(time180)
    
    if(B_angle == 450):
        #B_angle = 90
        time.sleep(0.001)
        ser.write("\x40".encode('utf-8'))     #B 180
        time.sleep(time180)
        return
    
    if(B_angle == 360):
        #B_angle = 0
        time.sleep(0.001)
        ser.write("\x40".encode('utf-8'))     #B 180
        time.sleep(time180)
        return
    
    else:
        time.sleep(0.001)
        ser.write("\x40".encode('utf-8'))     #B 180
        time.sleep(time180)
        return

The first generation machine prevents winding the air pipe, records each rotation direction and how much it rotates;

Tags: Algorithm

Posted on Thu, 30 Sep 2021 19:08:01 -0400 by oc1000