# Construction of Robotics and Application of the Optical-Flow Algorithm in Determining Robot Motions
## 2 Methodology  
In this section, the methodology to determine the velocity and angles of the robot using a single camera is presented. The main idea in this study is to use one camera to determine the position and velocity of the model. Currently, there are various methods to determine the distance from the surveillance camera to the object. Each method has its advantages and disadvantages. The stereo camera method [13] offers high accuracy, but the processing is quite complex, and the hardware system configuration is quite expensive. The method using a camera combined with a gyroscope sensor also provides relatively accurate results, but the system cost is still high due to the use of the gyroscope sensor, and the setup and calculation process is complex [4]. The method that combines the technical parameters of the camera and the actual size of the object also requires accurate camera parameters, which are not always possible to determine. Therefore, it reduces the flexibility of the system [3]. To overcome the drawbacks of the aforementioned methods, we propose using a new, simple approach that utilizes parameters in the object recognition problem to build estimation functions to determine the distance and movement angle of the object corresponding to the position of the surveillance camera. The algorithm and application in the robot are presented as follows. First of all, to detect the motion of the robot, we use a camera at the center, as shown in Figure 1. The camera is located at the position O of the system coordinate \(xOy\). Here, the system coordinate \(xOy\) is fixed with the camera in Robot 1. Point A refers to the position of the object in the \(xOy\) coordinate, so the position of point \(A\) is as \(X_{A}\) and \(Y_{A}\). Note that this is a two-dimensional system, and the workspace can be captured well by the camera. The fields of view of the camera are shown by the dark region with a limited angle \(\psi\), generated by upper and lower lines. The position of the object at time \(t_{1}\) is at \(A_{1}\), and it turns to \(A_{2}\) at time \(t_{2}\). We observe that if the object can be determined, the distance \(d_{1}\) from the camera to the object at time \(t_{1}\) is found, and the viewing angle \(\alpha_{1}\) is found, we can determine the position \(A_{1}\) using the following formula:  
\[X_{A_{1}}=d_{1}\cos(\alpha_{1}) \tag{1a}\] \[Y_{A_{1}}=d_{1}\sin(\alpha_{1}) \tag{1b}\]  
Similarly, by applying Formula (1), we can also determine the position of the object at time \(t_{2}\) (point \(A_{2}\)). After determining the position of the object at time \(t_{1}\) (point \(A_{1}\)) and time \(t_{2}\) (point \(A_{2}\)), we can determine the direction of the object's movement through the vector \(A_{1}A_{2}\) as follows:  
\[A_{1}^{\rightarrow}A_{2}=(X_{A_{2}}-X_{A_{1}};\ Y_{A_{2}}-Y_{A_{1}}) \tag{2}\]  
Figure 1: Workspace and setup of the camera. The object's movement speed can be relatively determined using the expression:  
\[v=\frac{\left| \begin{matrix}A_{1}^{\rightarrow}A_{2}\\ \Delta t\end{matrix} \right|}{\Delta t}=\frac{\sqrt{\left(X_{A_{2}}-X_{A_{1}} \right)^{2}+\left(Y_{A_{2}}-Y_{A_{1}}\right)^{2}}}{\left(t_{2}-t_{1}\right)} \tag{3}\]  
The object's movement angle is determined as follows:  
\[\varphi=a\tan\left(\frac{v_{y}}{v_{x}}\right)=a\tan\left(\frac{Y_{A_{2}}-Y_{A_ {1}}}{X_{A_{2}}-X_{A_{1}}}\right) \tag{4}\]  
Each position is featured by two parameters of \(d\) and \(\alpha\). When these two parameters are determined, the velocity and angle of the objects can be found. By leveraging image processing techniques, we can extract key parameters (height \(h\) and horizontal offset \(\Delta x\)) of an object within a camera's field of view. These parameters vary with the object's position.