# Experimental Evaluation of a Takagi-Sugeno Fuzzy Controller for an EV3 Ballbot System +
## 2 Dynamical Model  
In this work, a four-degree-of-freedom (DOF) underactuated system consisting of a rigid body balancing atop a ball (see Figure 2) and having two control inputs (see Figure 1), here known as EV3 BRS, is considered. When assuming that the whole dynamics of motion can be decomposed into two planes of motion, a TSFC is designed by taking just one of those planes of motion as a reference and then implementing it in a decentralized way on each one. The controller design is carried out under the premise that there is no slipping between wheel and surface and that only viscous friction exists between wheel and body. The control inputs are just considered as torques. The generalized coordinates are given by the angular displacement of the EV3 BRS's body, namely \(q_{1}\), and the angle of the motor shaft, namely \(q_{2}\) (See Figure 2).  
Consider the model for the EV3 BRS [4] given in the second-order matrix form: [31]  
\[M(\mathbf{q})\ddot{\mathbf{q}}+C(\mathbf{q},\dot{\mathbf{q}})\dot{\mathbf{q}}+\mathbf{g}(\mathbf{q})+\mathbf{ f}(\dot{\mathbf{q}})=\mathbf{\tau}_{\text{ext}}, \tag{1}\]  
whose form is frequently used to model the dynamics from robot arms of \(n\) DOF [32; 33; 34], where  
\[M(\mathbf{q})=\begin{bmatrix}m_{11}&m_{12}\\ m_{21}&m_{22}\end{bmatrix}\in\mathbb{R}^{n\times n} \tag{2}\]with \(m_{11}=I_{B}+I_{M}+I_{b}+L^{2}m_{B}+m_{B}R_{b}^{2}+m_{b}R_{b}^{2}+2 Lm_{B}R_{b}\cos(q _{1}),m_{12}=I_{M}+I_{b}\delta+m_{B}\delta R_{b}^{2}+Lm_{B}\delta R_{b}^{2}\cos(q _{1}),m_{21}=m_{12},m_{22}=I_{M}+I_{b}\delta^{2}+m_{B}\delta^{2}R_{b}^{2}+m_{b} \delta^{2}R_{b}^{2}\), and which is referred to as inertia (mass) matrix, symmetric and positive definite for all \(\mathbf{q}\in\mathbb{R}^{n}\),  
\[C(\mathbf{q},\dot{\mathbf{q}})=\begin{bmatrix}c_{11}&c_{12}\\ c_{21}&c_{22}\end{bmatrix}=\begin{bmatrix}-Lm_{B}R_{b}\sin(q_{1})\dot{q}_{1}& 0\\ -Lm_{B}\delta R_{b}\sin(q_{1})\dot{q}_{1}&0\end{bmatrix}\in\mathbb{R}^{n\times n} \tag{3}\]  
is the centrifugal and Coriolis forces (damping) matrix,  
\[\mathbf{g}(\mathbf{q})=\begin{bmatrix}g_{11}\\ g_{21}\end{bmatrix}=\begin{bmatrix}-\mathrm{g}Lm_{B}\sin(q_{1})\\ 0\end{bmatrix}\in\mathbb{R}^{n} \tag{4}\]  
is the gravitational forces or torques vector,  
\[\mathbf{f}(\dot{\mathbf{q}})=\begin{bmatrix}f_{11}\\ f_{21}\end{bmatrix}=\begin{bmatrix}f_{B_{b}}\dot{q}_{1}\\ f_{B_{b}}\dot{q}_{2}\end{bmatrix}\in\mathbb{R}^{n} \tag{5}\]  
is the viscous friction forces vector, which depends on the joint velocities, and  
\[\mathbf{\tau}_{\text{ext}}=\begin{bmatrix}0&\tau\end{bmatrix}^{\top}=\begin{bmatrix} 0&u\end{bmatrix}^{\top}\in\mathbb{R}^{n} \tag{6}\]  
is the vector of external forces corresponding to the torque exerted by the actuator. By an inverse relationship, the dynamics of motion (1) may also be expressed in terms of the joint accelerations, i.e.,  
\[\ddot{\mathbf{q}}=M(\mathbf{q})^{-1}[\mathbf{\tau}_{\text{ext}}-C(\mathbf{q},\dot{\mathbf{q}})\dot {\mathbf{q}}-\mathbf{g}(\mathbf{q})-\mathbf{f}(\dot{\mathbf{q}})] \tag{7}\]  
with  
\[M(\mathbf{q})^{-1}=\frac{\begin{bmatrix}m_{22}&-m_{12}\\ -m_{21}&m_{11}\end{bmatrix}}{\det(M(\mathbf{q}))}, \tag{8}\]  
where, if the existence of (8) is guaranteed, (7) is then given by  
\[\begin{bmatrix}\ddot{q}_{1}\\ \ddot{q}_{2}\end{bmatrix}=\frac{1}{\det(M(\mathbf{q}))}\begin{bmatrix}(m_{12}c_{2 1}-m_{22}c_{11})\dot{q}_{1}-m_{22}g_{11}+m_{12}f_{21}-m_{12}u\\ (m_{21}c_{11}-m_{11}c_{21})\dot{q}_{1}+m_{21}g_{11}-m_{11}f_{21}+m_{11}u\end{bmatrix}. \tag{9}\]