# Evaluation of PID-Based Algorithms for UGVs
## 3 Methodology
### PID Controller
#### 3.4.2 PID Heading Cross Track Error Controller  
The PID CTE (Cross Track Error) controller autonomously manages both linear and angular trajectories using two separate PID controllers, as shown in Figure 8. The error values are continuously updated during the navigation process and include the robot's relative position concerning the line and its final destination. A maximum tolerance of \(\pm 10\) cm is considered for the position error relative to the desired trajectory. The controller adjusts the voltage supplied to both tracks when it detects that the robot is nearing the allowed tolerance. This adjustment enables the UGV to navigate accurately, keeping it close to the planned trajectory between the origin and destination.  
The position error serves as a reference, allowing the system to modify the voltage applied to the tracks depending on the proximity to the destination. This means that the voltage can either increase or decrease based on the distance, enabling the UGV to adapt to changing conditions.  
In this study and analysis, several variables play crucial roles in understanding and controlling the system shown in Figure 8. These are similar to the previously mentioned variables, except for the desired distance from the line (D_DFL), the current distance from the line (A_DFL), and the error in this distance (e_CTE).  
The PID CTE algorithm, as shown in the pseudocode below (Algorithm 3), aims to move the UGV as depicted in Figure 9. This algorithm is quite similar to the previous one, but the error variable used as input for the PIDs is based on the distance between the robot and the desired trajectory.  
Figure 8: Controller with error associated with trajectory distance.  
```
Flag_Goal_Reached = FALSE Flag_Rotation = TRUE FORcoordinates in FILE: WhFILE Flag_Goal_Reached = FALSE: IF detect_people = TRUE: \(V_{L}=0\) and \(V_{R}=0\) (STOP MACHINE) ELSE: IF Flag_Rotation = TRUE IF Not_Aligned AND 10_Seconds_Passed_Without_Changing_Position: \(v=0\) and \(\omega\
eq\ 0\) (ROTATE MACHINE) ELSE: \(\text{Original\_Position = Actual\_Position}\) Flag_Rotation = FALSE ELSE: \(e_{Position}=\sqrt{\left(T_{x}-A_{Px}\right)^{2}+\left(T_{y}-A_{py}\right)^{2}}\) \(e_{CTE}=Actual_{DistanceFromLine}-Desired_{DistanceFromLine}\) IF \(e_{Position}\leq R\): \(V_{L}=0\) and \(V_{R}=0\) (STOP MACHINE) Flag_Goal_Reached = TRUE Flag_Rotation = TRUE ELSE: \(\omega=K_{p}^{DEL}e_{CTE}+K_{i}^{DEL}\int e_{CTE}\ dt+K_{d}^{DEL}\frac{de_{CTE}}{dt}\) \(\text{Linear\_PID}\) \(v=K_{p}^{linear}e_{Position}+K_{i}^{linear}\int e_{Position}\ dt+K_{d}^{linear}\frac{de_{Position}}{dt}\) \(V_{L}=v-\frac{L}{2}\omega\) AND \(V_{R}=v+\frac{L}{2}\omega\)
```  
**Algorithm 3** PID Cross Track Error controller.  
This pseudocode outlines the UGV's navigation approach, focusing on both efficiency and safety as it follows a predefined path. The flags \"Flag_Goal_Reached\" and \"Flag_Rotation\" are central to this algorithm, guiding the UGV's behavior in response to various contexts. While traversing coordinates, the algorithm prioritizes two aspects: detecting people and adjusting the trajectory. If people are detected, the UGV immediately stops to ensure safety. In the absence of detection, the focus shifts to movement precision. When rotation is necessary (\"Flag_Rotation\" is activated), the system checks whether the UGV is misaligned and, if there is no positional change after 10 s (indicating it is stuck), the rotation is performed. If the criteria are not met, the original position is logged, and the \"Flag_Rotation\" is deactivated. When no further rotation is needed (\"Flag_Rotation\" = FALSE), the algorithm checks whether the destination has been reached. If the goal is met, the UGV stops, the \"Flag_Goal_Reached\" is activated, and the movement ceases. If  
Figure 9: Trajectory with the PID CTE algorithm.  
the goal has not been reached, errors in distance from the target and line are calculated, allowing the UGV to adjust its trajectory accurately.