Sunday, April 17, 2011

Converting Computer Moves into Physical Moves


Again, here I have done some more planning so that it will be straightforward when writing the code for moving the computer’s chess pieces when it outputs a move.

The moves will come in the form (letter,number,letter,number). For example a move could be C7C6, which would mean move the piece at square C7 to square C6. Again recall that the computer outputs in (column, row) coordinates instead of matrix coordinates (row, column). Thus we do an inverse coordinate transform as that shown in the previous post’s table to get the correct numerical coordinates. Thus C7 would correspond to (6,2), and C6 would correspond to (5,2). 

Now, we are going to design the X-Y magnet system so that it will transport the pieces along the lines in between the squares so that the pieces do not collide. This is another reason why our chessboard had to be large. Thus the X-Y magnet system will need to have a finer coordinate system so that it can both go to the location of the piece and go in between other pieces. The following grid shows the coordinate system of the X-Y magnet system. 

The coordinates now range from 0 to 16 in both X and Y directions. The actual chess squares are colored so that the coordinate system could be visualized overlaying the actual chessboard. The chess pieces can only be located at coordinates where both the X and Y coordinates are both odd.

Note that the transformed numerical move coordinates will again need to be changed to fit the granularity of the XY system coordinate system. This involves multiplying each coordinate by two and adding 1: (2x+1,2y+1). Thus if the instructions are move piece at (6,2) to space (5,2) are received, this would correspond to the XY system needing to move the piece at (13,5) to (11, 5).

We plan to have the XY system start at the center of the board, which is position (8,8). We can then recalibrate the XY system after each move by forcing it to return to the center position after delivering a piece to a square. This can be done by placing a magnet behind each stepper motor that triggers a Reed switch placed at the exact center of each motor’s movement track. 

So when the origin coordinates are received, we subtract (8,8) from the coordinates. For example, (13,5) – (8,8) = (5,-3). The X stepper motor then shifts up five coordinate steps; each coordinate step will have a specified number of motor steps that will be determined through testing. The Y stepper motor then shifts left 3 coordinate steps. The magnet is then flipped up with the servo motor to attract the piece.

Then the current coordinates are subtracted from the next coordinates. For example, (11,5) – (13,5) = (-2,0). Thus the X stepper motor will need to shift down 2 coordinate steps. The Y stepper motor will not need to shift in this case.  However, to avoid piece collision we want to travel along the lines instead of through the squares. Thus, each time we are moving a piece, we first shift up and right 1 coordinate step. So we’d go from (13,5) to (14,6). Then we’d do the (-2,0) shift, thus going from (14,6) to (12,6). Then we’d cancel out the offset shift by going down and left one coordinate, thus going from (12,6) to (11,5). The piece has then arrived at the destination coordinates.

The magnet is flipped down, and the stepper motors move the system and recalibrate to the center (8,8) coordinate by subtracting the current coordinates from (8,8). For example,  (8,8) – (11,5) = (-3, 3). If the first coordinate is negative, the X coordinate stepper motor moves down until the Reed switch is triggered. If the first coordinate is positive, the X coordinate stepper motor moves up until the Reed switch is triggered. If the second coordinate is negative, the Y coordinate stepper motor moves left until the Reed switch is triggered. If the second coordinate is positive, the Y coordinate stepper motor moves right until the Reed switch is triggered. 

Now the program is ready for the human to move a piece.

No comments:

Post a Comment