## 4 Simulations
Operator \(\text{Mutation1}(\mathbb{S})\), applied with probability \(P_{\text{M1}}=0.1\), removes up to three random elements from \(\mathbb{S}\). Operator \(\text{Mutation2}(\mathbb{S})\), applied with probability \(P_{\text{M2}}=0.1\), removes a random element from \(S\) and replaces it with the element in \(\mathbb{B}\) which maximizes \(F(\mathbb{S})\). Finally, operator \(\text{Crossover}(\mathbb{S}_{1},\mathbb{S}_{2})\), with probability \(P_{C}=0.7\), generates a new individual \(S^{\prime}\) by extracting random elements from \(\mathbb{S}_{1}\cup\mathbb{S}_{2}\) as long as they increase the objective function \(F(\mathbb{S})\). Furthermore, we define a \(\text{Fill}(\mathbb{S},\mathbb{B})\) operator, which generates a superset of \(\mathbb{S}\) by repeatedly adding random candidate boxes from \(\mathbb{B}\) until \(F(\mathbb{S})\) stops increasing. By applying the Fill operator at the initialization and after each operator, we ensure that each individual is always a greedy local maximum. Optimization ends when the objective function does not decrease for \(G_{\text{stall}}=20\) consecutive frames. The genetic optimization algorithm was implemented in C++ using the OpenGA library ([[https://github.com/Arash-codedev/openGA](https://github.com/Arash-codedev/openGA)]([https://github.com/Arash-codedev/openGA](https://github.com/Arash-codedev/openGA)), accessed on 24 June 2021). The output of the box detection can be appreciated in Figure 5(b). Further details on the genetic optimization approach can be found in [30]. ### Refined Estimation of the Gap between Two Boxes

In the _refined estimation of the gap_ phase, the camera on the arm is moved to the estimated position of the gap between two boxes, at a fixed height above the boxes themselves. The camera is oriented so that the image plane is roughly parallel to the top pallet layer. Moreover, the image \(x\) axis is oriented as the expected direction of the box edge. The camera exposure \(t_{\text{exp}}\) is adjusted to a low value \(t_{\text{exp,near}}\) to prevent the saturation of the camera sensor. The 3D camera view at this stage can be seen in Figure 5(c). The gap refinement algorithm consists of three steps. First, 2D lines are detected through the probabilistic Hough Transform on the corrected intensity image \(R^{\prime}\). Then, 2D lines are discarded if their angle with respect to the image x axis is too large or if they are too far from the image center, as shown in Figure 5(d). Through a proper choice of thresholds, only the horizontal lines in the center of the image remain and most outliers are discarded. Finally, the gap position \(p_{\text{ref}}\) and orientation \(\theta_{\text{ref}}\) are computed as the mean position and orientation of the detected lines, and used to determine the target frame for the manipulation operation. ### Controller Design

During the extraction procedure, an admittance control strategy is implemented for the control of the arm position \(x_{\text{ref}}\):

\[x_{\text{ref}}=x_{\text{des}}+\Lambda\Delta x_{\text{des}} \tag{4}\]

along the tool insertion direction defined by the selection matrix \(\Lambda\):

\[\Lambda=[0\;0\;1\;0\;0\;0]^{T} \tag{5}\]

The admittance behavior is based on the tool wrench measure provided by the cobot and it produces a smooth behavior during tool insertion. In particular, a displacement for the control reference is defined at each time instant according to the measured wrench, in order to produce an elastic interaction in the case of collisions and prevent any damage to the boxes. The induced displacement \(\Delta x_{\text{des}}\) is obtained by means of a first-order digital filter to reduce the wrench estimation noise:

\[\Delta x_{\text{des}}=\frac{K_{F}}{1+K_{p}\,z^{-1}}\,\text{d}z(\Lambda^{T}F_{ \text{ext}},F_{\text{th}}) \tag{6}\]

where \(z^{-1}\) represents the sample-time delay according to the \(Z\)-transform notation and \(K_{p}\) is the filter gain.