# Implementing an Industry 4.0 UWB-Based Real-Time Locating System for Optimized Tracking
## 3 Materials and Methods
### Proposed Real-Time Locating System
If the absolute value of the radial displacement between the \(anchor_{j}\) and the \(tag_{i}\) exceeds the distance that the tag can cover at its maximum speed in the time window \(dt_{ij}\), the measurement becomes unreliable, suggesting that an obstruction is blocking the direct path communication between them; therefore, we can conclude that the communication was performed under NLOS conditions. Thus, before estimating the tag's position, the algorithm compares all the anchor-tag distances with their previous measurements and characterizes them as LOS or NLOS. In the second step, we developed an algorithm that processes the received distance measurements for the estimation of the tag's position. As the system captures data streams from the hardware components, the algorithm calculates the \(NLOS_{ij}\) table for identifying the LOS/NLOS condition of each measurement. Based on data from each tag, the software calculates the tag's position using the trilateration algorithm. In the event that there are measurements from more than three anchors, the extra anchors' measurements are used for position verification purposes. If the tag's position must be identified from two anchors, localization is still possible. When only two anchors are available for the estimation of the tag's location, Equation (9) is used:  
\[ \begin{cases}(x-x_{1})^{2}+(y-y_{1})^{2}={d_{1}}^{2}\\ (x-x_{2})^{2}+(y-y_{2})^{2}={d_{2}}^{2}\end{cases}  \tag{9}\]  
Figure 6: System and application architecture. The above system can either have a single solution, or two distinct x and y pairs, as shown in Figure 7. To solve the system, an extra source of information is needed, in order to pinpoint the tag's location. In this case, the localization will be unfeasible if the tag moves further to one of the two half planes. If the distance between point A and B is two times greater than the distance that the tag can travel at the time window \(dtr_{ij}\) we are sure that the tag is at the same half plane, and we can reject one of the two solutions. Summarizing the above findings, the following inequality must be satisfied:  
\[\sqrt{\left(x_{A}-x_{B}\right)^{2}+\left(y_{A}-y_{B}\right)^{2}}>2\times Vmax_ {i}\times dt_{ij} \tag{10}\]  
Another solution involves including some limitations for the anchor devices. In most cases, the anchors are placed close to the walls, so one of the two solutions is unfeasible because it does not belong to the solution space (it is not in the industrial area). As a conclusion to the above analysis, the final algorithmic steps that calculate the tags' location are presented; Figure 8 presents the flowchart of the algorithm. ```
1:rjj,t1,rjj,t2,NLOSjj \(\longleftarrow\) 0
2:while (1) do:
3:rjj,t1 \(\longleftarrow\) rjj,t2
4:read anchor's data streams rjj,t2 from USB/WiFi
5:calculate new rjj,t2, dtjj and drjj
6:for i in Tags do:
7:calculate newNLOSjj for tag i based on Vmax speed
8:numberOfLOSmeasurements = [];
9:numberOfNLOSmeasurements = [];
10:for j in Anchors do:
11:ifdr[i][j] > 0 and NLOS[i][j] = 0 and newNLOS[i][j] = 0 then
12:numberOfLOSmeasurements.add(rjj,t2);
13:else
14:numberOfNLOSmeasurements.add(rjj,t2);
15:endif
16:endfor
17:ifnumberOfLOSmeasurements.size() > 3 then
18:Tag i[x][y] \(\longleftarrow\) Normal_Trilateration(numberOfLOSmeasurements)
19:elseifnumberOfLOSmeasurements.size() = 3 then
20:Tag i[x][y] \(\longleftarrow\) Normal_Trilateration(numberOfLOSmeasurements)
21:elseif(numberOfLOSmeasurements.size() = 2 then
```  
**Algorithm 1**System algorithm for NLOS minimization and tag position estimation  
Figure 7: Trilateration with two LOS anchor–tag measurements. Figure 8: Flowchart of the proposed algorithm.