# Design and Trajectory Tracking Control of a Magnetorheological Prosthetic Knee Joint
## 4 Trajectory Tracking Control Based on Second-Order Sliding Mode  
Due to uncertainties and external interference, traditional PD control cannot track the knee joint swing trajectory well in the MR prosthesis control model. In addition, the first-order sliding mode control is to make the control system switch on the sliding mode surface, which easily causes the chattering phenomenon in the control system. Therefore, a second-order sliding mode control (SOSMC) algorithm is developed to control the swing trajectory of the actual MR prosthesis. The sliding mode surface of sliding mode control is constituted of the error and derivative of the current state quantity and the ideal state quantity of the system, and the phase plane is defined to make the state variables converge on the ideal state. The SOSMC algorithm can effectively eliminate the chattering phenomenon of the system by designing its sliding mode surface and switching rate. The principles of SOSMC are shown in Figure 15, which mainly includes equivalent continuous term and equivalent discrete term. The proposed SOSMC can be expressed as:  
\[\tau_{2}=\tau_{eq}+\tau_{dis} \tag{16}\]  
where \(\tau_{eq}\) is the equivalent continuous term, and \(\tau_{dis}\) is the equivalent discrete term. Figure 14: Error curve between sample value and fitted value. Figure 15: SOSMC principle diagram. The equivalent continuous term can be expressed as:  
\[\tau_{eq}=M_{21}\ddot{\theta}_{1}+M_{22}(\varepsilon\text{sgn}(S)+\lambda\dot{e} +\ddot{\theta}_{24})+C_{2}+G_{2} \tag{17}\]  
where \(S\) is the sliding mode surface function; \(\lambda\) is the parameter to be designed and \(\ddot{\theta}_{24}\) is the second derivative of the reference gait. The sliding mode surface function \(S\) is defined as:  
\[S=\lambda e+\dot{e} \tag{18}\]  
The equivalent discrete term is established by using super-twisting, which can be expressed as:  
\[\tau_{dis}=\mu_{1}\int_{0}^{t}\text{sign}(S)dt+\mu_{2}|S|^{0.5}\text{sign}(S) \tag{19}\]  
In the Equation (19), the positive real numbers \(\mu_{1}\) and \(\mu_{2}\) need to satisfy:  
\[\mu_{2}>\frac{\phi_{0}}{K_{m}}\geq 0 \tag{20}\]  
\[\mu_{1}^{2}\geq 4\frac{\phi_{0}}{K_{m}^{2}}\frac{\mu_{2}K_{M}+\phi_{0}}{\mu_{2}m _{M}+\phi_{0}}>0 \tag{21}\]  
where \(\phi_{0},\ K_{m},\text{ and }K_{M}\) are positive real numbers. The Lyapunov function \(V\) is defined as:  
\[V=|S|=S\text{sign}(S) \tag{22}\]  
Taking the derivative of \(V\), it can be obtained as:  
\[\dot{V}=\dot{S}\text{sign}(S) \tag{23}\]  
Substituting Equation (18) into Equation (23), the derivative of \(V\) is:  
Figure 14:0  
In the formula, the second derivative of the calf swing angle \(\ddot{\theta}_{2}\) can be expressed as:  
Figure 14:1  
Substituting Equation (25) into Equation (24), the following can be obtained:  
Figure 14:2  
Substituting Equations (16), (17) and (19) into Equation (26), we have:  
Figure 14:3  
Since \(\mu_{1}\) and \(\mu_{2}\) are positive real numbers, and \(t\geq 0\), it can be deduced that:  
Figure 14:4  
Because \(V\geq 0\) and \(\dot{V}\leq 0\), So the MR prosthesis system is gradually stable. Figure 16 shows the principle of the MR prosthesis based on SOSMC, which mainly includes SOSMC, the inverse model and the positive model of MR damper and the dynamic model of the MR prosthesis. The sliding mode control in SOSMC is established based on the sliding mode function and the dynamic model of the prosthesis, while the super-twisting algorithm is established based on the sliding mode function. The sliding mode function is established based on the difference between the reference swing angle of the lower leg and the actual swing angle.