# Evaluation of PID-Based Algorithms for UGVs
## 3 Methodology
### PID Controller
#### 3.4.1 PID Heading Controller  
The PID Heading Controller (PID-H) aims to control both linear and angular trajectories. To achieve this, two independent PID controllers are used, as shown in Figure 6, where the initial focus is located on a line with the destination coordinates. This initial alignment adjusts the UGV relative to the destination point with a precision of up to four degrees, which is the accepted angular threshold. The error values related to the robot's orientation and its position relative to the destination are updated during the navigation process. The system thus allows for a maximum limitation of \(\pm 2\) degrees within the scope of orientation error. The voltage applied to the tracks is corrected when the controller detects that this limit has been exceeded. Therefore, the UGV stays on the path between the origin and the destination. As the angular error is reduced, this effect contributes to a smooth trajectory and applies a voltage level to the robot's tracks corresponding to the calculated error. The angular error between the robot and the destination point is input as a reference into the PID controller as the robot starts its trajectory, intending to align the robot with the destination point as accurately as possible. The algorithm aims to optimize navigation, ensuring precise and smooth movement toward the destination. In this study and analysis context, various variables play crucial roles in understanding and controlling the system shown in Figure 6.  
The variable Desired Heading (\(\theta\)Des) represents the desired orientation or the angle to be reached or maintained by the system. The variable Target (T) defines the desired location on the map. The variable Actual Position (AP) is the precise position relative to a reference point. The variable Heading Error (eHead) is the error between the desired angle (\(\theta\)Des) and the actual angle (\(\theta\)) of the system. The variable Position Error (ePos) is the error between the desired position (T) and the actual position (AP) of the system. The variable Angular Value (\(\omega\)r) represents the angular value associated with rotational or curvilinear movement. The variable Linear Value (Vr) represents the linear motion of the system, and the variable Actual Heading (\(\theta\)) indicates the actual angle or current orientation of the system. The variable Microcontroller (\(\mu\)C) is the \"brain\" of the system, responsible for processing the values obtained from the \"cmd_vel\" topic to control the UGV. The variables Voltage Right Wheel (VR) and Voltage  
Figure 6: Controller with error associated with heading. Left Wheel (VL) indicate the voltages applied to the right and left wheels, respectively, of the locomotion system to influence movement and direction. The algorithm is shown in the pseudocode below (Algorithm 2), aiming to move as illustrated in Figure 7. It is somewhat more complex than the previous one, as it incorporates a PID controller in its control system. The scenario outlined by the presented pseudocode defines a highly sensitive navigation process where the UGV dynamically adapts to various circumstances. The foundation of this process relies on two flags: \"Flag_Goal_Reached\" and \"Flag_Rotation\". The first flag starts inactive, indicating that the destination has not yet been reached, while the second flag starts inactive. The second flag starts inactive, indicating that the destination has not yet been reached, while the second flag starts inactive. Figure 7: Trajectory with the PID Heading algorithm. begins active, signaling the need for a rotation. The detection of people is a priority, leading to an immediate stop of the UGV if detected. In the absence of people, the algorithm guides the UGV according to the planned trajectory. When a rotation is needed (\"Flag_Rotation\" is active), the algorithm checks whether it has been completed or if no position change has occurred after 10 s. If the rotation is completed, the machine stops, and \"Flag_Rotation\" is deactivated.