## 2 Generation of Motion Trajectory Library
### Motion Trajectory Generation  
To optimize the trajectories for common movement actions of a quadruped robot, the continuous-time optimization problem is often converted into a discrete-time nonlinear optimization problem [25]. For example, for a bipedal standing motion, the overall optimization time is denoted as \(T\), and \(N\) nodes are taken for discretization. The sampling time interval is then given by  
\[\Delta t=\frac{T}{N-1} \tag{3}\]  
In order to generate stable and smooth motion trajectories, the cost function is given by  
\[L_{1}=K_{1}\int_{0}^{T}\left(\sum_{i=1}^{n}\tau_{i}^{2}\right)dt \tag{4}\]  
where \(K_{1}\) is the weight constant, and minimizing this part can result in optimized trajectories that consume less energy. \[L_{2}=K_{2}\int_{0}^{T}\left(\sum_{i=1}^{n}\vec{q}_{i}^{\,2}+\sum_{i=1}^{n} \vec{q}_{i}^{\,2}\right)dt \tag{5}\]  
where \(K_{2}\) is the weight constant, and minimizing this part of the cost function ensures the stability of the trajectory, reducing sudden changes in motion. For the trunk state and control state, denoted as \( \begin{bmatrix}q&\dot{q}\end{bmatrix} \) and \( \begin{bmatrix}\tau&f_{ext}\end{bmatrix} \), respectively, they are subject to the following hardware constraints:  
\[ \begin{bmatrix}q^{\min}&q^{\min}\end{bmatrix}  \tag{6}\] \[ \begin{bmatrix}\tau^{\min}&f_{ext}^{\min}\end{bmatrix} \]  
As shown in Figure 3, we use the following dynamic equations to establish the relationship between the overall state and joint torques:  
\[M(q)\ddot{q}+C(q,\dot{q})+G(q)=B\tau+\int_{s}^{T}f_{ext} \tag{7}\]  
Figure 3: Model of contact point variation during the bipedal standing motion of a quadruped robot. where \(M(q)\in\mathbb{R}^{7\times 7}\) represents the mass matrix; \(B\in\mathbb{R}^{7\times 4}\) represents the selection matrix for joint torques; \(C(q,\dot{q})\in\mathbb{R}^{7\times 1}\) represents the Coriolis and centrifugal forces; \(G(q)\in\mathbb{R}^{7\times 1}\) represents the gravity vector; \(J_{*}^{T}\in\mathbb{R}^{7\times 4}\) represents the contact Jacobian matrix, where * can refer to either just the rear foot or all two feet, used to constrain the two movement phases separately; \(\tau\) is the controlled joint torques; and \(J_{*}^{T}f_{ext}\) represents the torques mapped from external forces \(f_{ext}\in\mathbb{R}^{4\times 1}\) into the joint space, applied at different contact points (all two feet or rear foot). The contact constraints are as follows:  
\[ \begin{split}\dot{J}_{t}\dot{q}+J_{t}\ddot{q}&=0 \quad\quad\text{All two feet}\\ \dot{J}_{r}\dot{q}+J_{r}\ddot{q}&=0\quad\quad\text{ Rear foot}\\ \sqrt{(f_{ext}^{x})^{2}}&\leqslant\mu|f_{ext}^{x}| \end{split}  \tag{8}\]  
where \(J_{t}\) and \(J_{r}\) represent the Jacobian matrices for all two feet contact and rear foot contact, respectively; \(\dot{J}\) denotes the drift matrix; and \(f_{ext}^{x}\) and \(f_{ext}^{z}\) represent the external force components in the X and Z directions, respectively. Contact constraints are used to ensure that the robot remains stable and does not move when in contact with the ground, while also adhering to physical constraints. These constraints account for not only joint velocities but also the effect of joint accelerations on the overall system dynamics, thereby making the optimization results more realistic and stable. Although the dynamic constraints ensure that the system satisfies the dynamic equations at each discrete time step, they do not guarantee that the state transitions between two consecutive time steps are consistent with the dynamics model. This could result in physically discontinuous or infeasible trajectories. The time integration constraints are as follows:  
\[ \begin{split} q[t+1]&=q[t]+\dot{q}[t]\Delta t\\ q[t+1]&=\dot{q}[t]+\ddot{q}[t]\Delta t\end{split}  \tag{9}\]  
For the constraints on the initial and terminal times and states, these are crucial to ensure that the object reaches the desired state within the specified time frame. The initial and terminal state constraints are defined as follows:  
\[