## 3 Controller Design  
### Sliding Mode Control  
Define error variables such as:  
\[e=q-q_{d}\in R^{3},\dot{e}=\dot{q}-\dot{q}_{d}\in R^{3},\ddot{e}=\ddot{q}-\ddot {q}_{d}\in R^{3} \tag{7}\]  
where \(e\in R^{3}\) is the error between the desired position and a simulated position, \(q_{d},\dot{q}_{d},\ddot{q}_{d}\in R^{3}\) are the vector of the desired position, desired angular velocity, and desired angular acceleration of the joint, respectively, and \(e\) and \(\dot{e}\) are supposed to be bounded. Then the sliding surface \(s(t)\) in the state-space \(R^{3}\) can be derived as:  
\[s=\left(\frac{d}{dt}+\lambda\right)^{n-1}e \tag{8}\]  
Figure 2: The architecture of the last link.  
where \(\lambda=diag\Big{(}\begin{array}{ccc}\lambda_{1}&\lambda_{2}&\lambda_{3}\end{array} \Big{)}\), \(\lambda_{i}\) (\(i=1,2,3\)) is a positive constant.  
In this circumstance, we choose \(n=2\), i.e., \(s=\dot{e}+\lambda e\) is a function of the tracking position error and the velocity error based on the manipulator dynamics.  
The derivative of the sliding surface with respect to time is derived as:  
\[\dot{s}=\ddot{e}+\lambda\dot{e}\ =\ \hat{M}^{-1}(q)\Big{[}\tau-\hat{C}(q,\dot{q}) \dot{q}-\hat{G}(q)-d\Big{]}-\ddot{q}_{d}+\lambda\Big{(}\dot{q}-\dot{q}_{d}\Big{)}. \tag{9}\]  
**Property.**\(\dot{\hat{M}}(q)-2\hat{C}(q,\dot{q})\) is a skew matrix that satisfies with \(x^{T}\Big{[}\hat{M}(q)-2\hat{C}(q,\dot{q})\Big{]}x=0\) for any vector \(x\in R^{n}\). Then, multiplying both sides of the equation above with \(M(\theta)\), we obtain:  
\[\hat{M}\dot{s}=\hat{M}\Big{(}\ddot{e}+\lambda\dot{e}\Big{)}\ =\ \tau-\hat{C}(\dot{q},q)\dot{q}-\hat{G}(q)-\hat{M}(q) \ddot{q}_{d}+\hat{M}(q)\lambda\dot{e}+d. \tag{10}\]  
The Lyapunov function can be defined as:  
\[V=\frac{1}{2}s^{T}\hat{M}s. \tag{11}\]  
Taking the derivative, the Equation (11) with respect to time, we obtain:  
\[\dot{V}=s^{T}\Big{[}\tau-\hat{C}(q,\dot{q})\Big{(}\dot{q}_{d}-\lambda e\Big{)} -\hat{G}(q)-\hat{M}(q)\Big{(}\ddot{q}_{d}-\lambda\dot{e}\Big{)}+d\Big{]}. \tag{12}\]  
Let the equivalent state \(\dot{q}_{s}=\dot{q}-s=\dot{q}_{d}-\lambda e\rightarrow\ \ddot{q}_{s}=\ddot{q}-\dot{s}=\ddot{q}_{d}- \lambda\dot{e}\)[18]; then substituting into Equation (8), we obtain:  
\[\dot{V}=s^{T}\Big{[}\tau-\hat{C}(q,\dot{q})\dot{q}_{s}-\hat{G}(q)-\hat{M}(q) \ddot{q}_{s}+d\Big{]}. \tag{13}\]  
Then the control signal function is designated as:  
\[\tau_{control}=\hat{C}(q,\dot{q})\dot{q}_{s}+\hat{G}(q)+\hat{M}(q)\ddot{q}_{s}- \alpha\text{tanh}(s)-Ks \tag{14}\]  
where \(\alpha=diag\Big{(}\begin{array}{ccc}\alpha_{1}&\alpha_{2}&\alpha_{3}\end{array} \Big{)}\) is a diagonal positive definite matrix, \(\alpha_{i}\) is positive constant, \(\text{tanh}(s)=\Big{(}\begin{array}{ccc}\text{tanh}(s_{1})&\text{tanh}(s_{2 })&\text{tanh}(s_{3})\end{array}\Big{)}^{T}\), and \(K=diag(K_{1}\), \(K_{2}\), \(K_{3})\) is a positive matrix in which \(s^{T}Ks>0\ \forall s\
eq 0\). The term -\(Ks\) is added to force the state to approach the switching manifolds faster and the tracking error will be converged in a finite time.  
The stability of the system can be easily proved if the gains of the switching controller are bigger than the upper bounded uncertainties. Then substituting Equation (14) to (13), one can obtain:  
\[\dot{V}\ =-s^{T}\alpha\text{tanh}(s)-s^{T}Ks+s^{T}d. \tag{15}\]  
Since we supposed that all \(\Delta(.)\) are bounded, i.e.,\(\|d\|_{\infty}\leq d_{bound}\), then to guarantee the stability of the system, the derivative of the Lyapunov function must be negative:  
\[\dot{V}\ \leq-s^{T}\alpha\text{tanh}(s)-s^{T}Ks+s^{T}d_{bound}\leq 0 \tag{16}\] \[\to s^{T}\alpha\text{tanh}(s)+s^{T}Ks\geq s^{T}d_{bound} \tag{17}\]  
where \(d_{bound}=f\Big{(}\dot{x}\Big{)}=f_{1}\dot{x}+f_{2}sign(\dot{x})\) and \(f_{1}\) and \(f_{2}\) are positive constant matrices.