Simulation and Validation of Optimized PID Controller in AGV (Automated Guided Vehicles) Model Using PSO and BAS Algorithms

Automated guided vehicles (AGVs) are popular subsets of robots that come in various shapes and sizes. The group's use in the industry ranges from applications for carrying pallets, carts, and utensils to helping the elderly or transporting medicine to hospitals. Even recently, they have been used in libraries to carry books on shelves. The main part of an AGV includes its body, motor, driver, processor, and sensors, which are more or less the same in all types of AGVs, and addons vary depending on the application and the work environment. The part that affects AGV performance is the control strategy, to which researchers have shown different approaches. Using various techniques and simulations to obtain a model is the key and can help to improve and evaluate the performance of the strategy of the robot. In this study, based on the actual design of the AGV system, all data and components are described, and the simulation is performed in MATLAB software. Then, for controlling the platform based on the PID controller tuning, four methods of Ziegler Nichols, empirical, Particle Swarm Optimization (PSO), and Beetle Antennae Searching (BAS) (optimizer) are discussed, and the results are compared in the four paths including the circle, ellipse, Spiral and 8-shaped paths by observing and testing the tuned PID parameters. Finally, a series of subsequent experiences were carried out in CoppeliaSim (VREP) as a famous robot simulator to overcome the environmental constraints for the same paths that were used in Matlab based on the extracted PID values. Based on the results, the empirical methods, PSO, and BAS errors are very close together. But in general, the BAS algorithm is the fastest, and the PSO had better performance. In general, the maximum error is linked to the path of 8 shapes and the minimum is related to circle shape one. Finally, the analysis of results in different paths in both simulators shows the same results. Therefore, concerning the limited test on the real platform and using the PID coefficients obtained from the simulation shows the model's ability for the researchers in robotic research.


Introduction
Automated Guided Vehicles (AGVs) play a pivotal role in robotics and have become an indispensable part of it. Based on history, AGVs introduced in 1953 are known as comparatively older inventions, but regardless of their age, the increasing applications show the increased demand in the industry and are being improved by AI day by day [1]. Tese improvements open up an opportunity for researchers to investigate the limitations that AGV robots may bring. Te AGVs are used in various applications, and recently due to COVID-19 restrictions, AGVs' demand is increased in various applications to provide better service and assistance in hotels, hospitals, restaurants, assist patients, etc., during the lockdowns around the world [2]. AGVs consist of three main parts: the frame and its installed device, models and sizes, and the navigation and actuator systems. Based on their application and role as service robots, these robots can be categorized in various shapes and structures, from dualwheel to worm shapes [3]. But other than the shape, the control section is known as one of the main issues investigated by various researchers over the years. Reviewing published research about the AGV controlling part shows,Kodagoda et al. showed a fuzzy logic control (FLC) with uncoupled vertical and horizontal control for a golf car as the AGV. Tis AGV has four wheels, with the steering control system, which is driven by a permanent magnet DC motor besides, the active deceleration of AGV is to drive the stepping motor to control the cable connected to the brake golf car pedal. Te encoder calculates the speed of AGV on four wheels, and the encoder obtains the steering angle and angular speed on the steering shaft. Te longitudinal control is realized by two uncoupled fuzzy drive controllers and fuzzy brake controllers, and the lateral controller is also obtained by fuzzy logic. By comparing the proposed FLC scheme with the traditional PID scheme, the paper concluded that the proposed FLC have better performance in tracking, smaller steady-state error, and powerful in load changing, coupling efects, operating point changes, and road grade changes [4]. Suárez et al. designed a method to determine the Ackerman steering system's longitudinal and steering system model-based AGV. Tey proposed the longitudinal model based on the speed step response and obtained the steering system model by simulating the behaviour of the PID controller, the motor, and the steering system load with MATLAB. Te fuzzy controller, pure pursuit controller, ε-Controller with PI regulator, and ε--Controller with the PI regulator are used and was tested on the semicircular path with a radius of 25 meters. Te result shows that the fuzzy controller, pure pursuit controller performed worst, and the ε-Controller with PI regulator and ε-Controller with the PI regulator is robust, and almost both controllers worked the same [5]. Chen et al. proposed PID controllers and fuzzy PID controllers for electric vehicles driven by two-wheel hub motors. Te AGV simulation was built on two rear-wheel hub motors that drove eleven degrees of freedom and two models. Tey proposed adjusting the traction force acting on the two drive wheels according to the slip rate and yaw rate to improve the handling and stability of the vehicle. Trough the simulation experiment in MATLAB/Simulink environment, comparing PID controller, fuzzy PID controller, and without a controller, they found that PID controller and fuzzy PID controller can improve the control stability of the vehicle. However, it does not afect the vertical movement of the vehicle [6]. Faber Archila and Becker developed an electric vehicle with four wheels driven by two hub DC motors mounted on the front axle and the control system. Te control system consists of two levels. Te motor controller is responsible for running the motor in the appropriate model at the low level to generate the required motor torque. Te torque coordination controller can correctly coordinate the motor torque at a high level and provide stability and consistent steering performance during the control saturation period. Te Adams software is used for simulation as the simulator, and the current control adopts the PI controller. Te results show that the control system can successfully realize the vehicle's drive-by-wire, steer-by-wire, and power steering functions [7]. Gupta et al. proposed a trajectory tracking system based on a tricycle AGV that involves a front driving wheel and two passive rear wheels. Te trajectory tracking algorithm is used as the pure tracking algorithm based on curvature calculation which is worked based on forwardlooking distance as the main used parameter calculating the arc. Besides, in their research, the laser and receiver SICK equipment (AUTO-NAV200) installed on the AGV rotating tower determines the automatic positron emission and direction. Te experiment is carried out on a rectangular path and shows that the AGV can follow the path to reach the target position, with an acceptable position error of less than 5% [8]. Te four-wheel mobile AGV structure with the fuzzy PID controller was studied by Liu et al. In the simulation surrounding for tracing target, and as a result, they mentioned the AGV fast performance with the stability antiinterference in trajectory task [9]. Parikh et al. used Arduino and a DC motor as the main part of the AGV robot and simulated them in MATLAB Simulink. Te AGV has four wheels, is driven by a DC motor, and uses infrared sensors for tracking. Ten, the simulated model analyzed the speed of the AGV with the P, PI, and PID controller system, which is tuned by the Ziegler-Nicholas algorithm on a straight path to fnd an AGV system that can run at a uniform speed. Tey investigated the AGV response over the PID parameters; they found that the overshoot of the P controller is small, but the steady-state error is high and needs more time to stabilize. In the PI controller, the AGV is unstable, and with the PID controller, It can normally work with the ignorable overshoot. Tey concluded that the ZN algorithm and PID controller is more suitable [10]. AGV trajectory tracking control method for AGV was studied by Chen et al. Te results of the AGV platform consist of two independently driven wheels and one driven wheel. Ten, if the AGV needs to run in reverse, the wheels rotate the AGV's coordinate system 180 degrees, and then the tail's and head's positions will be changed. Te experiments conducted on sinusoids and paths consisting of segments and arcs found their proposed control method feasible [11]. Li et al., based on the Four-Wheel Independent Steering and Four-Wheel Independent Driving (4WIS-4WID) vehicle model, proposed a system. Teir study consisted of two controllers of fourwheel PID steering and a four-wheel Sliding Mode Controller (SMC) driving for driving and longitudinal motion control. Te research shows that a four-wheel SMC steering controller and four-wheel combined yaw rate and longitudinal velocity SMC driving controller can achieve most of the control objectives. Te simulation result indicated that the four-wheel SMC steering controller, four-wheel combined yaw rate, and longitudinal velocity SMC driving controller are most suitable for 4WID-4WIS vehicles [12]. Zhifu et al. proposed a dynamic torque distribution method for 8x8-wheel motor-driven vehicles to increase the algorithm's speed and the vehicle's response speed to complex road conditions. Te vehicle uses the PID control method to track the longitudinal speed and yaw angle. Te designed framework meant based on the direct yaw moment control method. Analyze the expected acceleration and expected yaw according to the driver's accelerator pedal and steering wheel signals. Te vehicle stability is promised in the steering tracking process Trough simulation experiments on the MATLAB/Simulink platform [13]. Setiawan et al. designed four-wheel independent steering (4-WIS) automatic guided vehicle and proposed a trajectory tracking controller based on the back-stepping method. Tey modelled the 4-WIS AGV by simplifying the ordinary four-wheeled vehicle model to a two-wheeled vehicle model with centreline wheels. Trough simulation experiments, they found that their trajectory tracking controller can very well track sharpedged straight and circular trajectories [14]. Richard and Gang hired the Programmable Logical Controller (PLC) and Radio Frequency Identifcation RFID technology in AGV to control and improve the speed of data fow. Tey use PID controllers for designing and using the Ziegler-Nichols method in Matlab with SISOTOOL to tune PID parameters based on critical gain and critical period [15].
Two-wheel diferential AGV and PID controllers were investigated by Tang et al. Tis study is merged with MATLAB/Simulink as the simulation tool and takes the estimated deviation as input and the diference between the rotational speed of the left and right driving wheels as the output. After tuning the PID parameters and investigating the efect of parameters, the result shows that the designed PID controller can make the AGV perform well in the straight and arc paths [16]. Te physical and simulated models are compared by Papelis and Sakioti to evaluate the fdelity of the simulation model and the infuence of the motor model sensor model. Tey used the Stingray robot kit from Parallax and performed simulations on the Autonomous Robotics Modeling & Simulation Environment (ARMSE) platform. Te line-following robot turns by the return values of 8 infrared sensors. Even though the result shows the robot's performance to follow the line, there are diferences between the simulation and physical models [17]. Zhou et al. designed a fuzzy PID controller for AGV to allow the AGV to operate stably for a long time. Te AGV system consists of an STM32F207 microcontroller, gray sensor, ultrasonic sensor, infrared sensor, camera, wireless module, and other peripheral devices. Due to the system complexity, they address using the Simulink to simulate a fuzzy PID control system to avoid the infuence of parameter changes and external environmental interference. Ten, they reported that the AGV can adaptively modify the control parameters to achieve trajectory tracking better. Experiments have found that the fuzzy PID algorithm is more stable than the traditional PID algorithm [18]. Lego Mindstorms components and Matlab Simulink were used to simulate the AGV with the simple digital control algorithm to realize the tracking function by Abdulhamid and Mutheke. Te robot uses a Lego EV3 motor to drive two front wheels and a robot-supported by two rear wheels. A colour sensor is installed in the front of the robot to identify the line. Tey found that a robot without a controller has many swings in a straight line, which consumes energy and reduces speed, so the efciency of this robot in a straight line is very low. Terefore, they use a PID controller. To obtain the required control efect, they tested multiple sets of K p , K i , and K d parameters, and fnally, they summarized the efects of the three parameters: if the value of K p is increased, the rise time and steady-state error is decreased, the overshoot will be increased, and the setting time will be small changed. If the value of K i increases, the rise time decreases, and the overshoot and settling time is increased. If the value of Kd is increased, the rise time will be a small change, the overshoot will be decreased, the setting time will be increased, and the steady-state error does not change [19]. Xu et al. proposed a hybrid control strategy that combines the yaw angle stability control of the two drive modules with the real-time algorithm to solve poor accuracy and difculty in the arc trajectory tracking process. Tey divided the arc trajectory into three segments: the start, end, and arc segments. Te AGV and the two diferential modules were used in the arc tracking segment. Te AGV assembly consists of a laser navigator, a vision sensor, and two diferential modules. Te front and rear diferential modules include two servo drives and two drive wheels. Te angular velocity constraints between the four driving wheels establish the speed coordination conditions of the four driving wheels. Te trajectory and expected path are simulated by MATLAB simulation, and it is founded that the hybrid control strategy combining the yaw angle stability control module and the real-time correction algorithm has a faster response speed. Te AGV can run smoothly on an arc orbit with a specifed radius but is adjusted in real-time. Its fexibility is poor, and it is necessary to optimize the algorithm to achieve higher accuracy of AGV tracking in the arc trajectory [20]. Te Robust AGV path tracking control strategy was pointed by Wu et al. to improve tracking accuracy and stability. Tey simplifed the complex path tracking problem to a simple yaw angle tracking problem. Te research introduces the strategy based on nonsingular terminal sliding mode (NTSM) and active disturbance rejection control (ADRC). It uses an extended state observer to estimate and compensate for the unmodelled dynamics of external disturbances of the system in real-time. During the research, the CarSim-Simulink simulation and results show that the proposed control strategy can ensure vehicle stability and quickly and accurately follow the reference path [21]. Pliego-Jiménez et al. proposed an inverse dynamics controller to control the tracking of a two-wheel diferential drive vehicle. Te controller is proposed to compensate for the nonlinear problems that occur during the motor action. Te assembly consists of one caster and two DC motor-driven wheels that were simulated with the inverse dynamic controller in MATLAB/Simulink and were compared with the conventional PID controller. Two paths in the form of circular and straight are assumed as the reference path. Te controller controls the tracking trajectory by minimizing the position and angle errors. Te report shows that the proposed controller can reduce the error faster than the traditional Computational Intelligence and Neuroscience 3 PID controller [22]. Zhou et al. and colleagues designed a 16wheel hard AGV system equipped with magnetic tape navigation to track the line. Tey simplifed the 16-wheel heavy AGV into a two-wheel AGV by adjusting the navigation system location based on the Ackerman command principle. MATLAB/Simulink was used to simulate and test the path consisting of a straight line to a curve and a curved line to a straight line. Tey found that the following system design has an acceptable efect on plain, curved, and mixed trajectories [23]. Song proposed a trajectory tracking controller for AGV with time-varying state feedback. Tey used straight paths and circular curve patterns for experiments to check the controller's performance. Te experiment aimed to compare the predicted trajectory by the controller and the actual one on the simulation platform. Tey reported the successful simulation and mentioned that diferent controller parameters could afect the stable response time and steady-state errors. Ten, diferent controller parameters need to be selected according to the trajectory change to achieve a better control efect [24]. High-precision continuous attitude adjustment for AGV path tracking issues are investigated by Weng et al. Tis research proposed an improved model predictive control with a state classifcation model (SCM) and smooth transition (ST) strategy, namely SCMPC-ST. Te Numerical simulation was carried out on MATLAB to compare the integral separation PID (IS-PID), standard SCMPC, and SCMPC-ST under the same resolution. Tey found that it is more efective to adjust the relationship between deviations in some cases than to eliminating them directly [25]. Vartika et al. investigated the two Ziegler-Nichols and genetic algorithm (GA) methods to adjust the parameters of K p , K i , and K d , characteristics. Besides, they compared the rise time and range overshoot characteristics of traditional PID controllers and fuzzybased PID controllers. Te research specifed that to tune the PID parameters compared with the traditional ZN method, the adaptive intelligent PID controller, along with the Fuzzy logic Controller (FLC) and Genetic Algorithm (GA), can ensure improved performance parameters while tuning the parameters of the PID controller [26]. As the survey shows, the most cost-efective approach to solving this issue would be a simulation, which assists scholars in better studying AGVs and their efciency, mainly PID tuning, to improve the movement and control. Although various control methods have been proposed, the study shows that PID controllers have been used as a basic reference for evaluating and expanding other proposed controllers. As the survey shows, PID controllers are well known in various robot applications, and researchers have tried to fnd the best values for these controller parameters by various methods, like meta-heuristic methods in diferent robot felds [27][28][29][30][31][32]. Also, in most of the reported research studies, the assumed values in the modelling section are not real, and the detail of the simulation process for the used AGV is not described from one side; on the other side, few validations on diferent paths shape of the proposed model are investigated. Te present research has been done to present. Te rest of this article is structured as bellows: in part two, the structure and parts of AGV with the mathematical equation and modelling in Matlab software are described. Ten, the PID tuning method based on Ziegler-Nichols and empirical methods with the actual size and specifcation of the designed AGV hired on the model, and the robot performance was analyzed with the various specifc path. Ten, in Section 3, the principle of two metaheuristic algorithms of Particle Swarm Optimization (PSO) and Beetle Antennae Searching (BAS) is initially described and then used to optimize the PID values. Afterwards, the robot's performance was investigated over the diferent path shapes and angular and tangential velocities. After that, the CoppeliaSim (VREP) simulator was used to overcome the real environment test limitation, and the robot's performance over one more path along with the previous one was analyzed. Section four was mentioned as the last part for the paper's conclusion. Te paper's main contribution can be summarized as follows: (1)

Automated Guided Vehicle (AGV) Robot's Construction
In short, the AGV robots can be defned as systems consisting of components such as the main body, motor driver (actuators), navigation and anticollisions, processor, communication systems, and batteries ( Figure 1) of all the above components; the four main parts of the framework, the sensor, the actuator (motor and driver), the controller, shown in Figure 1, are particularly important. Figure 1 shows the AGV platform with two motors (usually DC motors) that act as actuator devices to move and carry the body load. In addition, to compensation, the body wheels and freewheels are often used for balancing the body weights. In line with the research of this paper, the real AGV designed system has six wheels, two diferential drive wheels which are located in the middle, and four passive wheels are placed in the front and back of the vehicle. Tese four passive wheels are responsible for maintaining the horizontal balance of the vehicle. In AGV robots, the number of freewheels based on the motor position can be two or four, and it should be remarked that based on null action to move the body, it does not afect the dynamic equation of the whole system, and it can be considered as a two-wheel robot [33]. Te number of freewheels in AGV robots can be specifed as two or four, depending on the location of the engine in the body. It is important to note that due to the null action for the body movement, the number of freewheels does not change the dynamic equation of the whole system. Terefore, the assumed AGV in this research with the four freewheels can be considered a two-wheeled robot [34]. Figure 2 shows the designed AGV with all system components.
As shown in Figure 2, the designed vehicle assembly consists of 16 magnetic sensors packed in one module, which are responsible for detecting the trajectory. Tere are three types of collision avoidance sensors (ultrasonic, PIX, and two bumper sensors at the front and rear). LCD and controlling the switch. Te vehicle is 0.916 meters long, 0.62 meters wide, and 0.37 meters high, with a wheel diameter of 0.108 meters. For the designed system, Arduino Mega2560 is chosen as the main controller. As stated before, the purpose of this study is to simulate the designed AGV robot in Matlab software and validate the performance of the robot through tracking the various paths. With this aim, the main parts of the AGV can be revealed in Matlab Simulink, as shown in Figure 3. Figure 3, in order to simulate the AGV robot, the platform can be separated into three key modules named: the physical system, sensors, and decision-making parts, which is described as follows.

AGV Physical System Section.
According to the assumed model and structure, the dual-wheeled robot dynamic model and its related parameters were selected. Terefore, based on the mentioned assumption, the physical system includes an inverse dynamic and kinematic model, which is defned below.

Te AGV Dynamic Model.
As stated before, the system assumed based on the dual-wheeled diferential robot is equipped with DC motors on the left and right sides of the body. Ten, as the frst step, each motor should simulate and controlled ( Figure 4). Figure 4 shows the electrical equivalent circuit of DC motor, i a shows the current of the armature, R mot and L mot , electric inductance and resistance of armature, E a voltage of armature terminal, E b the value of back emf, ω m the speed of the motor (rad/sec), T the torque of motor, J m the friction of   Computational Intelligence and Neuroscience rotational viscous inertia. For the motor part, the back emf (E b ) and torque (T) parameters can be obtained from equation (1) [35].
Equation (1) shows the dependence of engine torque (T) on the motor torque constant (K t ) as the constant parameter and the armature current(i). and the relation of E b (back emf, electromagnetic force) to the electromotive force constant (K e ) and rotational velocity(ω). Considering the SI units since the motor torque is equal to the back emf and a constant value(K t � K e � K). Ten equation (2), with respect to Newton's law and Kirchhof's law assuming equation (1), is represented as follows: Equation (2) shows the mechanical and electrical equation of the motor. In equation (2), J is the moment of inertia of the rotor, b motor viscous friction constant, K signifes both the motor torque constant and the back emf constant. Te input voltage (V in ) and the back emf (Eb), R mot, and L mot represent electric resistance and inductance, respectively, as indicated in Figure 4. In order to calculate the ω as the motor angular velocity from the mechanical equation part, considering the _ Ɵ � ω / and € Ɵ � _ ω equation (2) can be rewritten as follows: Also, equation (4) can be used as an electrical part to calculate the armature current (i a ).
Te mentioned equations (3) and (4) can be directly hired for the motor simulation section in Simulink to calculate the armature current and angular velocity of the motor [35].

Transfer Function of DC Motor Dynamic Model.
Equation (2) is expressed with the terms of S and using Laplace transform as equations (5) and (6) In equation (7), after eliminating I(s), the open-loop transfer function of the permanent magnet DC motor is obtained. In this transfer function, the voltage V in as the input, and rotational speed is considered as the output. Tis part refers to the dynamic model of both sides of the robot motors.
where J stands for rotational inertia, b denotes viscous friction coefcient, L represents the armature inductance, and R stands for armature resistance. Lastly, by considering the DC motor controlled by the armature parameters, a dynamic model can be extracted according to equations (8)- (10). Figure 4: Te dc motor schematic [13].  Computational Intelligence and Neuroscience According to the aforementioned equations and all parameters of the motor summarized in Table 1. Te Simulink block diagram for this section can be derived as shown in Figure 5(a). It should be noted that in addition to the mentioned parameters, the values for other parameters like voltage of armature terminal (E a ), the value of back emf (E b ), speed of the motor (rad/sec) (ω m ), and motor torque (T) should be calculated by a motor with respect to the suggested model. Table 1 shows the actual values of the dc motor parameters (four-inch brushless electric wheel hub motor, 24 V DC, 280 rpm) based on the values obtained from the manufacturer's laboratory [36]. As illustrated in Figure 2, two numbers of this motor are assembled on the design AGV system.

Te AGV Kinematic
Model. Te next section for the physical system includes a kinematic model for the robot. In this section, the angular velocity of the left and right wheels (ω L , ω R ) in terms of radians per second (rad/s) is considered as the input and the V lin linear velocity in terms of meters per second (m/s) and ω the angular velocity of the robot in terms of radians per second (rad/s) assumed as the output. Based on the dual wheel model [3], as shown in Figure 5(b), R and L represent the radius of the robot wheels and the distance between the two wheels, which are connected on both sides of the robot frame. In the mentioned model, forward and reverse kinematics are inspected. Te Forward kinematics (equation (11)) means the x and y coordinates along with orientation angles, which can be calculated from the length and angles of the robot and Inverse kinematics (equation (12)) means calculating the angles required to obtain the position of x, y, and the desired orientation. In kinematics, the angular velocity of left (ω L ) and right (ω R ) of robot wheels consider as input, and the plane coordinates (x, y) along with the heading direction of the robot θ as output. Te equation for the forward and inverse kinematics can be shown as follows: In equations (11) and (12), the (V lin ) stands for the robot's linear velocity, r stands for the wheel radius, L stands for the distance between the two sides of wheels, (ω) the angular velocity, ω L and ω R stands for the angular velocity of the right and left wheel, respectively. Based on the real value of the designed AGV prototype, it should be noticed that r is 0.054 meters, and L is 0.62 meters. To show the mentioned equation in the simulation program, the position and direction of the robot are required. Terefore, the velocities of both sides of the wheels (ω L , ω R ) are fed into the inverse kinematics model to calculate the coordinate of the robot (x and y) and the direction angle (θ). Furthermore, the robot's coordinate can be derived from these equations by integral and trigonometric functions, as shown in the following equation: Finally, concerning equation (13), the Simulink model is presented in Figure 6.
Te parameters and formulas for the proposed models, as shown in Figures 3 and 4, are summarized in Table 2 and labelled from equations (14) to (22).

Sensor Section.
Te sensor part is the second basic AGV block. Tis part carried out the functionality of detecting the reference line. In the real platform, an array of magnetic sensors are installed in front of the vehicle with a working principle similar to the IR sensor, as described in our previous paper [33]. For this sensor, magnetic tape is used as the line. Ten, when a sensor is in front of a magnetic tape, it shows the maximum values and will be detected by the robot's magnetic tape.
Conversely, the tape hardly refects when the sensor is away from the magnet tape, so the sensor would not be triggered. In the simulation program, the 16 sensors are simulated by calculating the position of every magnetic sensor and comparing it with the position of the reference path. Te current robot position (x_pos, y_pos) and the robot position of the last simulation frame (x_last_pos, y_last_pos) are fed into the Matlab function block, and the states of every magnetic sensor are outputs of the Matlab function block (Figure 7).

Decision-Making Component
Tis section consists of the error calculation and the PID controller, as shown in Figure 8. Te motor's direction decides based on sensor reading and PID parameters in this part. Te error calculation part has the duty to read the values of 16 sensors, and then according to the sensor values, the relevant error is extracted and entered into the PID section. As the Classical controller, the PID controller works based on the error feedback with the general equation (14) [16].
Equation (14) shows that the controller works based on three gain parameters of K p (proportional), K i (integral), K d (de rivation)in de xs [10]. Ten, the proportional, integral, and derivative indexes are used to generate the corresponding PWM. Te generated PWM commands and determined the robot speed.
In other words, the amount of error by the magnetic sensor array modes in the PID controller leads to increased and decreased speed of the robot motors. For example, based on sensor reading in a straight or winding path, the robot's speed increases or decreases to adjust the steering angle for tracking the path, as shown in Code 1.
As described in the main controller section, Te PID controller is equipped to adjust the diference of the speed of both sides of the robot; thus, the robot will be able to move along the path. Its input value (Figure 8) is the error between the robot's current direction and the path's target direction, which is calculated based on the Magnetic sensor values. As shown in Code 1, the robot follows the path after extracting error values based on the sensor reading. Ten, the error values were assigned as − 14 to − 1, 0, and +1 to +14 for left, middle, and right sensors, respectively. Ten, the PID value     Computational Intelligence and Neuroscience is calculated to specify the robot's speed. When none of the sensors are triggered, which means that sensors are not facing the reference path, the PID controller is bypassed, and the output value of both sides of the wheels is set as a constant so that the robot will keep moving forward. Each sensor has a coefcient number that depends on the position of the sensor. Te left sensors have negative coefcients, while the right sensors have positive coefcients. Te error value is the summation of the coefcients of all the triggered sensors. Finally, the motor's voltage at the left wheel is set as a constant added by the PID output value, while the voltage of the right side is set as a constant subtracted by the PID output value.

PID Controller Tuning.
As mentioned before, the PID controller is used to avoid oscillation and help the robot pass the path smoothly [37]. It also increases the system's stability. Te PID is known as the standard traditional controlling method, and MATLAB Simulink has provided a specifc tool to help design and tuning PID controller processes for wide applications. Te previous research paper shows the PID controller's efect and the Ziegler-Nichols method [38] for tuning missions.
As it mentioned before [33], to extract the PID loop parameters, the 1 st Ziegler-Nichols method (Z-N) [39] can be applied on     Table 3 shows the step response before and after adjusting the PID parameters.

PID Controller Testing and Empirical PID (E_PID) Tune.
As stated, the PID value directly afects the path tracking and performance of the AGV robot; then, to check the PID tuning, the calculated value is inserted in the model, and the AGV model performance is investigated. In order to validate the parameter, in this step, all mentioned blocks are connected as a closed-loop along with the real value of motor, vehicle size, and PID controller parameters which executes once every step (0.01 seconds in our confguration). Ten, the AGV performance was tested in the various paths. Te parameter validation has been carried out based on the compatibility of the linetracking function under various conditions, and four experimental paths with diferent shapes are designed. Tis validation examines the amount of line tracking in four diferent directions [35], as shown in Table 4.
To start the experiment, for each path, the robot is placed in the setpoint, and the head direction is positioned parallel to the path, the PID indexes of K p � 3.263175, K i � 43.677826, K d � 0.060948 inserted inside the model. Tis process was repeated for each path at the same time, and the extracted result about position and speed were logged and plotted. Te robot's movement against all paths is shown in Figure 9.
As the result shows, the Z-N parameter against the previous efort [33] on the real platform data was unsuccessful. Ten, the test based on the empirical method started to fnd the value that can follow the path for the robot. At frst, K i and K d were set as 0, and many tests were carried out to fnd the proper K p value. Based on previous experiments, the spiral path is one of the paths the robot always has the problem following. Ten, the spiral path is selected to check, and robot performance is observed base on the Spiral path with a length of 6.4509 meters. Te test result shows that in the case of selecting the very small value for the K p, the steering angle is too small to track the path, and if the K p is too big, the output value of the PID controller will diverge. Figure 10 shows each PID value and robot performance.
As it shown initially, K p is set as an intermediate value of 0.025, based on the result with K p � 0.005 Figure 10(a), K p � 0.025 Figure 10(b), and K p � 0.05 Figure 10(c). In the next step, the K i value was selected as 0.01, and the output value of the PID controller diverged Figure 10(d). Ten, a smaller value of 0.001 was attempted, and the path was tracked successfully. Finally, K d was set to 0.01 to reduce the oscillation, and the spiral path was tracked in Figure 10(e). After extracting the fnal PID value, the length of the path increased to 12.9413 meters to ensure the robot's performance Figure 10(f ). Te setting process of the PID values tuning attempts has been arranged based on Table 5.
As Figure 10 and Table 5 shown, based on spiral path tracking, the PID controller with the value in set 5 (K p � 0.025, K i � 0.001, K d � 0.01) successfully follows the spiral line path. Ten, to check the empirical PID value performance, the values test on all other four paths, and the tracking results are shown in Figure 11.
R m ])/nume DO: PID_ bypass � 1; (6) end If (7) Error _Inte � error_ Inte + error; Error _Dif � error-last Error;   Figure 11 shows that in all four predefned paths, the robot successfully follows the path with efcient performance, and the output values follow the target values with smooth curves. Figure 12 and Table 6 show the trajectory tracking analysis.
As it observed, among all these 4 scenarios, the tangential velocity has shown similar curves. It boosted slightly higher than the target value initially, then it approached the target value and remained stable until the end. In terms of the          Te angular velocity of the left wheels was around 4.4201 rad/s, while the target value was up to 2.6943 rad/s since the PID controller can reduce the oscillation. On the spiral path, while the robot was moving, the path became more and more straight, the angular velocity also became increasingly stable. Te target velocity of both sides of the wheels has reached 3.412 rad/s and 2.4524 rad/s, respectively, during the spiral path scenario test. However, the maximum angular velocity of the two sides of the wheels were only 5.127 rad/s and 5.0059 rad/s, respectively, as the maximum value for this parameter. On the 8-shaped path, the peak of the angular velocity of the robot appeared when the robot passed through the sharp corners of the path. Even the Empirical PID values show the promise performance, but to ensure better parameters, the optimization part conducted is described in the next section.

Optimization
As the next step to explore the optimum values for the PID controller parameters, two metaheuristic algorithms, as shown in Figure 13, named Particle Swarm Optimization (PSO) [40] algorithm and Beetle Antennae Searching (BAS) [41], are applied. Metaheuristic algorithms have some advantages over classical methods. Tese algorithms are very popular because of their powerful performance in optimization problems [35]. PSO algorithm is a simple algorithm, and the number of setting parameters in this algorithm are very small. Also, this algorithm has a good performance in continuous problem spaces. Tis algorithm has an easy implementation, robustness to control parameters, and computational efciency, and it is used widely by many researchers in such problems [40]. Te main reason for using the BAS algorithm is being very fast and reaching the optimum point quickly. Although its accuracy is not the same as PSO, using the BAS algorithm can be useful in applications with time as a high priority [41]. Both algorithms are set to three dimensions (3-D space), and the cost function for both methods is defned as follows: Here, the x tracked and x reference represent the tracked and the main(reference) path in the x direction and y tracked , y reference are the tracked and the main path in the y direction, respectively. In both methods, based on the cost function, the error is defned as the diference between the desired path and the tracked path by AGV during the simulation. Te Cost function of this problem is Mean Square Error (MSE), and the optimization algorithms are used to fnd the optimum coefcients of the controller to minimize the error. Tis is a 3-D optimization problem, and the decision vector is presented in the following equation: Here, x 1 , x 2 and x 3 are K p , K i and K d one-to-one and all coefcients are positive. Te PSO and BAS algorithms are described briefy in the following section.

Particle Swarm Optimization (PSO).
Te PSO algorithm was frst introduced as the metaheuristic algorithm to optimize the various problem iteratively by Kennedy and Eberhard in 1995 [41] and then improved by Shi and Eberhar [42]. It is inspired by the birds behavior. In this algorithm, the founded solutions are improved regarding the cost function. PSO is known as a population-based algorithm inspired by nature and categorized as an implicit method. In PSO, a set of candidate solutions are generated inside the problem space, and then the cost function for all particles is evaluated. Ten, the particles move by a vector. Tis vector includes three vectors (Figure 13(a)). Te PSO algorithm is shown in the following pseudocode (Code 2).
As Code 2 shows, after initialization, the frst part is the inertia vector, and it is alongside the current velocity vector. Te second vector is the diference between the current

Input: Initialize the population For t � maximum generation
For i � 1: number of populations else if x i,d (t + 1) < x min then x i,d (t + 1) � x min end end end end Output: P best, g best CODE 2: Particle swarm optimization (PSO) algorithm.
Input: Assume the f(x t ) as the objective function: variablex t consi de r as: (a) Calculate the normalized value for vector b: b → � rn d(k, 1)/‖rn d(k, 1)‖: k represents the spatial dimension (b) space coordinates and Search in variable space for the right (x rt ) and left x lt antenna: 14 Computational Intelligence and Neuroscience position and the best-founded solution by that particle, and the third vector is the diference between the current position and the best-founded solution by all particles. Ten, the positions of all particles are updated, and this process is repeated iteratively until the stopping criterion is met. In (17), the Mathematical formulation of the PSO algorithm is presented.
In (17), W is the inertia weight, v i and x i are the velocity and current position of the i th particle, P best is the personal best of the i th particle, r 1 , r 2 as the random numbers between zero and one and c 1 , c 2 are acceleration coefcients.

Beetle Antennae Searching (BAS). Te Beetle Antennae
Searching (BAS) is proposed and inspired by the searching behaviour of longhorn beetles (Figure 13(b)). Tis algorithm imitates the function of antennae and the random walking mechanism of beetles in nature by the two main steps of detecting and searching [41]. According to the biological study, when the beetle seeks food, it does not know the food location but adjusts the foraging route according to the intensity of the food's smell. Te beetle has two long antennae, and its movement is arranged based on the stronger smell on each antenna side. Te subsequent Code 3 shows the complete BAS algorithm.
As it is shown in the BAS, based on assigned search space, the left and right antennae positions (x r and x l ) specifed the next position of the beetle, and the position of the beetle is frequently updated to gradually reach the optimal target. Firstly, the value for the position of the beetle and the direction of the beetle antenna is initialized, and then the beetle movement direction, according to the initial value of the left and right antenna, is calculated. After that, the beetle's position and direction are updated, and the value of the left and right antenna in the current position to move the beetle in the next stage is calculated. Ten, the position obtained in each iteration for three variables of K p , K i , and K d . Afterwards, the ftness value is calculated based on the error generated by the system after substituting that into the ftness function. Te size between the ftness value and the set minimum threshold is compared. In the next step, it stops if the ftness value is greater than the threshold or the algorithm reaches the maximum number of iterations. Otherwise, it jumps back to the previous step until the stopping criterion is met, and fnally, the optimum solution is shown.

PSO and BAS Implementation and Stopping Criteria.
Generally, in the meta-Heuristic algorithms, all parameters are not exactly defned, and some settings of these algorithms are depended on the problem space and its specifcations. To adjust the parameters, the algorithm has run with initial settings and based on the history of the cost function and its efciency, the settings of the algorithm for the problem are modifed. Te settings of the PSO and BAS algorithms are presented in Table 7. Table 7 shows the PSO algorithm based on the coeffcient selection process in [42]. As it can be seen, the numerical value for both parameters, the number of repetitions and the size of the population, is 10. Te main reason for selecting these values is that the higher population and iteration numbers only increased the calculation time without a signifcant improvement in the results. Te values of c 1 , c 2 are 2 and r 1 , r 2 are random numbers between zero and one. Also, diferent values for the parameters of the BAS algorithm are applied, and the best results based to the minimum cost function are presented. Te lower number of iterations did not lead to the minimum cost function value. Details in [41] present the process of tuning the BAS coefcients. It should be noted that in both algorithms, the number of iterative loops is considered to be 10, and the graphs are drawn result from 10 repetitions of the algorithms. Besides, generally in optimization problems, diferent methods are used for stopping the Optimization process. Some of the most commons are listed as follows: (i) Te number of iterations or the Number of Function evaluations (NFE) reaches a specifc number (ii) Te optimization time is over (iii) Te diference between the founded solutions in each iteration and the previous level is smaller than a specifc value (iv) Te algorithm cannot fnd better solutions for several iterations To fnd the optimum solutions, both algorithms call the cost function. Te Number of Function Evaluation (NFE) indicates the number of using the cost function to obtain its value based on the input values. Figure 14 presents the history of cost function vs the number of function evaluations (NFE) for both PSO and BAS algorithms.
Considering Figure 14, it can be seen that in both fgures, the value of the cost function are decreasing. In PSO, after 10 iterations, the value of the cost function is 2.918, and the value of the cost function for the BAS algorithm is 4.619.By performing the Optimization, the best-obtained coefcients for K p , K i and K d for PSO, K p � 0.02238268877, K i � 0.0006907332736, K d � 0.009376291668 and for BAS, K p � 0.03, K i � 0.0001, K d � 0.02 respectively explored.

Result
Te model evaluation was conducted in three-step, frstly the optimized PID parameter was tested on the model over the paths; secondly, all PID parameters(empirical, PSO, and BAS) were compared by the error as the diference between the reference line and tracked line with the histogram and correlation factors analyzation, fnally to overcome the space limitation the CoppeliaSim (VREP) simulator along with four previous paths one more path named special path tested and the result compared. Te mentioned steps are described as follows.

PSO and BAS PID Parameter Test.
In order to compare the Optimization PID value and empirical result, the explored values are fed into the simulated model. Te results for each path are summarized in Table 8 and Figure 15.
As Figure 15 depicted, both values of the PID parameter for PSO and BAS algorithms tracked the path successfully. In these algorithms, the same as Empirical PID values the tangential velocity slightly overshoots in all paths and then follows the target velocity. Also, the maximum angular velocity belongs to the 8-shape path, and the least belongs to the circle path trajectory. Te error is defned as the distance between the tracked and the reference paths. Ten, with respect to the maximum error, except for the spiral path, BAS has less error than following the reference path.

PID Parameter and Histograms/Correlation of Errors.
To compare all three method PID values, Figures 16(a)-16(c) depicted the histograms of errors over all the following paths.
It can be seen that all errors are very small and close to zero. In addition, the errors of the circle path are the smallest. Besides, Figure 16 shows that the controller can track the circular path with the best accuracy. However, even as Figure 17 shows, the number of points compared to the reference path in which the robot did not exactly follow the path shown with the P * are less and very near to the paths. Eventually, BAS values show better performance, but all three values are acceptable as the errors for other paths are small. Te Pearson correlation coefcient is an important criterion for judging the goodness of results. Tis coeffcient measures the linear correlation between two data sets, and its value is between − 1 and 1. If the correlation coefcient is 1, then it means that a linear equation can relate these two values. Considering two sets as x, y, the value of 1 for the correlation coefcient means that all data points are on a line, and as x is increasing, then y is increasing and vice versa for − 1. A zero value for the correlation coefcient means that there is no linear relationship between these two sets. Equation (18) presents the mathematical formulation of the Pearson correlation coefcient.
In (18), n is the number of data points and X tracked and X Ref represent the tracked and the reference path of the AGV. To evaluate the errors, the histogram of errors are depicted. It can be seen that most errors are close to zero. In Table 9, the correlation coefcients for all four paths in both x and y directions are presented.
Considering Table 9, it can be seen that for all paths, the correlation coefcients between the reference path and the tracked paths are very close to 1. Based on the statistical results, the obtained coefcients for the PID controller lead to an acceptable accuracy in tracking for the AGV.      model to the mathematical equation and showing the real platform performance and, thirdly, extending the tracking path and adding one more path with the comparison due to the real environment limitation. With the mentioned missions, the described PID algorithm along (Code 1) with the designed AGV as per as real dimension and shape ( Figure 2) implemented in CoppeliaSim (VREP) and the tracking result for fve paths of circle path (7.945 meters), "ellipse shape" path (7.987 meters), spiral path (7.780 meters), "8 shapes with the 22.695 meters length, and "special shape" path (18 meters) observed and recorded result shown in Figure 18 as well as Table 10.
As it dissipated in Table 10 and Figure 18, through simulation experiments, it was found that all the extracted PID values successfully follow the path smoothly, which is in hand with the Matlab modelling section. Te results show that even the robot for each test started from diferent origin locations in space, but the robot's movement speed was around 0.053 m/s. Te robot's performance in the VREP environment shows that the maximum orientation for the body belongs to the robot's frst touch of the path, which may happen by the right-side sensors instead of the center sensors. Te result recorded shows the maximum body average degree belongs to the Special path and the least one   belongs to Spiral.and the 8-shape path with the longest length takes the maximum, and the circle with the 7.945 meters has the minimum time to follow. Te average of both body degrees is very near, and it shows in all the paths the maximum and minimum of degree for body degree is between -90 and 90 except in 8 shape and special path in which minimum body degrees are − 32 and -0.66 in empirical PID values.

Conclusions
Tis paper presents the modelling and simulation of dual-wheeled AVG systems equipped with an array of 16 magnetic sensors accompanying the PID controller in MATLAB software. In this research, frst, the details of the AGV model simulation, including the main parts of the body, engine and driver, processor, and sensors, along with the model construction steps, are described.
As it mentioned in the survey section, most of the parameters in the previously reported paper are unreal or used with the scale. Ten, the exact value of the real AGV designed to adjust the PID controller, along with the exact steps and path tracking analysis by Z-N and experimental PID methods, were investigated to build the real model. After that, two optimization methods named PSO and BAS were used to have the optimum values of PID parameters and check the robot's performance. In each experiment, the robot was put on a designed path and was instructed to move along the path. Even though the main controller selected on the real platform (ARDUINO MEGA 2560) has a data sampling limit below 1 kHz, this point is not taken into account in the system's response time during modelling and checking the response in the simulation section. Some limited tests on the real platform with the obtained PID values showed successful tracking for the platform but to evaluate the simulated model and extracted PID value, the model compared with the AGV performance in CoppeliaSim software (VREP software) over the mentioned path in MATLAB and the special shape path. CoppeliaSim software was selected based on more realistic performance and easy coding experience for various movement algorithms, along with its indecency to the pure mathematical AGV model. In conclusion, according to obtained result in the simulation section, the PID controller by empirical tuning method, PSO and BAS showed a good performance to track the path in Matlab and CoppeliaSim (VREP) simulator. Te same achievement for diferent path tracking missions in MATLAB and CoppeliaSim (VREP) simulator demonstrates the robot model ability and trusted values for the PID controller. Te tested path shows that the tracking error of the PID controller is minimum in the circle and maximum in the spiral path. In most cases, the BAS showed better results than other methods. Te results obtained from the experiments indicate the capability of the model presented in the simulation section and the similarity of the performance with the Vrep simulator that can be useful for researchers in the feld of service robots. In future work, to have a complete model, after applying all the sensors, it is suggested to check the robot model and real performance in the presence of obstacles as well as more metaheuristic optimizer controller parameters in realistic environments.

Data Availability
Te data used to support the fndings of this study are available from the corresponding author upon request.

Conflicts of Interest
Te authors declare that they have no conficts of interest.