Anh2016 Chapter DesignAndControlAutomaticChess
Anh2016 Chapter DesignAndControlAutomaticChess
Nguyen Duy Anh, Luong Thanh Nhat and Tran Van Phan Nhan
Abstract This paper presents a 3DoF robot manipulator system which can play
chess physically with human. The system consists of three main parts: a computer
vision program written by Visual Studio to recognize chess moves, a chess program
to choose the best move to response and a robot arm to perform chess move on a
real chessboard. In this paper, the authors focus on analyzing mechanical design,
methods to detect chess moves and algorithm applied to control the SCARA robot
arm. Based on the design, a robot arm was manufactured and set up. Chess matches
between robot and human were held to experiment the operation of robot arm as
well as the result of the matches.
1 Introduction
Chess is a two-player strategy game played on chessboard. The question is: “What
will happened if the opponent is a robot?”. Nowadays, super computers can beat
chess grand masters, however, there must be one man who reads the result of
calculation from the computer, then, execute the move on chessboard [1].
Therefore, an autonomous chess-playing process has been being researched in the
world. In Vietnam, there have not been any researches about autonomous
chess-playing system, authors decided to manufacture a robot arm which can play
chess automatically and physically.
Opponent’s move
COMPUTER UNIT WEBCAM UNIT
(Execute: image processing , USB (Use Logitech C 170 to
playing chess program ) identify chess moves )
RS 232
Robot’s
move
%PWM,
Kp, Ki,Kd
MICROCONTROLLER POWER UNIT
UNIT (Use 3 DC servo
(Use STM32F4) and 1 RC servo)
Encoder
In the first part of project, SolidWorks was used to calculate and design struc-
ture, dimension of links, joints of robot arm. In the second part, one camera hung
above the chessboard and taking pictures to detect chess moves. A chess-playing
program written on Visual Studio will evaluate and find the best move for robot. In
the final part, a PID controller was used to control position of robot arm. A whole
system is briefly described in Fig. 1.
2 Mechanical Design
2.1 Kinematics
The kinematics model was built by the algorithm of Denavit Hartenberg; the DH
parameters are the relationships among the robot’s serial links. Base on require-
ments of the system, the SCARA type was used that has a schematic shown in
Fig. 2. The DH parameters according to the configuration of the SCARA are
presented in Table 1.
Considering Table 1 and Fig. 2, the forward kinematic equations are obtained as
follows:
z ¼ h1 þ h 2 d 3 ð3Þ
h2
Y2
Z2
d3
X3
h1
Y0 Y3
Z0 Z3
X0
d3 ¼ h 1 þ h2 z ð4Þ
ðx2 þ y2 Þ ðl21 þ l22 Þ
h2 ¼ arccos ð5Þ
2 l1 l2
0 1 0 1
B x þy þ l21
2 y l1
2 2
l22 C B C
h1 ¼ arcsin@qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiA arccos@qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiA ð6Þ
2 2 2 2
ð2xl1 Þ þ ð2yl1 Þ ð2xl1 Þ þ ð2yl1 Þ
Figure 3 describes that link I is driven by motor I through a closed coupling I, link
II is driven by motor II which is connected with link I by a closed coupling II.
Motor III controls the height position of the end-effector through a mixed trans-
mission between ball screw and timing belt. Figure 4 shows the 3D design of the
robot arm and Fig. 5 shows the gripper designed by SolidWorks.
488 N.D. Anh et al.
1. Motor I
3 4 5 6 7 8
2. Closed coupling I
n2 3. Link I
9
4. Closed coupling II
2
5. Motor II
10 6. Motor III
1 7. Link II
n3
8. Ball screw
n1
9.Timing belt trans-
mission
10. End-effector
Logitech C170 webcam was used to perceive the chess moves (Fig. 6) and con-
nected with the computer via USB port. The process (Fig. 7) began with camera
calibration to ensure the precision of capturing pictures, then, a picture of an empty
chessboard (chessboard without chess piece) was taken. After every chess move,
camera will capture an image and execute image subtraction to determine if the
chess piece was presented on each chess cell.
Pre-processing Image:
Two steps of pre-processing: Crop (Fig. 8) and Grayscale (Fig. 9) were executed to
improve image’s quality. Chess board is a square, but the image taken by camera is
in rectangular shape, therefore, unnecessary parts must be cropped to focus on 64
squares of the chessboard. In addition, images taken by camera are in RGB scale so
they have three different layers that will complicate the process, so, converting
those images into Grayscale which has only one layer is necessary (Fig. 10).
Pre-processing Image
Image Subtraction
Determine
chessboard matrix
This method was applied to find differences between two input pictures. After
subtraction, pixel value will be compared with threshold, the position of each chess
piece will be shown in a Binary picture (Fig. 11).
Design and Control Automatic Chess-Playing Robot Arm 491
Based on the results of Binary Image, a 8 × 8 chess board matrix will be created
respectively with 8 × 8 chess board, and chess cells that chess piece is standing on
will have a value of “1”, otherwise, the value is “0” [1] (Figs. 12 and 13).
Information combined from two matrices (before and after opponent’s move),
the chess move will be determined easily by a “delta matrix” (Fig. 14). In “Delta
matrix”, “−1” element describes the chess move beginning point, “1” element
describes the chess move ending point. Then, we compare the matrix with chess
board notation in Fig. 15 to record the move.
After image processing, the chess programming on computer will calculate and
compute chess move to response to the opponent. Chess programming uses a
library containing: opening moves and sample moves [3]. In addition, the program
applied Min-max and Alpha-beta algorithm to choose the best move from all
possible moves [4]. The selected move will be sent to the microcontroller to control
robot arm grip and drop chess pieces on the real chessboard.
4 Control System
Control system diagram was shown in Fig. 16. Microcontroller receives chess
moves sent from PC via RS232, processes and control motors. Positions of motor
will response to microcontroller by encoder. Working range of robot arm was
limited by limit switches.
When design the control system, it was necessary to select the appropriate
actuators. In this case, DC servo motors were chosen because of its high accuracy
and easy control. The system needs a position control algorithm in order to help the
robot arm reach correct position. Because the motor’s parameters are not enough for
the simulation, PID algorithm with the Zeigler–Nichols II method using feedback
signal from encoder was applied to calculate and create the PWM signal to control
the position of the motor’s angle. When the system is turned on, it is necessary to
initialize PID parameters, enable microcontroller’s interrupt and move the robot
arm to “HOME” position in order to reset the encoder. Then, the system returns to
waiting state, waiting for the process enable bit in RS232 interrupt. When the
computer sends a process statement to microcontroller, the process is enabled, the
arm reaches each position from start to end in sequence through PID position
algorithm subroutine.
Design and Control Automatic Chess-Playing Robot Arm 493
Motor
5V power source
Encoder
for encoder
According to the 3D design, authors manufactured entire robot arm and the gripper
to test the operating of system in real match. Robot’s material is Acrylic plastic
PMMA (Figs. 17 and 18).
The Figs. 19 and 20 show the straight trajectory of robot end-effector when pro-
cessing a move the Knight from B8 (261;−120;0) to C6 (357;−72;0) using
MATHLAB simulation. The move started from stand by position (24;185;250).
In Fig. 21, there are three images, the first is empty chess board’s image, the next
two images are the chess board before and after opponent’s move. It can be seen
from the picture, white pawn was moved from E2 to E4 and the result of process is
written in the textbox. Image processing’s accuracy is secured if we provide low
noise lighting condition and place chess pieces within square area.
The system include: standard FIDE chessboard, camera, robot manipulator, pro-
grams on computer. To secure lighting condition, an additional lamp was used and
placed above the chessboard (Fig. 17). Five chess games versus five different
random opponents were held and the results were shown in Table 2.
Gripper’s errors include impact between gripper and different chess pieces when
moving as well as the opening distance of gripper is not wide enough to release
chess piece. The position accuracy of robot arm is based on how it put chessmen
right in the square on the chessboard. If the footprint intersects with the borderline,
it will be known as error. Otherwise, if the footprint’s center and the center of
chessboard’s square are not coincident, it will be acceptable.
After five matches, it can be seen that the working of system is stable, follow the
setting sequence: taking picture, image processing, choosing best move and moving
chess pieces on physical chessboard. There is no failure when system process
images and transmit data, however, the match will stop if the gripper do not release
chessman or chess piece was not placed inside chess cell. Accuracy of moving
chess pieces decrease after every move because of robot’s repeatability error and
vibration of the gripper when moving. These make error happened easily when
matches last longer than 30 moves.
6 Conclusion
References
1. Arda M, Kuşçu H, Öztürk E (2013) Obtain chess moves with image processing. In: Proceeding
of the Unitech Grabovo international scientific conference
2. Quoc LH (2005) Kỹ thuật người máy Phần 1: Robot công nghiệp. Vietnam National University
Publisher, Ho Chi Minh City
3. Tan NN, Quoc NX (2010) Thiết kế chương trình chơi cờ vua. Graduate thesis, Cao Thang
College
4. Khac VV, Cuong LBQ (2013) Robot chơi cờ tướng. Gaduate thesis, HCM City University of
Technology