## 3 Inverse Kinematics
### Closed-Form Solution for Multiple-GSJ Section
#### 3.3.1 Locations of the GSJs
Given the desired position and orientation of end-effector and link lengths of the studied \(2n\)-DOF serial manipulator, based on the known locations \(\mathbf{O}_{n-1}\), \(\mathbf{O}_{n}\) and the distances \(l_{o,n-1}\) and \(l_{O_{n-2}}\), this algorithm firstly determines the location of GSJ \(\mathbf{O}_{n-2}\), which is function about \(l_{o,n-1}\) and \(l_{O_{n-2}}\), i.e., \(\mathbf{p}_{n-2}=\mathbf{p}_{n-2}\big{(}l_{o,n-1},l_{O_{n-2}}\big{)}\). Then based on the above computed \(O_{n-2}\), known \(\mathbf{O}_{n-1}\) and the distances \(l_{o,n-2}\) and \(l_{O_{n-3}}\), this algorithm determines the location of GSJ \(\mathbf{O}_{n-3}\), which is function about \(l_{o,n-2}\), \(l_{O_{n-3}}\), \(l_{o,n-1}\) and \(l_{O_{n-2}}\), i.e., \(\mathbf{p}_{n-3}=\mathbf{p}_{n-3}\big{(}l_{o,n-2},l_{O_{n-3}},l_{o,n-1},l_{O_{ n-2}}\big{)}\). This process is repeated with the remaining locations. Finally, based on the above computed \(\mathbf{O}_{2}\), \(\mathbf{O}_{3}\) and the distances \(l_{o,2}\) and \(l_{O_{1}}\), this algorithm determines the location of GSJ \(\mathbf{O}_{1}\), which is function about \(l_{o,2}\) and \(l_{O_{1}}\),..., \(l_{o,n-2}\) and \(l_{O_{n-2}}\), i.e., \(\mathbf{p}_{1}=\mathbf{p}_{1}\big{(}l_{o,2},l_{O_{1}},\cdots,l_{o,n-1},l_{O_{ n-2}}\big{)}\), where \(l_{O_{1}}\) is equal to link length \(l_{1}\). Hence, considering the whole manipulator, the positions of the GSJs \(\mathbf{p}_{1,\cdots,n-2}\) is function about \(l_{v,2}\) and \(l_{O_{1}}\),..., \(l_{v,n-2}\) and \(l_{O_{n-2}}\), i.e., \(\mathbf{p}_{1,\cdots,n-2}=\mathbf{p}_{1,\cdots,n-2}\big{(}l_{v,2},l_{O_{1}}, \cdots,l_{v,n-1},l_{O_{n-2}}\big{)}\). Based on this, the distances \(l_{v,2}\) and \(l_{O_{1}}\),..., \(l_{v,n-1}\) and \(l_{O_{n-2}}\) should also satisfy the following inequality constraints:  
\[ \begin{array}{l}\Delta(L_{i})=(b(L_{i}))^{2}-4a(L_{i})c(L_{i})\geq 0\\ p_{i+2,x}(L_{i})p_{i+1,y}(L_{i})-p_{i+2,y}(L_{i})p_{i+1,x}(L_{i})\
eq 0\end{array} , \tag{10}\]  
where the value of \(i\) includes \(1,\cdots,n-2\), \(L_{i}=\big{(}l_{o,j+1},l_{O_{i}},\cdots,l_{v,n-1},l_{O_{n-2}}\big{)}\) represents the related variables for  
Assume that the structural environment of the narrow space is known. The minimum distance between Link \(i\) (\(i=1,2,3,4\)) and the environmental boundary can be expressed as  
\[d_{i,min}=\min_{u\in[0,1],v}\|\mathbf{A}_{i}(u)-\mathbf{C}_{i,v}\|, \tag{12}\]  
where \(\mathbf{A}_{i}(u)\) represents the point on the straight line \(\overline{\mathbf{O}_{i-1}\mathbf{O}_{i}}\) where Link \(i\) is, and its coordinate value is  
\[\mathbf{p}_{\mathbf{A}_{i}}(u)=\mathbf{p}_{i-1}\big{(}l_{v,i+1},l_{\mathbf{O}_{i}}\big{)}+u \big{(}\mathbf{p}_{i}-\mathbf{p}_{i-1}\big{(}l_{v,i+1},l_{\mathbf{O}_{i}}\big{)}\big{)}. \tag{13}\]  
The symbol \(u\in\Re\) represents the linear parameter, when \(u\in[0,1]\), \(\mathbf{A}_{i}(u)\) only represents the point on the link's axis, and \(\mathbf{C}_{i,v}\) represents the point on the narrow environment boundary that is closest to Link \(i\). In actual calculation, the distances \(l_{v,i+1}\), \(l_{\mathbf{O}_{i}}\) and \(u\) in Equation (13) are given by  
\[ \begin{array}{l}l_{v,i+1}=l_{v,i+1}^{l}+k_{1}\cdot\Delta_{l_{v,i+1}},k_{1}= 0,1,\cdots,N_{l_{v,i+1}}\\ l_{\mathbf{O}_{i}}=l_{\mathbf{O},i}^{l}+k_{2}\cdot\Delta_{l_{\mathbf{O}_{i}}},\qquad\qquad k _{2}=0,1,\cdots,N_{l_{\mathbf{O}_{i}}}\end{array}  \tag{14}\]  
and  
\[u=k_{3}\cdot\Delta_{u},k=0,1,\cdots,N_{u}, \tag{15}\]  
respectively, where \(\Delta_{l_{v,i+1}}\), \(\Delta_{l_{\mathbf{O}_{i}}}\), and \(\Delta_{u}\) denote the value intervals of \(l_{v,i+1}\), \(l_{\mathbf{O}_{i}}\) and \(u\), respectively, and \(N_{l_{v,i+1}}\), \(N_{l_{\mathbf{O}_{i}}}\), and \(N_{u}\) denote the maximum of the indices \(k_{1}\), \(k_{2}\), and \(k_{3}\), respectively. Let \(\delta_{i}\) denote the maximum distance from the point on Link \(i\) to the link's axis. If  
\[d_{i,min}>2\delta_{i}, \tag{16}\]  
it means that Link \(i\) has no collision with the boundary.