# Switched Control of Motor Assistance and Functional Electrical Stimulation for Bieps Curls +
## Materials and Methods
### Control Development  
The control objective of the biceps curls experiment is to track a desired forearm trajectory, quantified by the position tracking error, \(e_{1}\,:\,\mathbb{R}_{\geq 0}\rightarrow\mathbb{R}\), defined as  
\[e_{1}\left(t\right)\triangleq q_{d}\left(t\right)-q\left(t\right). \tag{8}\]  
To facilitate the subsequent development of the FES and motor controllers, an auxiliary tracking error \(e_{2}\,:\,\mathbb{R}_{\geq 0}\rightarrow\mathbb{R}\) is defined as  
\[e_{2}\left(t\right)\triangleq e_{1}\left(t\right)+\alpha e_{1}\left(t\right), \tag{9}\]  
where \(\alpha\,\in\,\mathbb{R}_{>0}\) is a selectable constant gain. Taking the time derivative of (9), multiplying by \(M\), adding and subtracting \(e_{1}\), and using Equations (6) and (8) yields  
\[M\dot{e}_{2} = \chi-Ve_{2}-B_{\sigma}u_{m}-B_{\sigma}u_{e}-e_{1}, \tag{10}\]  
where the auxiliary term \(\chi\,:\,Q\times\mathbb{R}\times\mathbb{R}_{\geq 0}\,\rightarrow\,\mathbb{R}\) is defined as \(\chi\,\triangleq\,M\left(\dot{q}_{d}+\alpha e_{2}-\alpha^{2}e_{1}\right)+V \left(\dot{q}_{d}+\alpha e_{1}\right)+G+\tau_{p}+\tau_{b}+\tau_{d}+e_{1}.\) From Properties 1-6, \(\chi\) can be bounded as  
\[\left|\chi\right|\leq c_{1}+c_{2}\parallel z\parallel+c_{3}\parallel z \parallel^{2}, \tag{11}\]  
where \(c_{1},\,c_{2},\,c_{3}\in\mathbb{R}_{>0}\) are known constants, \(\parallel\cdot\parallel\) denotes the Euclidean norm, and the error vector \(z\in\mathbb{R}^{2}\) is defined as \(z\triangleq\left[ \begin{array}{cc}e_{1}&e_{2}\end{array} \right]^{T}.\) Based on Equations (10) and (11), and the subsequent stability analysis, the FES control input is designed as  
\[u_{m} \triangleq \text{sat}_{\Gamma}\left[c_{\sigma}^{-1}\left(k_{1}e_{2}+\left(k _{2}+k_{3}\parallel z\parallel+k_{4}\parallel z\parallel^{2}\right)\text{sgn }\left(e_{2}\right)\right)\right], \tag{12}\]  
where \(\left\{k_{i}\right\}_{i=1,\ldots,A}\,\in\,\mathbb{R}_{>0}\), are selectable constant control gains, \(\text{sat}_{\Gamma}\left(\cdot\right)\) is defined as \(\text{sat}_{\Gamma}(\kappa)\triangleq\kappa\,\,\text{for}\,\left|\kappa\right| \leq\Gamma\) and \(\text{sat}_{\Gamma}(\kappa)\triangleq\text{sgn}(\kappa)\Gamma\,\,\text{for} \,\left|\kappa\right|>\Gamma\), where \(\Gamma\,\in\,\mathbb{R}_{>0}\) is a selectable design constant and \(\text{sgn}\left(\cdot\right)\,:\,\mathbb{R}\rightarrow[-1,1]\) is the signum function. If the FES control input \(u_{m}\) is saturated, the motor begins assisting the muscle until \(u_{m}\) decreases to the lower threshold denoted by \(\gamma_{j}\,:\,\mathbb{R}_{\geq 0}\rightarrow\mathbb{R}_{\geq 0}\), which is initialized at \(\gamma_{1}\in\mathbb{R}_{>0}\), such that \(\gamma_{1}\leq\Gamma\). The threshold \(\gamma_{j}\) resets to \(\gamma_{1}\) at the beginning of each biceps curl and updates every time it is reached, according to \(\gamma_{j+1}=\rho\gamma_{j}\), where \(j\in\mathbb{N}\) denotes the \(j^{\text{th}}\) time during the \(n^{\text{th}}\) biceps curl for which \(u_{m}\) saturates at \(\Gamma\) and then decreases to \(\gamma_{j}\). The selected constant \(\rho\in(0,\,1)\) was used to decrease the lower threshold after every time the comfort threshold was reached in a single biceps curl, which was motivated by the observation that, as the muscle fatigues, the FES control input rises quicker to the comfort threshold (i.e., saturation point \(\Gamma\)) after each successive bout of motor assistance. At the beginning of each biceps curl (i.e., when \(\dot{q}_{d}\) changes from negative to positive), the motor is not activated unless \(u_{m}\) reaches \(\Gamma\), and is again deactivated the next time that \(u_{m}\leq\gamma_{j}\) or when a new biceps curl starts. Let \(T_{ext,n},\,T_{flex,n}\in\mathbb{R}_{>0}\) denote the initial times during the \(n^{\text{th}}\) biceps curl for which \(\dot{q}_{d}\leq 0\) and \(\dot{q}_{d}>0\).