## 4 Mathematical Model of the Closed-Loop Trajectory  
In this section, the mathematical model of a closed-loop trajectory composed of a rotated semi-oval and a straight-line segment is presented. This model is designed to control the movement of a hexapod robot, taking into account the phase shift between different groups of legs. The closed-loop trajectory shown in Figure 14 is a mathematical proposal to represent the displacements discussed in [1; 2; 3]. This trajectory consists of two types of segments: \(\{x_{1},z_{1}\}\) and \(\{x_{2},z_{2}\}\). The function \(x_{1}(t)\) represents the \(x\)-coordinate of the straight-line segment, while \(z_{1}(t)\) is its corresponding \(z\)-coordinate, which remains zero. The functions \(x_{2}(t)\) and \(z_{2}(t)\) represent the \(x\) and \(z\) coordinates of the rotated semi-oval, respectively. These segments are defined as follows:  
\[x_{1}(t)=x_{2}(\tau_{2}(t))+(x_{2}(\tau_{3}(t))-x_{2}(\tau_{2}(t)))\frac{t-\tau _{2}(t)}{\tau_{3}(t)-\tau_{2}(t)} \tag{8}\]  
\begin{table}
\begin{tabular}{c c} \hline \hline
**Type** & **Angular Delta** & **Range** \\ \hline DAR in the \(yz\) plane & \(d_{x}\Big{|}\text{cos}^{-1}\Big{(}\frac{\mathbf{E}_{\text{s}}\cdot(\mathbf{E}_ {\text{s}}\odot\sigma_{x})\times\mathbf{E}_{\text{s}}\odot\tau_{x}}{\|\mathbf{ E}_{\text{s}}\odot\tau_{x}\|}\Big{)}\Big{|}\) & \([0,\pi]\) \\ DAR in  
\[z_{1}(t)=0 \tag{9}\] \[x_{2}(t)=\cos(\theta)\,a\cos(\omega t+\phi)+\sin(\theta)\,b\sin(\omega t +\phi)\] (10) \[z_{2}(t)=-\sin(\theta)\,a\cos(\omega t+\phi)+\cos(\theta)\,b\sin( \omega t+\phi) \tag{11}\]  
where \(a\) is the semi-major axis of the semi-oval, \(b\) is the semi-minor axis of the semi-oval, \(\omega\) is the angular frequency, \(\theta\) is the rotation angle of the semi-oval, and \(t\) is the time. The compensation angle \(\phi\) is given by:  
\[\phi=\tan^{-1}\Big{(}\frac{a}{b}\tan(\theta)\Big{)}. \tag{12}\]  
The interception times \(\tau_{1}(t)\), \(\tau_{2}(t)\), and \(\tau_{3}(t)\), which mark the transitions between different segments of the trajectory, are defined as follows:  
\[\tau_{1}(t)=\frac{2k(t)\pi}{\omega} \tag{13}\]  
\[\tau_{2}(t)=\frac{2k(t)\pi}{\omega}+\frac{\pi}{\omega} \tag{14}\]  
\[\tau_{3}(t)=\frac{2(k(t)+1)\pi}{\omega}. \tag{15}\]  
In these expressions, to manage the periodic nature of the trajectory, a cycle function \(k(t)\) is defined as:  
\[k(t)=\bigg{\lfloor}\frac{\omega t}{2\pi}\bigg{\rfloor}. \tag{16}\]  
To control the phase shift between the two groups of legs of the hexapod robot, we define the upper time for group 1 and the lower time for group 2 as:  
\[t_{\hat{g}1}=\frac{3\pi}{2\omega} \tag{17}\]  
\[z_{1}(t)=0 \tag{9}\]0  
Time vector \(t\) is then adjusted to include the phase shift \(\eta\):  
\[z_{1}(t)=0 \tag{9}\]1  
Finally, the trajectory is plotted by combining the semi-oval and the straight-line segments. For each time step \(t\), the position vector \(p(t)\) is calculated as:  
\[p(t)= \begin{cases}\Big{[}x_{2}(t)&0&z_{2}(t)\Big{]}^{T},&\text{if }\tau_{1}(t)\leq t\leq\tau_{2}(t)\\ \Big{[}x_{1}(t)&0&z_{1}(t)\Big{]}^{T},&\text{if }\tau_{2}(t)<t\leq\tau_{3}(t). \end{cases}  \tag{20}\]  
This model provides a comprehensive framework for generating closed-loop trajectories with precise control over the phase shifts between different groups of legs, ensuring smooth and coordinated movement for hexapod robots. Previous studies have explored similar trajectories for hexapod robots to evaluate their locomotion capabilities and control algorithms. For instance, in [1], a biologically inspired locomotion pattern was proposed for a lightweight hexapod robot, emphasizing the use of curved and linear paths to mimic natural insect movements. In another study, ref. [2], a neural network-based approach was used to replicate the kinematics of hexapod locomotion, utilizing both curved and straight trajectories to test the system's adaptability and efficiency. Additionally, ref.