Application of Machine Learning in Air Hockey Interactive Control System

In recent years, chip design technology and AI (artificial intelligence) have made significant progress. This forces all of fields to investigate how to increase the competitiveness of products with machine learning technology. In this work, we mainly use deep learning coupled with motor control to realize the real-time interactive system of air hockey, and to verify the feasibility of machine learning in the real-time interactive system. In particular, we use the convolutional neural network YOLO (“you only look once”) to capture the hockey current position. At the same time, the law of reflection and neural networking are applied to predict the end position of the puck Based on the predicted location, the system will control the stepping motor to move the linear slide to realize the real-time interactive air hockey system. Finally, we discuss and verify the accuracy of the prediction of the puck end position and improve the system response time to meet the system requirements.


Introduction
Advances in integrated circuit (IC) design technology have made significant contributions in both memory space and processing power. This has boosted the feasibility of artificial intelligence technology applications [1]. How to combine machine learning with machine control is an important research issue.
Related works usually got the position of the puck by traditional image recognition. The mutual conversion of the color space is used to eliminate the influence of the brightness on the color characteristics of the puck [2]. The prediction first assumes that the puck moves in a straight line, and a linear formula is used as the prediction method after the last impact on the edge of the table or after the puck enters the specified area [3]. It was also proposed to use a neural network for the end point. Position prediction [4] uses the angle, speed, and position of the puck through the attack line as input data to train a neural network model that can predict the position of the puck through the finish line. Compared with directly extracting the puck position for trajectory prediction, some have proposed adding a high-speed vision system to capture the player's attacking postures and movements to make the basis for the robot's return decision [5], or to analyze the eye movements of human players to generate a return strategy using the human eye to determine the lack of time [6], and some people make a control mechanism based on reinforcement learning to reduce the rate of missing points of this system [7].

Preliminaries
Air hockey is a competitive entertainment game that combines intelligence and reaction ability. As shown in Figure 1a, the game environment consists of a table with a goal on each side of the table. The surface of the table has evenly distributed air holes. The fan under the table will generate airflow from the air holes, allowing the plastic disc, hockey puck, to be almost sliding on a frictionless tabletop. The player uses the plastic handle to try to penetrate the opponent's goal and block the opponent's attack as much as possible.
The linear slide rail in air hockey is a rolling guide, using steel balls or rollers as the transmission interface between the slider and the slide rail to carry out rolling motion without limit of stroke, so that the load platform can follow the slide rail at high speed, high-precision linear motion. Due to the low frictional resistance, the drive horsepower is low, and the requirements for miniaturization and high-speed machinery can be realized at the same time.
The stepping motor in air hockey is a control element that converts electrical pulse signals into angular displacement or linear displacement. When there is no overload, the speed and stop position of the motor depends only on the frequency and number of pulses of the pulse signal. The influence of load changes, and the stepper motor has only periodic errors without cumulative errors. The stepping Sensors 2020, 20, 7233 3 of 22 motor has a stator and rotor that are like gear-like protrusions and fit each other, and the current flowing to the stator coil is switched to gradually rotate at a certain angle. The stepping motor has a great self-retaining force when it generates a magnetic field after being energized, so it can maintain the stopped position even without using a mechanical brake. Although the stepping motor is small in size, it can achieve high torque output at low speed, so it has good performance in acceleration and frequent movement.
By setting up a camera on the air hockey table (shown in Figure 1b), the real-time image of the hockey position can be captured and transmitted to a personal computer (PC). In order to block the hockey smoothly, the defender must move to the corresponding position before the hockey goal is scored. Therefore, it is necessary to obtain the position of the hockey and predict the hockey end position in advance, and finally move the defender according to the predicted result.
Sensors 2020, 10, x FOR PEER REVIEW 3 of 23 of load changes, and the stepper motor has only periodic errors without cumulative errors. The stepping motor has a stator and rotor that are like gear-like protrusions and fit each other, and the current flowing to the stator coil is switched to gradually rotate at a certain angle. The stepping motor has a great self-retaining force when it generates a magnetic field after being energized, so it can maintain the stopped position even without using a mechanical brake. Although the stepping motor is small in size, it can achieve high torque output at low speed, so it has good performance in acceleration and frequent movement. By setting up a camera on the air hockey table (shown in Figure 1b), the real-time image of the hockey position can be captured and transmitted to a personal computer (PC). In order to block the hockey smoothly, the defender must move to the corresponding position before the hockey goal is scored. Therefore, it is necessary to obtain the position of the hockey and predict the hockey end position in advance, and finally move the defender according to the predicted result.

Proposed System Architecture
This section presents the proposed system architecture. Since the moving speed of the hockey is very fast and the distance within the table for the experimental environment is not large, we consider it in real-time, including the recognition time, the prediction time, and the defender's movement time. The total of these three times is less than the movement time of hockey (hockey moving distance divided by the fastest puck speed).
In terms of target recognition, we use deep learning models as a recognition method to reduce the impact of environmental brightness on the characteristics of the hockey. We choose YOLO as its algorithm to meet the requirement of real-time.
We also added a neural network-like prediction method, and compared their prediction accuracy and prediction time because hockey may be affected by the friction and levelness of the table to change its linear motion trajectory, in addition to the linear formula combined with the law of reflection for prediction.
In terms of cost and control difficulty, we use stepping motors with linear slides as the move control of the defender, and the stepping motor may lose step during the control process (the motor torque is not enough to drive the defender move), causing the system to make an error in judging the position of the defender's movement, so it will move the defender as fast as possible without losing step with different control mechanisms.

Proposed System Architecture
This section presents the proposed system architecture. Since the moving speed of the hockey is very fast and the distance within the table for the experimental environment is not large, we consider it in real-time, including the recognition time, the prediction time, and the defender's movement time. The total of these three times is less than the movement time of hockey (hockey moving distance divided by the fastest puck speed).
In terms of target recognition, we use deep learning models as a recognition method to reduce the impact of environmental brightness on the characteristics of the hockey. We choose YOLO as its algorithm to meet the requirement of real-time.
We also added a neural network-like prediction method, and compared their prediction accuracy and prediction time because hockey may be affected by the friction and levelness of the table to change its linear motion trajectory, in addition to the linear formula combined with the law of reflection for prediction.
In terms of cost and control difficulty, we use stepping motors with linear slides as the move control of the defender, and the stepping motor may lose step during the control process (the motor torque is not enough to drive the defender move), causing the system to make an error in judging the position of the defender's movement, so it will move the defender as fast as possible without losing step with different control mechanisms.
The overall system architecture is shown in Figure 2. The camera lens is mounted 1.3 m above the to do image recognition. The target recognition is performed by the camera capturing the entire air hockey table image and then using a convolutional neural network (YOLO) to detect the position of the hockey puck and the grip of the attacker. Then, the final position of the hockey puck is predicted by the neural network and the reflection law based on the direction of the attacker's force and the hockey ball's trajectory. Finally, the prediction result is transmitted to the controller and the stepper motor is controlled to move the defender to block the hockey ball from scoring.
The detail is introduced later for two system implementation methods. It is divided into three main parts, which are the image recognition for identifying the puck, the prediction for computing and predicting the end position of the hockey, and the control for controlling the linear guideway of the stepper motor.
Sensors 2020, 10, x FOR PEER REVIEW 4 of 23 The overall system architecture is shown in Figure 2. The camera lens is mounted 1. 3 m above  the table to get the entire desktop image in real time. It sends real-time images to the PC via USB to  do image recognition. The target recognition is performed by the camera capturing the entire air  hockey table image and then using a convolutional neural network (YOLO) to detect the position of the hockey puck and the grip of the attacker. Then, the final position of the hockey puck is predicted by the neural network and the reflection law based on the direction of the attacker's force and the hockey ball's trajectory. Finally, the prediction result is transmitted to the controller and the stepper motor is controlled to move the defender to block the hockey ball from scoring.
The detail is introduced later for two system implementation methods. It is divided into three main parts, which are the image recognition for identifying the puck, the prediction for computing and predicting the end position of the hockey, and the control for controlling the linear guideway of the stepper motor.

System Implementation-Method 1: Direct Prediction
As shown in Figure 3, method 1 is that when the hockey ball passes the attack line, it will predict its end position in the direction of the hockey movement and move the defender to the predicted area. Because the total length of the defensive area is 59 cm and the diameter of the defender is 7.5 cm, the defensive area is divided into nine areas; one area is about 6.6 cm wide.

System Implementation-Method 1: Direct Prediction
As shown in Figure 3, method 1 is that when the hockey ball passes the attack line, it will predict its end position in the direction of the hockey movement and move the defender to the predicted area. Because the total length of the defensive area is 59 cm and the diameter of the defender is 7.5 cm, the defensive area is divided into nine areas; one area is about 6.6 cm wide.

Image Recognition
By testing with the same hardware device (GeForce GTX 1050 Ti, 4GB, NVIDIA Corporation in California, Santa Clara, CA, USA), the recognition speed of YOLOv3 [27] is 15 fps on average, while tiny-YOLOv3 can reach an average of 30 fps. Therefore, tiny-YOLOv3 is used as the target recognition method. The network architecture is shown in Figure 4. The original YOLOv3′s 53-layer convolutional layer is reduced to 13-layer convolutional layers. Except for the last convolutional   By testing with the same hardware device (GeForce GTX 1050 Ti, 4GB, NVIDIA Corporation in California, Santa Clara, CA, USA), the recognition speed of YOLOv3 [27] is 15 fps on average, while tiny-YOLOv3 can reach an average of 30 fps. Therefore, tiny-YOLOv3 is used as the target recognition method. The network architecture is shown in Figure 4. The original YOLOv3 s 53-layer convolutional layer is reduced to 13-layer convolutional layers. Except for the last convolutional layer, all convolutional layers are followed by batch normalization to normalize the output data and uses the LeakyRelu function that performs a nonlinear transformation on the normalized data. The LeakyRelu function is defined as where α = 0.1.
Since the target category to be identified is only the hockey, the output dimensions of the network architecture can be expressed as 26 × 26 × 3 × (5 + 1) and 13 × 13 × 3 × (5 + 1), where 26 × 26 and 13 × 13 represent the size of the segmented grid. The value of 3 gives the bounding boxes predicted by each grid; 5 includes the size, bounding box position, and credibility score; and 1 is the probability of the hockey.

Image Recognition
By testing with the same hardware device (GeForce GTX 1050 Ti, 4GB, NVIDIA Corporation in California, Santa Clara, CA, USA), the recognition speed of YOLOv3 [27] is 15 fps on average, while tiny-YOLOv3 can reach an average of 30 fps. Therefore, tiny-YOLOv3 is used as the target recognition method. The network architecture is shown in Figure 4. The original YOLOv3′s 53-layer convolutional layer is reduced to 13-layer convolutional layers. Except for the last convolutional layer, all convolutional layers are followed by batch normalization to normalize the output data and uses the LeakyRelu function that performs a nonlinear transformation on the normalized data. The LeakyRelu function is defined as Since the target category to be identified is only the hockey, the output dimensions of the network architecture can be expressed as 26 × 26 × 3 × (5 + 1) and 13 × 13 × 3 × (5 + 1), where 26 × 26 and 13 × 13 represent the size of the segmented grid. The value of 3 gives the bounding boxes predicted by each grid; 5 includes the size, bounding box position, and credibility score; and 1 is the probability of the hockey. The training data are divided into two different training data groups based on the video footage of the actual game process. One is 250 clear images of hockey moving slowly, as shown in Figure 5 and the other is 250 blurred images of hockey moving fast, as shown in Figure 6-a total of 500 hockey images. The size of the hockey mark of the blurred image is based on the size of the clear hockey mark.
The loss function used in training is the loss function of YOLOv3, and binary classification prediction is made according to whether there is a target in the bounding box (i.e., if there is this category). Target detection and type prediction are calculated by binary cross-entropy.
The training data are divided into two different training data groups based on the video footage of the actual game process. One is 250 clear images of hockey moving slowly, as shown in Figure 5 and the other is 250 blurred images of hockey moving fast, as shown in Figure 6-a total of 500 hockey images. The size of the hockey mark of the blurred image is based on the size of the clear hockey mark.  The loss function used in training is the loss function of YOLOv3, and binary classification prediction is made according to whether there is a target in the bounding box (i.e., if there is this category). Target detection and type prediction are calculated by binary cross-entropy.

Prediction Computing
In an ideal situation, the hockey ball moves in a linear motion. However, environmental factors such as table friction and levelness will affect the movement of the hockey. Therefore, we use linear formulas combined with the law of reflection to compare the accuracy of prediction and execution time with the proposed method that uses neural networks.
Using a linear formula combined with the law of reflection to predict the end position is based on the linear formula (before hitting the edge of the table) and the law of reflection (after hitting the edge of the table) to calculate its trajectory, as shown in Figure 7. First, we calculate the trajectory before the collision: The training data are divided into two different training data groups based on the video footage of the actual game process. One is 250 clear images of hockey moving slowly, as shown in Figure 5 and the other is 250 blurred images of hockey moving fast, as shown in Figure 6-a total of 500 hockey images. The size of the hockey mark of the blurred image is based on the size of the clear hockey mark.  The loss function used in training is the loss function of YOLOv3, and binary classification prediction is made according to whether there is a target in the bounding box (i.e., if there is this category). Target detection and type prediction are calculated by binary cross-entropy.

Prediction Computing
In an ideal situation, the hockey ball moves in a linear motion. However, environmental factors such as table friction and levelness will affect the movement of the hockey. Therefore, we use linear formulas combined with the law of reflection to compare the accuracy of prediction and execution time with the proposed method that uses neural networks.
Using a linear formula combined with the law of reflection to predict the end position is based on the linear formula (before hitting the edge of the table) and the law of reflection (after hitting the edge of the table) to calculate its trajectory, as shown in Figure 7. First, we calculate the trajectory before the collision:

Prediction Computing
In an ideal situation, the hockey ball moves in a linear motion. However, environmental factors such as table friction and levelness will affect the movement of the hockey. Therefore, we use linear formulas combined with the law of reflection to compare the accuracy of prediction and execution time with the proposed method that uses neural networks.
Using a linear formula combined with the law of reflection to predict the end position is based on the linear formula (before hitting the edge of the table) and the law of reflection (after hitting the edge of the table) to calculate its trajectory, as shown in Figure 7. First, we calculate the trajectory before the collision: where X t and Y t represent the final position before hitting the edge of the table; C x and C y represent the hockey center point at the current point in time; and P x and P y represent the hockey center point at the previous point in time. If a collision occurs during the prediction process, then we use the reflection law that the incident angle is equal to the reflection angle to calculate the final coordinate position, as shown in the following formula: where X t+1 and Y t+1 represent the final position of the set defensive area after hitting the edge of the table. As shown in Figure 8, when calculating the collision point, it is necessary to consider that the Sensors 2020, 20, 7233 7 of 22 hockey puck is a circle instead of a point, so we reverse the actual collision point to correct for the hockey radius by the following two formulas: where X a and Y a are the impact points after correction; X b and Y b are the impact points before correction; Y min and Y max represent the upper and lower boundaries, respectively; and m is the slope of the current direction of travel. The neural-network prediction method regards the prediction problem as a classification problem, and divides the final prediction coordinates into nine regions (the width of the game environment is 59 cm and the grip diameter is 7.5 cm). The input data are the coordinates of the three time points and the collision speed between the two points. There are a total of eight input data. Because of the different input values, the input data are normalized first. Here, the minimum maximum value is used. Min-max normalization scales the data to the interval (0, 1), and the output is the area from 0 to 8. We also compare the prediction accuracy and execution time. The excitation functions are all sigmoid, and the final output layer uses the softmax function to normalize the output value to the (0, 1) interval, which represents the probability of outputting each area from 0 to 8, and the sum is 1. The maximum value is the prediction area, the loss function for cross entropy, and the learning optimization algorithm used is adam.

Control
A stepper motor, also known as a step motor or stepping motor, is a brushless DC electric motor that divides a full rotation into a number of equal steps. The motor's position can then be commanded to move and hold at one of these steps without any position sensor for feedback (an open-loop controller), as long as the motor is carefully sized to the application with respect to torque and speed. Motor resonance frequency can be calculated from the formula: where Mh is holding torque (N·m), p is number of pole pairs, and Jr is rotor inertia (kg·m 2 ). Since the stepping motor is controlled by a pulse signal, it needs to be initialized to obtain the number of pulses corresponding to the moving distance. The initialization process is to set the limit distance of the defender's movement through the mechanical limit switch. As shown in Figure 9, the limit switch is installed to the left and right sides of the slide rail. First, the stepping motor controls movement of the defender to the left. When the limit switch is reached, then it starts to move in the opposite direction and records the number of pulses until it hits the right limit switch, thereby calculating the number of pulses required to move a defensive area, and moves the defender to the center of the track after the initialization is completed, that is, defensive area four.

Control
A stepper motor, also known as a step motor or stepping motor, is a brushless DC electric motor that divides a full rotation into a number of equal steps. The motor's position can then be commanded to move and hold at one of these steps without any position sensor for feedback (an open-loop controller), as long as the motor is carefully sized to the application with respect to torque and speed. Motor resonance frequency can be calculated from the formula: where M h is holding torque (N·m), p is number of pole pairs, and J r is rotor inertia (kg·m 2 ). Since the stepping motor is controlled by a pulse signal, it needs to be initialized to obtain the number of pulses corresponding to the moving distance. The initialization process is to set the limit distance of the defender's movement through the mechanical limit switch. As shown in Figure 9, the limit switch is installed to the left and right sides of the slide rail. First, the stepping motor controls movement of the defender to the left. When the limit switch is reached, then it starts to move in the opposite direction and records the number of pulses until it hits the right limit switch, thereby calculating the number of pulses required to move a defensive area, and moves the defender to the center of the track after the initialization is completed, that is, defensive area four. When the speed of the stepping motor is slow, the coil current has enough time to reach the maximum value and the output torque is larger. On the contrary, when the speed increases, the pulse signal changes rapidly, so that the coil current weakens and the output torque decreases. The movement of the defender must meet the conditions of the high-speed hockey movement, so the original pulse selection part is initialized to control the motor with the highest pulse frequency (2500 Hz), but through When the speed of the stepping motor is slow, the coil current has enough time to reach the maximum value and the output torque is larger. On the contrary, when the speed increases, the pulse signal changes rapidly, so that the coil current weakens and the output torque decreases. The movement of the defender must meet the conditions of the high-speed hockey movement, so the original pulse selection part is initialized to control the motor with the highest pulse frequency (2500 Hz), but through experiments, it was found that controlling the motor at this frequency is prone to insufficient torque. In the situation when the phenomenon of synchronization loss occurs, although the controller sent a control signal, the defender did not move, causing the system to make an error in the position judgment, which makes it impossible to block the hockey in real time and needs to be reinitialized. In order to solve this problem, the frequency of the start pulse signal is changed to a gradual increase instead of directly using the highest speed frequency pulse to control the motor, as shown in Figure 10. When the speed of the stepping motor is slow, the coil current has enough time to reach the maximum value and the output torque is larger. On the contrary, when the speed increases, the pulse signal changes rapidly, so that the coil current weakens and the output torque decreases. The movement of the defender must meet the conditions of the high-speed hockey movement, so the original pulse selection part is initialized to control the motor with the highest pulse frequency (2500 Hz), but through experiments, it was found that controlling the motor at this frequency is prone to insufficient torque. In the situation when the phenomenon of synchronization loss occurs, although the controller sent a control signal, the defender did not move, causing the system to make an error in the position judgment, which makes it impossible to block the hockey in real time and needs to be reinitialized. In order to solve this problem, the frequency of the start pulse signal is changed to a gradual increase instead of directly using the highest speed frequency pulse to control the motor, as shown in Figure 10.

System Implementation-Method 2: Two-Stage Prediction
This method divides the prediction of the hockey end position into a preliminary and final prediction. The preliminary prediction is to use the neural network to roughly estimate the end position of the hockey through the direction of the attacker's force before the hockey is hit by the attacker's grip; the final prediction is to predict the end position of the hockey by the linear formula combined with the law of reflection.

Image Recognition
Due to the addition of preliminary predictions, there are two types of targets that need to be identified, hockey and the attacker's grip, and the output dimension becomes 26 × 26 × 3 × (5 + 2) and

System Implementation-Method 2: Two-Stage Prediction
This method divides the prediction of the hockey end position into a preliminary and final prediction. The preliminary prediction is to use the neural network to roughly estimate the end position of the hockey through the direction of the attacker's force before the hockey is hit by the attacker's grip; the final prediction is to predict the end position of the hockey by the linear formula combined with the law of reflection.

Image Recognition
Due to the addition of preliminary predictions, there are two types of targets that need to be identified, hockey and the attacker's grip, and the output dimension becomes 26 × 26 × 3 × (5 + 2) and 13 × 13 × 3 × (5 + 2), where 26 × 26 and 13 × 13 represent the size of the segmented grid. The value of 3 gives the bounding boxes predicted by each grid; 5 includes the size, bounding box position, and credibility score; and 2 is the probability of hockey and attacker's grip. The network architecture is shown in Figure 11.
Since both hockey and the attacker have only one, the bounding box with the highest credibility score is selected as the prediction result. The loss function is the same as the loss function of tiny-YOLOv3 mentioned in method 1.
13 × 13 × 3 × (5 + 2), where 26 × 26 and 13 × 13 represent the size of the segmented grid. The value of 3 gives the bounding boxes predicted by each grid; 5 includes the size, bounding box position, and credibility score; and 2 is the probability of hockey and attacker's grip. The network architecture is shown in Figure 11.
Since both hockey and the attacker have only one, the bounding box with the highest credibility score is selected as the prediction result. The loss function is the same as the loss function of tiny-YOLOv3 mentioned in method 1.

Prediction Computing
The prediction of the hockey end position is divided into preliminary prediction and final prediction. The preliminary prediction uses the direction of force applied by the attacker before hitting the ball as the basis for rough estimation of the hockey end position. It is carried out when the distance between the attacker's grip and the stick is less than 10 cm. The results of the prediction are divided into three areas, as shown in Figure 12, which are the upper half of the defense area (area 6, 7, 8), the lower half (area 0, 1, 2), and the center area (area 3, 4, 5). If it is the upper half, the defender moves to area 6; if it is the lower half, it moves to area 2; if the prediction result is in the center area, the defender stays in area 4.
Preliminary predictions will be conducted with a neural network-like method to compare the accuracy of predictions of different network architectures, and the architecture with the highest accuracy selected as a neural network architecture such as this prediction method. This system regards predicting the final area of hockey as a classification problem, and uses an open source tool, Auto-Keras [28][29][30], to search the network architecture.

Prediction Computing
The prediction of the hockey end position is divided into preliminary prediction and final prediction. The preliminary prediction uses the direction of force applied by the attacker before hitting the ball as the basis for rough estimation of the hockey end position. It is carried out when the distance between the attacker's grip and the stick is less than 10 cm. The results of the prediction are divided into three areas, as shown in Figure 12, which are the upper half of the defense area (area 6, 7, 8), the lower half (area 0, 1, 2), and the center area (area 3, 4, 5). If it is the upper half, the defender moves to area 6; if it is the lower half, it moves to area 2; if the prediction result is in the center area, the defender stays in area 4.
Preliminary predictions will be conducted with a neural network-like method to compare the accuracy of predictions of different network architectures, and the architecture with the highest accuracy selected as a neural network architecture such as this prediction method. This system regards predicting the final area of hockey as a classification problem, and uses an open source tool, Auto-Keras [28][29][30], to search the network architecture. We use the two different input data sets to search for suitable network architecture and compare its prediction accuracy. Data set 1 is 1000 pieces of data of the two grip positions before hitting the hockey. As shown in Figure 13,  We use the two different input data sets to search for suitable network architecture and compare its prediction accuracy. Data set 1 is 1000 pieces of data of the two grip positions before hitting the hockey. As shown in Figure 13, X 1 , Y 1 , X 2 , Y 2 represent the position of the two-point grip. Data set 2 is the two-point grip position before hitting the hockey ball, plus the 1000 data of the current position of the hockey ball. As shown in Figure 14, H x1 , H y1 , H x2 , H y2 represent the two-point grip position and B x , B y represent the hockey position. The operation of neural network is as follows. A neuron with label y j receives an input x i such as X 1 , Y 1 , X 2 , Y 2 , H x1 , H y1 , H x2 , H y2 from predecessor neurons by a connection assigned a weight w ji .
where W j = · · · w ji · · · T and X = · · · x i · · · T . The error e j between real output d j and y j is then rewritten as The total error is 1 2 that implies 1 2 By introducing a parameter η called the learning rate, the new weighting W new j is obtained by This expression means that each input will correspond to a different weight, and the output is multiplied by the weight to calculate the input of the next layer, and the weight is continuously updated until convergence, which finally gives the continuous output.
This expression means that each input will correspond to a different weight, and the output is multiplied by the weight to calculate the input of the next layer, and the weight is continuously updated until convergence, which finally gives the continuous output.    The output of the two data sets are the respective probabilities of regions 2, 4, and 6, and because of the different input values, the input data will be normalized first. Here, the minimum and maximum normalization (min-max normalization) scale the data to the interval (0,1), and different network architectures and different excitation functions are experimented with. The final output layer uses the softmax function to normalize the output value to the (0, 1) interval, which provides a representation of the probability of the three regions. The sum is one, and the maximum value is taken as the prediction region, the loss function is cross entropy, and the learning optimization algorithm used is adam.
The final prediction uses the linear formula mentioned in method 1 combined with the law of reflection to predict the final zone position of the hockey when the hockey passes the center line.

Control
The control mechanism of initializing a stepper motor is the same used in method one. The movement after initialization will be moved according to the two prediction results. The movement based on the preliminary prediction result is called the first stage movement, and the movement based on the final prediction result is called the second stage movement. The output of the two data sets are the respective probabilities of regions 2, 4, and 6, and because of the different input values, the input data will be normalized first. Here, the minimum and maximum normalization (min-max normalization) scale the data to the interval (0,1), and different network architectures and different excitation functions are experimented with. The final output layer uses the softmax function to normalize the output value to the (0, 1) interval, which provides a representation of the probability of the three regions. The sum is one, and the maximum value is taken as the prediction region, the loss function is cross entropy, and the learning optimization algorithm used is adam.
The final prediction uses the linear formula mentioned in method 1 combined with the law of reflection to predict the final zone position of the hockey when the hockey passes the center line.

Control
The control mechanism of initializing a stepper motor is the same used in method one. The movement after initialization will be moved according to the two prediction results. The movement based on the preliminary prediction result is called the first stage movement, and the movement based on the final prediction result is called the second stage movement.
Since the movement is divided into two stages, there will be two different movement conditions. The first situation is that when the movement direction of the second stage control is the same as that of the first stage, the starting torque of the second stage control only needs to be the same as the torque of the first stage control to drive the movement of the defender; therefore, it is at the pulse frequency. The selection of this is the same as the pulse frequency of the first stage.
The second situation is that the movement direction of the second stage control is different from that of the first stage. Since the interval between the two stages of control is quite short, the movement of the second stage immediately after the end of the first stage will cause the motor to move in the first stage. After the stage control operation is completed, the discharge is not complete. If the motor is controlled with the same pulse frequency as the first stage control, the motor will not be able to drive the second stage operation due to insufficient torque, and the motor will lose step. Therefore, two methods are proposed. Different stepping motor control mechanisms are used, and their out-of-step conditions and the time spent moving are compared. Therefore, two different stepping motor control mechanisms are proposed and compared for the out-of-synchronization situation and the time taken to move.
The first control mechanism is to start slowly and then run at a constant speed and then stop, and when the moving directions of the two stages are different, the start pulse frequency of the second stage is reduced to increase the torque, as shown in Figure 15, to smoothly control the motor.
The second control mechanism is to change the two-stage motor control to a slow start and a constant speed operation and then a slow stop for control, as shown in Figure 16.
proposed and compared for the out-of-synchronization situation and the time taken to move.
The first control mechanism is to start slowly and then run at a constant speed and then stop, and when the moving directions of the two stages are different, the start pulse frequency of the second stage is reduced to increase the torque, as shown in Figure 15, to smoothly control the motor.
The second control mechanism is to change the two-stage motor control to a slow start and a constant speed operation and then a slow stop for control, as shown in Figure 16.   proposed and compared for the out-of-synchronization situation and the time taken to move.

Experimental Environment and Results
The first control mechanism is to start slowly and then run at a constant speed and then stop, and when the moving directions of the two stages are different, the start pulse frequency of the second stage is reduced to increase the torque, as shown in Figure 15, to smoothly control the motor.
The second control mechanism is to change the two-stage motor control to a slow start and a constant speed operation and then a slow stop for control, as shown in Figure 16.

Experimental Environment
The air hockey table and related parameters are shown in Figure 17 and Table 1.

Experimental Environment
The air hockey table and related parameters are shown in Figure 17 and Table 1.      STM32 is a 32-bit microcontroller launched by STMicroelectronics and is equipped with a variety of communication interfaces: I2C, SPI, UART, etc., which can be connected to sensors or used as independent controllers according to needs. The development environment of STM32 uses the C language, and there are many different series of choices according to the needs. In this work, we chose 32F072BDISCOVERY based on Cortex-M0 as the core, as shown in Figure 18, with four sets of UART, two sets of SPI, two sets of I2C, and other interfaces. The linear slide used in this work is a ball-type linear slide, as shown in Figure 19. The stepping motor in this work adopts the model 42BYGH4417 NEMA 17, as shown in Figure 20, which is a two-phase, four-wire motor with an 8 mm screw rod diameter and a minimum movement about 0.001 m.   Table length  109 cm  Table width 59 cm Goal width 19 cm Air hockey ball diameter 6.3 cm Plstic handle diameter 7.5 cm STM32 is a 32-bit microcontroller launched by STMicroelectronics and is equipped with a variety of communication interfaces: I2C, SPI, UART, etc., which can be connected to sensors or used as independent controllers according to needs. The development environment of STM32 uses the C language, and there are many different series of choices according to the needs. In this work, we chose 32F072BDISCOVERY based on Cortex-M0 as the core, as shown in Figure 18, with four sets of UART, two sets of SPI, two sets of I2C, and other interfaces. The linear slide used in this work is a ball-type linear slide, as shown in Figure 19. The stepping motor in this work adopts the model 42BYGH4417 NEMA 17, as shown in Figure 20, which is a two-phase, four-wire motor with an 8 mm screw rod diameter and a minimum movement about 0.001 m.     In addition, the pixel of the camera is set to 640 × 480 and the operating system of the personal computer (PC) is Windows 10. The PC hardware equipment is listed in Table 2.

Experimental Results
The following experimental results are presented: identification effect of the self-trained tiny-YOLOv3, the accuracy and execution time of the hockey end position prediction of the different methods, the frequency pulse combination of different modes of stepping motors, the defender's movement control in method 2, the fastest ball speed that the system can block after the actual test, and 100 actual game results.

Identification Effect of the Self-Trained Tiny-YOLOv3
Because the background of the training data is similar, the number of training times is set to 1000, and the IoU and credibility score thresholds are set to 0.5 after the model converges, and the identification of 100 actual game images is tested. The pixel setting is 640 × 480. The average position and recognition speed is 30 frames per second. All the targets in the test data include hockey and the attacker's grip. The classification results and positioning errors are shown in Tables 3 and 4. In addition, the pixel of the camera is set to 640 × 480 and the operating system of the personal computer (PC) is Windows 10. The PC hardware equipment is listed in Table 2.

Experimental Results
The following experimental results are presented: identification effect of the self-trained tiny-YOLOv3, the accuracy and execution time of the hockey end position prediction of the different methods, the frequency pulse combination of different modes of stepping motors, the defender's movement control in method 2, the fastest ball speed that the system can block after the actual test, and 100 actual game results.

Identification Effect of the Self-Trained Tiny-YOLOv3
Because the background of the training data is similar, the number of training times is set to 1000, and the IoU and credibility score thresholds are set to 0.5 after the model converges, and the identification of 100 actual game images is tested. The pixel setting is 640 × 480. The average position and recognition speed is 30 frames per second. All the targets in the test data include hockey and the attacker's grip. The classification results and positioning errors are shown in Tables 3 and 4.

Accuracy and Execution Time of the Hockey and Position Prediction for Different Methods
In preliminary prediction of method 2, as shown in Table 5, we set up eight models with different parameters to train neural networks, including 1000 training data, 500 test data, and 10,000 training times. The input layer and hidden layer in the model all use the same excitation function for nonlinear conversion. In the final prediction of method 2, the final position of the hockey ball after passing through different designated areas was predicted by a linear formula combined with the reflection law. A total of 500 data were tested. As shown in Table 6, the experimental results show that the hockey has a higher accuracy rate after passing the center line. Finally, accuracy and execution time of the hockey and position prediction for different methods are listed in Table 7. Since system implementation method 2 has best accuracy and execution time of the hockey and position prediction, we adopt system implementation method 2 to be the main method for later experiments.  Table 6. Prediction accuracy and execution time in method 2.

Final Prediction (Linear Formula Combined with the Reflection Law) Accuracy Execution Time (Millisecond)
Hockey prediction after hockey passes the attack line 0.79 0.04 Hockey prediction after passing the center line 0.84 0.04 Table 7. Accuracy and execution time of the hockey end position prediction of different methods. The stepping motor control mechanism of method 2 is divided into two stages with the same moving direction and two stages with different moving directions to compare the moving time under different control mechanisms. The instructions follow.

Method
As shown in Figure 21, the control mechanism of two stages with the same moving direction (for example, 4 → 6 → 8) is Start slowly → Constant speed operation → Stop. We experimented with five different progressive pulse frequency combinations, as shown in Figure 22 and Table 8. The movement time in Table 8 is the total time (unit: second) to move the four defensive areas, and T represents the number of pulses required to move one area. We used the fastest mode five that does not cause the motor to lose step and the fastest moving speed as the pulse frequency to control the motor when the direction is the same.
(for example, 4 → 6 → 8) is Start slowly → Constant speed operation → Stop. We experimented with five different progressive pulse frequency combinations, as shown in Figure 22 and Table 8. The movement time in Table 8 is the total time (unit: second) to move the four defensive areas, and T represents the number of pulses required to move one area. We used the fastest mode five that does not cause the motor to lose step and the fastest moving speed as the pulse frequency to control the motor when the direction is the same.  (for example, 4 → 6 → 8) is Start slowly → Constant speed operation → Stop. We experimented with five different progressive pulse frequency combinations, as shown in Figure 22 and Table 8. The movement time in Table 8 is the total time (unit: second) to move the four defensive areas, and T represents the number of pulses required to move one area. We used the fastest mode five that does not cause the motor to lose step and the fastest moving speed as the pulse frequency to control the motor when the direction is the same.   As shown in Figure 23, there are two control mechanisms for two stages with different moving directions (for example, 4 → 6 → 4). The first control mechanism is Start slowly → Constant speed operation. In the second stage, it started with a lower frequency pulse, and experimented with five different progressive pulse frequency combinations, as shown in Figure 24. The second control mechanism is Start slowly → Constant speed operation → Stop slowly. We also experimented with six different progressive pulse frequency combinations, as shown in Figures 25 and 26. The experimental results are shown in Tables 9 and 10. The movement time in Tables 9 and 10 is the total time (unit: second) to move the four defense areas, and T represents the number of pulses required to move one area. After comparison, it is found that mode 5 of control mechanism 1 will not cause the motor to lose step and move the fastest. Mode 5 of control mechanism 1 is used as the pulse frequency to control the motor when the direction is opposite. Hz × (2T-10) 0.668 no As shown in Figure 23, there are two control mechanisms for two stages with different moving directions (for example, 4 → 6 → 4). The first control mechanism is Start slowly → Constant speed operation. In the second stage, it started with a lower frequency pulse, and experimented with five different progressive pulse frequency combinations, as shown in Figure 24. The second control mechanism is Start slowly → Constant speed operation → Stop slowly. We also experimented with six different progressive pulse frequency combinations, as shown in Figures 25 and 26. The experimental results are shown in Tables 9 and 10. The movement time in Tables 9 and 10 is the total time (unit: second) to move the four defense areas, and T represents the number of pulses required to move one area. After comparison, it is found that mode 5 of control mechanism 1 will not cause the motor to lose step and move the fastest. Mode 5 of control mechanism 1 is used as the pulse frequency to control the motor when the direction is opposite.          In order to successfully block the hockey, the sum of the recognition time, prediction time, and defender movement time must be less than the hockey movement time (hockey movement distance/fastest ball speed). The hockey movement distance is from the midpoint of the attack line to the farthest defense; i.e., the distance of the area (area 8/area 0). The experimental results are shown in Table 11. The actual game prediction method is to use method two and model 5 as the neural network architecture for preliminary prediction. After the hockey passes the center line, the final prediction is made by using linear formulas and the law of reflection. The number of games is 100. The fastest ball speed does not exceed 1.15 m/s. The statistical results are shown in Table 12. The actual blocking probability in most areas is much lower than the final prediction accuracy. The reason is that the initial prediction error caused the defender to move the farthest area by two. The reason for the increase to six and the actual blocking probability in area 5 being greater than the predicted correct rate is because the hockey is recorded as a blocking during the movement success, although the defender move is based on the result of the wrong prediction.

Conclusions
From the experimental results, it is found that the method of prediction using the law of reflection can block the fast-moving hockey instantly when the hockey speed does not exceed three meters per second. When predicting with the direction of the force, it is found that when the player uses wrist movement to swing, it will reduce the accuracy of the predictions. In the future, player gestures will be added as neural networklike inputs to improve the accuracy of the predictions, and control of return strategies will be added.