# Path Optimization of Two-Posture Manipulator of Apple Packing Robots
## 3 Materials and Methods
### Path Optimization Method for the Manipulator of Apple Packing Robots
#### 3.2.4 Packing Path Optimization Algorithm  
The packing path optimization algorithm is realized using an improved genetic algorithm fused with an optimal parameter selection algorithm. The improved genetic algorithm mainly includes the following steps: definition of chromosome generation rule, fitness function setting, crossover operation, mutation operation, comparison, and substitution operation. An optimal parameter selection algorithm is proposed to improve  
Figure 5: Examples of common apple trays. Figure 6: Automatic apple packing points and sample route. the optimization results of the genetic algorithm. The improved genetic algorithm fused with the optimal parameter selection algorithm is shown in Figure 7a, and the improved genetic algorithm is shown in Figure 7b. The parameter combination includes four parameters, namely, population size, crossover probability, mutation probability, and comparison substitution coefficient. The main steps of the improved genetic algorithm include chromosome coding and population creation, fitness function design, region crossover operation, mutation operation, comparison and substitution operation, and termination condition setting. Chromosome coding and population creation is used to code every path composed of different grasping points, placing points, and manipulator postures to one chromosome. All chromosomes corresponding to all paths formed one population. The fitness function is designed to denote the quality of every population. The region crossover operation (an example is shown in Figure 8) is used to enrich the diversity of offspring. The mutation operation (an example is shown in Figure 9) guarantees the randomness of various posture solutions of the manipulator. The comparison and substitution operation (an example is shown in Figure 10) can select the chromosome with the optimal fitness function value and replace the inferior one with it. The termination condition is set to stop the iteration. (1) Two-level chromosome coding and population creation  
Figure 7: Flowchart of the improved genetic algorithm fused with the optimal parameter selection algorithm: (**a**) flowchart of the improved genetic algorithm fused with the optimal parameter selection algorithm; (**b**) flowchart of the improved genetic algorithm. Before path optimization, grasping points with apples and placing points without apples are labeled in order. Apple grasping points are labeled with negative values from left to right (\(-1\), \(-2\), \(-3\), \(-4\), \(\ldots\), \(-m\)), and apple placing points are labeled with positive values from left to right and from top to bottom (\(1\), \(2\), \(3\), \(\ldots\), \(n\)), as shown in Figure 6. The coordinates of each point within the rotation range are mapped to the coordinates in the visual detection system. Two types of rotational joint angle solutions are found for each point within the rotation range of the manipulator. Therefore, the manipulator has two different postures at each point. The two postures of each point are labeled as two adjacent real integers. When the point number of the end effector is \(-2\), the two postures of this point are labeled as \(-21\) and \(-22\), respectively. Grasping points and postures are relabeled with negative  
Figure 8: Process of the crossover operator. The red circles indicate the positive numbers in the unchanged and changed regions that have the same or adjacent numbers. The red boxes indicate the changed positive numbers in the unchanged regions that have the same or adjacent numbers as the positive numbers of the changed regions. Figure 9: Process of the mutation operator. The purple circles indicate the posture changed by the mutation operator. values from left to right, which are \(-11\), \(-12\), \(-21\), \(-22\), \(-31\), \(-32\), \(-41\), \(-42\), \(\ldots\), \(-m1\), \(-m2\). Similarly, placing points and postures are labeled with positive values, which are \(11\), \(12\), \(21\), \(22\), \(31\), \(32\), \(\ldots\), \(n1\), \(n2\).