## 2 Design and Modeling
### Modeling and the Control Allocation  
To assist the controller design, we establish the dynamics model of the FMAV. Since the inertia of the wings is small relative to the inertia of the body, we assume that the FMAV is a rigid body and ignore the change in the body's moment of inertia when the wings flap. The coordinate \(O^{x}X^{x}Y^{x}Z^{e}\) defined in Figure 3 is the inertial coordinates. In the body coordinates \(O^{b}X^{b}Y^{b}Z^{b}\) fixed at the Center of Mass (CoM) of the FMAV, the rotation direction of the roll, pitch, and yaw angle is assumed to be clockwise about the \(X^{b}\), \(Y^{b}\), and \(Z^{b}\)-axis, respectively. \(O^{s}X^{s}Y^{s}Z^{s}\) is the flapping-plane coordinates fixed at the intersection of the fuselage and the rotation axis ( \(Y^{b}\)-axis of the body coordinates) of the flapping wing mechanism, the \(Y^{s}\)-axis of the flapping-plane coordinates is parallel to the \(Y^{b}\)-axis, and the \(Z^{s}\)-axis is parallel to the trailing edge of the wing. Due to the symmetry of the body, the inertia matrix \(J\) of the FMAV can be assumed to be a diagonal matrix. The main diagonal of the inertia matrix \(J\) can be measured using the Bifilar torsional method [29]. Figure 1: (**a**) Illustration of the lightweight FMAV. (**b**) Explosion diagram of mechanical structure. (**c**–**e**) Schematic diagram of control torque generation. Translucent arrows show the nominal wingbeat-average thrust vectors before torque generating. Solid arrows show wingbeat-average thrust and torque after torque generating. Figure 2: Illustration of the main autopilot board. In this paper, the dynamic model of FMAV is divided into the translational model and the rotational model as follows in Equation (1):  
\[m\dot{p} =F_{T}-mg \tag{1}\] \[\dot{J}\dot{\omega} =\mathbf{\tau}+\mathbf{\tau}_{0}-\mathbf{\omega}\times\mathbf{J}\mathbf{\omega}\]  
where, \(\mathbf{\omega}\) is the angular velocity of the body, \(\mathbf{\tau}\) represents the torque generated by the flapping wings. \(\mathbf{\tau}_{0}\) represents the initial offset torque. \(m\) is the mass of the FMAV, \(\mathbf{p}~{}=~{}[x,y,z]^{\mathrm{T}}\) represents the position of FMAV in the inertial coordinates. \(\mathbf{F}_{T}\) represents the periodic average thrust vector in the inertial coordinates, which acts on the Center of Pressure (Cop) of the wing. \(\mathbf{F}_{T}\) can be obtained by  
\[\mathbf{F}_{T} =R_{b}(R_{sl}\mathbf{T}_{l}+R_{sr}\mathbf{T}_{r}) \tag{2}\] \[=\mathbf{R}_{b}\left(\left[ \begin{array}{ccc}\cos\beta_{l}&0&\sin \beta_{l}\\ 0&1&0\\ -\sin\beta_{l}&0&\cos\beta_{l}\end{array} \right]\left[ \begin{array}{c}0\\ 0\\ f_{l}\end{array} \right]+\left[ \begin{array}{ccc}\cos\beta_{r}&0&\sin\beta_ {r}\\ 0&1&0\\ -\sin\beta_{r}&0&\cos\beta_{r}\end{array} \right]\left[ \begin{array}{c}0\\ 0\\ f_{r}\end{array} \right]\right)\]  
where \(\mathbf{R}_{b}\) is the rotation matrix from the body coordinates to the inertial coordinates, \(\mathbf{R}_{sl}\) and \(\mathbf{R}_{sr}\) are the rotation matrix from the left and right flapping-plane coordinates to the body coordinates, respectively. \(\beta_{l}\) and \(\beta_{r}\) are the rotation angle of the left and right flapping planes, respectively. \(f_{l}\) and \(f_{r}\) are the scalar thrust generated by the left and right flapping wings, respectively. Expanding Equation (2), we can get the vertical component \(F_{Tz}\) of the \(\mathbf{F}_{T}\):  
\[\mathbf{F}_{T}=\left[ \begin{array}{ccc}\cos\phi\cos\theta&-\sin\theta&\cos\phi \cos\theta&-\sin\theta\end{array} \right]\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] \tag{3}\]  
where, \(\phi\) and \(\theta\) are the roll and pitch angle, respectively.