## 2 Design and Modeling
### Modeling and the Control Allocation
The \(\mathbf{\tau}\) in Equation (1) is defined by  
\[\mathbf{\tau}=\mathbf{L}_{copl}\times\mathbf{R}_{sl}\mathbf{T}_{l}+\mathbf{L}_{copr}\times\mathbf{R}_{ sr}\mathbf{T}_{r} \tag{4}\]  
where, \(\mathbf{L}_{copl}\) and \(\mathbf{L}_{copr}\) are the vector of the CoP of the left and right wing in the body coordinates, respectively. When the flapping plane driven by the servo is tilted, the coordinates of the Cop also change accordingly. As shown in Figure 3, take for example the flapping wing mechanism on the left side, the coordinates of the Cop can be obtained by:  
\[\mathbf{L}_{copl}=\mathbf{R}_{s}\left[ \begin{array}{c}0\\ l_{y}\\ l_{z}\end{array} \right]+\left[ \begin{array}{c}0\\ 0\\ d\end{array} \right] \tag{5}\]  
Since the two wings on one side beat symmetrically about the \(X^{\mathrm{s}}Z^{\mathrm{s}}\)-plane, the coordinates of the Cop can be assumed to be \(\left[0,l_{y},l_{z}\right]^{\mathrm{T}}\) in flapping-plane coordinates. The actual value of the \(l_{y}\) and \(l_{z}\) can be obtained from the relationship between force and torque in the force and torque test. \(d\) is the distance between the CoM and the point \(O_{s}\). Combining Equation (4), Equation (5), and Equation (3), we can obtain the control allocation as:  
\[\left[ \begin{array}{c}\tau_{x}\\ \tau_{y}\\ \tau_{z}\\ \mathbf{F}_{Tz}\end{array} \right]=\mathbf{C}\mathbf{U} \tag{6}\]where,  
\[\mathbf{C}=\left[ \begin{array}{cccc}l_{y}&0&-l_{y}&0\\ 0&d&0&d\\ 0&-l_{y}&0&l_{y}\\ \cos\phi\cos\theta&-\sin\theta&\cos\phi\cos\theta&-\sin\theta\end{array} \right] \tag{7}\] \[\mathbf{U}=\left[ \begin{array}{c}f_{l}\cos\beta_{l}\\ f_{l}\sin\beta_{l}\\ f_{r}\cos\beta_{r}\\ f_{r}\sin\beta_{r}\end{array} \right]=\left[ \begin{array}{c}U_{1}\\ U_{2}\\ U_{3}\\ U_{4}\end{array} \right]\]  
According to the above Equation, we can get the relationship between the virtual control effort \(U\) and the thrust \(f\), the rotation angle \(\beta\) of the flapping plane, as shown in Equation (10). \[\left[ \begin{array}{c}f_{l}\\ f_{r}\\ \beta_{l}\\ \beta_{r}\end{array} \right]=\left[ \begin{array}{c}\sqrt{U_{1}^{2}+U_{2}^{2 }}\\ \sqrt{U_{3}^{2}+U_{4}^{2}}\\ \arctan\frac{U_{4}}{U_{3}}\end{array} \right] \tag{8}\]  
So far, based on this control allocation, we obtain the map from the desired force and torque to the output of actuators, using Equations (6), (7) and (10). If the actuator model describing the input-output relationship of the actuator is known, we can solve the input of the actuator according to the required force and torque outputted by the controller. However, the actual actuator model contains the lift forces and torque as functions of instantaneous wing motion, which is very complex. Considering that the wings flap quickly and with a periodic nature, we make an assumption that the instantaneous lift forces on the rigid body are approximated by wing stroke average forces. In this scenario, We can obtain the actuator model by measuring the average force and torque under different actuator inputs. A 6-axis force/torque test platform (Nano17 Ti, ATI) is set up as illustrated in Figure 4. The actuator model is divided into the thrust model and the servo model. The thrust model describes the relationship between the input of the motor and the magnitude of the thrust generated by the wings. The servo model describes the relationship between the input of the servo and the rotation angle of the flapping plane. The input of the motor and servo is the Pulse-Width Modulation (PWM) signal with a variable duty cycle. To obtain the thrust model, the position of the servo is fixed in the middle position, with the different control inputs of the motor, and the thrust is measured. For the servo  
Figure 3: Illustration of model parameters and coordinates. model, under the condition of fixed motor input, with the different control input of the servo, we measure the average thrust on three axes, hence the rotation angle of the thrust can be obtained to get the relationship between the servo input and rotation angle of the flapping plane.