4. Genetic Algorithm

Genetic algorithm is used to optimize the trajectory of a Stanford manipulator. The objective is to minimize the movement distance of the manipulator's end effector by optimizing the sequence and timing of joint movements.

According to the initial posture matrix, the inverse kinematics model established by Denavit-Hartenberg method is used to find the initial state of each joint. In accordance with the given beginning moment, cubic polynomial interpolation is applied to each joint variable and the positive kinematic model is used to calculate the end effector path. Genetic algorithm is then used to optimize the sequential order of each joint and the time difference between different starting time of joints, with an objective function of minimizing the path of end effector.

Unoptimized Path:

Optimized Path:

4.1 Trajectory Planning

To plan the trajectory, cubic polynomial interpolation is applied to each joint variable. This interpolation ensures smooth transitions by maintaining continuity in position, velocity, and acceleration, which reduces mechanical stress and ensures efficient movement. The end effector's path is computed using the positive kinematic model based on the given starting conditions.

4.2 Genetic Algorithm Components

Initialization:

  • Randomly generate the initial population of solutions.
  • Each individual in the population represents a possible set of middle moments tm1 and tm2, encoded as a binary string.

Initialization Function:


Function initialization(pop_size, chromo_size)
Input: 
    int pop_size; 
    int chromo_size; 
    int array[2] pop(pop_size, chromo_size); 
Output: 
    for i = 1 to pop_size 
        for j = 1 to 2 × chromo_size 
            pop(i, j) = round(rand); 
        end for 
    end for 
end Function
          

Fitness Function:

  • Calculate the fitness of each individual.
  • The fitness value is based on the distance L of the end effector's movement, where smaller distances are preferred.
  • Convert binary strings to decimal to determine tm1 and tm2.

Fitness Calculation Function:


function score = fitness(individual, chromo_size, theta_10, theta_1f, theta_20, theta_2f, d_30, d_3f, tf)
    
    bits = individual;
    [t2, t3] = decode(bits, chromo_size, tf);
    score = distance(theta_10, theta_1f, theta_20, theta_2f, d_30, d_3f, t2, t3, tf);
end
          

Selection:

  • Rank individuals based on their fitness.
  • Select individuals for reproduction, favoring those with better fitness.

Crossover:

  • Combine pairs of individuals to produce offspring, sharing characteristics of both parents.
  • Use a crossover rate to determine how many offspring to produce.

Mutation:

  • Introduce random changes to some individuals to maintain genetic diversity.
  • Use a mutation rate to control the frequency of these changes.

Iteration:

  • Repeat the process for a number of generations to evolve better solutions.

The goal is to minimize the movement distance L of the end effector by finding optimal values for t2 and t3

Formulas for Calculating L(t2, t3)

The calculation of the distance L(t2, t3) involves piecewise functions based on the ranges of t:

$$ When \ 0 < t \leq t_2:$$

$$L = \int_{0}^{t_2} (\dot{x}(t))^2 + (\dot{y}(t))^2 + (\dot{z}(t))^2 \, dt$$

$$ When \ t_2 < t \leq t_3:$$

$$L = \int_{t_2}^{t_3} (\dot{x}(t))^2 + (\dot{y}(t))^2 + (\dot{z}(t))^2 \, dt$$

$$ When \ t_3 < t \leq t_f:$$

$$L = \int_{t_3}^{t_f} (\dot{x}(t))^2 + (\dot{y}(t))^2 + (\dot{z}(t))^2 \, dt$$

Where tf is the final time when the end effector reaches the target position. These formulas represent the distance covered by the end effector in each segment of its movement.

View on Github
Made with ❤️ by Group B2!