# Reinforcement-Learning-Based Path Planning: A Reward Function Strategy
## 4 Discussion  
This section explores variations in the proposed algorithms within the four maps and the behavior of the trajectory-tracking controller.  
The results demonstrate acceptable performance for both the basic RL and Deep Q-Learning algorithms. Both algorithms reduced the distance compared to the A* algorithm, which only had four probable actions. The A* algorithm achieved the same distance as the basic RL algorithm and the Deep Q-Learning algorithm, with eight possible actions, shown in Maps 1 and 4. The A* algorithm indicated a higher number of turns in all of the evaluated maps. Technique A* depended on knowledge of the environment, which limited its application in dynamic environments.  
The RL algorithm and the Deep Q-Learning algorithm reduced the number of turns in all maps, resulting in a balance between trajectory distance and the number of turns.  
The difference between the RL algorithm and the Deep Q-Learning algorithm lay in the number of turns along the trajectory. The Deep Q-Learning algorithm reduced the number of turns in Maps 3 and 4. This allowed the robot to maintain a constant velocity along most of its trajectory.  
The behavior of the RL algorithm and the Deep Q-Learning algorithm allowed us to verify that the proposed reward function motivated the agent to take shorter paths with fewer turns in comparison to the A* technique. The reward function employed in the basic RL algorithm and the Deep Q-Learning algorithm accomplished the objective of incentivizing an agent to take diagonal paths with the minimum number of turns. This approach allowed the robot to save energy by maintaining a constant velocity for an extended period of time.  
The RL and Deep Q-Learning algorithms found an optimal path without prior knowledge of the locations of the obstacles and their dynamics without updating the probability  
Figure 20: The controller’s response for the trajectory of the Deep Q-Learning algorithm for Map 4. (**a**) The linear velocity of the robot in the trajectory of Map 4; (**b**) the angular velocity of the robot in the trajectory of Map 4; (**c**) the error \(x\) of the robot in the trajectory of Map 4; and (**d**) the error \(y\) of the robot in the trajectory of Map 4.  
of displacement. The proposed dynamic environments did not represent a problem for any of the algorithms in determining the optimal path since the dynamic obstacles had minimal motion in the environment.  
The reward function employed in the basic RL algorithm and the Deep Q-Learning algorithm accomplished the objective of incentivizing the agent to take diagonal trajectories with the minimum number of turns. This approach allowed the robot to save energy by maintaining a constant velocity for as long as possible.  
The proposed method was evaluated using two RL-based algorithms. The result was the same performance as the ID3 QN and DQN algorithms in the length of the trajectory. Regarding the number of turns, the ID3 QN algorithm showed a higher performance compared to the DQN algorithm and the proposed method. Additionally, the proposed algorithm showed a reduction in the number of neurons from 256 to 64 and a reduction in the number of hidden layers from three to two compared to the ID3 QN method. This represents a reduction in computational resources.  
Trajectory control based on the Lyapunov candidate was proposed, which corresponds to a mean square error that meets the two stability conditions.  
The error between the desired trajectory and the estimated trajectory was less than 1.2 cm in axis \(x\) and \(y\).