## 3 Environment Set Up
### Robotic Arm Collision Detection Method  
In order to avoid collision during the picking process, the collision detection among the arm, end effector, and branches of the crabapple tree was studied in this paper. According to its shape, a simple and reasonable cylindrical bounding box was selected to envelop it, which can simplify the collision detection process and improve the detection efficiency [16]. Because the leaves and twigs (radius less than 3 mm) of the tree will not affect the picking path and collision picking robotic arm, it can be ignored. The thicker branches of the tree were mainly enveloped by a cylindrical bounding box so that the collision detection problem of picking arm, end effector, and the tree branches could be simplified as the collision detection problem between cylinders, that is, it was converted into the shortest distance between cylinder and cylinder axis. By judging the relationship between the shortest distance between two axes and the sum of the radii of two cylinders, whether the picking robot collides with the branches can be judged. The positional relationship between the two enveloping cylinders is shown in Figure 6. Among them, \(C_{i}\) means that the radius of the envelope cylinder between the joint \(i\) of the robotic arm and the joint \(i+1\) is \(r_{i}\), \(D_{i}\) means that the radius of the envelope cylinder of the branches of the tree is \(r_{j}\), and \(L_{ij}\) means the distance between the axis of the envelope cylinder of the robotic arm and the branches of the tree, by comparing the relationship between \(r_{j}+r_{i}\) and \(L_{ij}\), it is determined whether the robotic arm collides with the tree branch. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Branch** & **Starting Point (m)** & **Endpoint (m)** & **Radius (mm)** \\ \hline
1 & (0.00, 0.540, 0.610) & (0.00, \(-\)0.210, 0.610) & 29.5 \\
2 & (0.00, 0.180, 0.610) & (0.00, \(-\)0.167, 0.490) & 12.0 \\
3 & (\(-\)0.026, 0.107, 0.661) & (\(-\)0.183, \(-\)0.101, 0.818) & 13.5 \\
4 & (0.027, 0.159, 0.625) & (0.230, \(-\)0.037, 0.778) & 15.0 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Parameters of each branch of the crabapple tree. Figure 6: Enveloping cylinder. If the position coordinates of joint \(i\) and joint \(i+1\) of the robotic arm are (\(x_{i}\), \(y_{i}\), \(z_{i}\)) and (\(x_{i+1}\), \(y_{i+1}\), \(z_{i+1}\)), respectively, then the \(C_{i}\)-axis equation of the cylindrical envelope of the connecting rod is as follows:  
\[\frac{x-x_{i}}{x_{i+1}-x_{i}}=\frac{y-y_{i}}{y_{i+1}-y_{i}}=\frac{z-z_{i}}{z_{i +1}-z_{i}}=t\;t\in(0,1) \tag{1}\]  
In the formula: \(t\)--scale factor; \(i\)--a positive integer from 0 to 7. Simplify the above equation to the following:  
\[ \begin{cases}x_{i}(t)=(x_{i+1}-x_{i})t+x_{i}\\ y_{i}(t)=(y_{i+1}-y_{i})t+y_{i}\;t\in(0,1)\\ z_{i}(t)=(z_{i+1}-z_{i})t+z_{i}\end{cases}  \tag{2}\]  
The branch \(D_{j}\) of the sand fruit tree is enveloped by a cylinder, and the position coordinates of the two ends of the branch are (\(x_{j}\), \(y_{j}\), \(z_{j}\)) and (\(x_{j+1}\), \(y_{j+1}\), \(z_{j+1}\)). The linear equation of the axis of the cylinder \(D_{j}\) enclosed by the two ends of the branch is as follows:  
\[\frac{x-x_{j}}{x_{j+1}-x_{j}}=\frac{y-y_{j}}{y_{j+1}-y_{j}}=\frac{z-z_{j}}{z_{ j+1}-z_{j}}=q\;q\in(0,1) \tag{3}\]  
Similarly, the above equation can be simplified as follows:  
\[ \begin{cases}x_{j}(q)=(x_{j+1}-x_{j})t+x_{j}\\ y_{j}(q)=(y_{j+1}-y_{j})t+y_{j}\;q\in(0,1)\\ z_{j}(q)=(z_{j+1}-z_{j})t+z_{j}\end{cases}  \tag{4}\]  
By using the cylindrical bounding box collision detection method, the linkage of the robotic arm, the end effector, and the branches of the fruit tree are enveloped in a cylinder to simplify the collision detection process and improve detection efficiency.