Path Planning For A Robot Arm Using Genetic Algorithm

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

PATH PLANNING FOR A ROBOT ARM USING

GENETIC ALGORITHM

What are GAs?

Genetic algorithms(GAs) are adaptive heuristic


search algorithm based on evolutionary ideas of
natural selection and genetics.
Genetic algorithms(GAs) are a part of
evolutionary computing,a rapidly growing area
of artificial intelligence.GAs are inspired by
Darwin's theory about evolution- survival for
the fittest.
In nature,competition among individuals for
scanty resources results in the fittest individuals
dominating over the weaker ones.

Why Genetic Algorithms?

It is better than conventional AI,it is more


robust.
GAs are good at taking large,potentially huge
search spaces and navigating them,looking for
optimal combinations of things.

Optimization

Optimization is a process that finds a best,or


optimal,solution for a problem.The Optimization
problems are centered around three factors:
1.An objective function which is to be
minimized or maximized;
2.A set of unknowns or variables that affect
the objective function,
3.A set of constraints that allow the unknowns
to take on certain values but exclude others;

An optimization problem is thus defined


as:Finding values of the variables that minimize
or maximize the objective function while
satisfying the constraints.

Basic Genetics

All living organisms consists of cells.


In each cell there is same set of
chromosomes.Chromosomes are strings of
DNA and serve as a model for the whole
organism.
A chromosome consists of genes,blocks of
DNA.
Each gene encodes a particular protein that
represents a trait(feature),e.g.,color of eyes.
Possible settings for a trait(e.g.,blue,brown) are
called alleles.

Each gene has its own position in the


chromosome called its locus.
Complete set of genetic material(all
chromosomes) is called a genome.
Particular set of genes in a genome is called
genotype.
When two organisms mate they share their
genes,the resultant offspring may end up
having half the genes from one parent and half
from the other.This process is called
recombination(crossover).

The new created offspring can then be


mutated.Mutation means,that the elements of
DNA are a bit changed.These changes are
mainly caused by errors in copying genes from
parents.
The fitness of an organism is measured by the
success of the organism in its life(survival).

Basic Terminology

Chromosome:a set of genes;a chromosome


contains the solution in form of genes.
Gene:a part of chromosome,a gene contains a
part of solution.It determines the
solution.e.g.,16743 is a chromosome and
1,6,7,4 and 3 are its genes.
Individual:same as chromosome.
Population:number of individuals present with
same length of chromosome.
Fitness:a value assigned to an individual based
on how far or close a individual is from the
solution.

Fitness function:a function that assigns fitness


value to the individual.It is problem specific.
Mutation:changing a random gene in an
individual.
Selection:selecting individuals for creating the
next generation.

Genetic algorithm begins with a set of


solutions(represented by chromosomes) called
the population.
Solutions from one population are taken and
used to form a new population.This is motivated
by the possibility that the new population will be
better than the old one.
Solutions are selected according to their fitness
to form new solutions(offspring);more suitable
they are,more chances they have to reproduce.
This is repeated until some condition (e.g.,
number of populations or improvement of the
best solution) is satisfied.

Outline of Basic Genetic Algorithm


1.Generate random population of n
chromosomes(i.e. suitable solutions for the
problem)
2.Evaluate the fitness f(x) of each chromosome x
in the population.
3.Create a new population by repeating following
steps until the new population is complete.
(a).Select two parent chromosome from the
population according to their fitness(better the
fitness,bigger the chance to be selected).

(b).With a crossover probability,cross over the


parents to form new offspring(children).If no
crossover was performed,offspring is the exact
copy of parents.
(c).With a mutation probability,mutate new
offspring at each locus(position in
chromosome).
(d).Place new offspring in the new population.
4.Use new generated population for a further
run of the algorithm.
5.If the end condition is satisfied,stop,and return
the best solution in the current population.
6.Go to step 2.

Flow chart for genetic programming

Encoding

One common approach is to encode solutions


as binary strings;sequences of 0's and
1's,where digit at each position represents the
value of some aspect of the solution.
Example:
-a gene represents some data(eye color,hair
color,sight, etc.
-a chromosome is an array of genes.
In binary form,a gene looks like (11100010).
a chromosome looks like:
gene1

gene2

gene3

gene4

(11000010,00001110,001111010,10100011)

Binary Encoding

Binary encoding is the most common to


represent information contained.In genetic
algorithms,it was first used because of its
relative simplicity.
In binary encoding every chromosome is a
string of bits 0 and 1,like
chromosome 1:101100101100101011100101
chromosome 2:111111100000110000011111

Operators of genetic algorithm

Genetic operators used in genetic algorithms


maintain genetic diversity.
Genetic diversity or variation is a necessity for
the process of evolution.
Genetic operators are:
-reproduction(selection)
-crossover(or recombination)
-mutation

In addition to these parameters,there are some


parameters of GA.One important parameter is
Population Size.
Population size specifies how many
chromosomes are in population(in one
generation).
If there are only few chromosomes,then GA
would have a few possibilities to perform
crossover and only a small part of search space
is explored.
If there are many chromosomes,then GA slows
down.

Basic genetic algorithm example

Maximize the function f(x)=x2 over the range of


integers from 0...31.
1.Devise a means to represent a solution to the
problem:
assume,we represent x with a 5 digit unsigned
binary integer.
2.Devise a heuristic for evaluating the fitness of
any particular solution:
the function f(x) is simple,so it is easy to use the
f(x) value itself to rate the fitness of the solution.

3.Coding-binary and the string length:


GAs often process the binary representation of the
solutions.because mutation and crossover can be
clearly defined for binary solutions.A binary string
of length 5 can represent 32 numbers (0 to 31).
4.Randomly generate a set of solutions:
Here consider a population of 4 solutions.Assume
four randomly generated solutions as:
01101,11000,01000,10011.These are
chromosomes or genotypes.
5.Evaluate the fitness of each member of the
population:
The calculated fitness values for each individual
are:

(a)Decode the individual into an integer


01101=>13;11000=>24;01000=>8;10011=>19;
(b)Evaluate fitness according to f(x)=x2.
13=>169;24=>576;8=>64;19=>361;
(c)Expected count=N*Prob I,where N is the
number of individuals in the population called
population size,here N=4.

6.Produce a new generation of solutions by


picking from the existing pool of solutions with a
preference for solutions which are better suited
than others:
we divide the range into 4 bins,sized according
to the relative fitness of the solutions which they
represent.

By generating 4 uniform (0,1) random values


and seeing which bin they fall into we pick the
four strings that will form the basis of the next
generation.

7.Randomly pair the members of the new


generation
random number generator decides which
strings should mate together.Here, lets say first
two strings mate together and the second two
strings together.
8.Within each pair swap parts of the members
solutions to create offspring which are a mixture
of the parents:

For the first pair of strings: 01101,11000


-we randomly select the crossover point to be
after the forth digit.crossing these two strings at
that point yields:
01101 => 0110 | 1 => 01100
11000 => 1100 | 0 => 11001
for the second pair of strings: 11000,10011
-we randomly select the crossover point to be
after the second digit.crossing these two strings
at that point yields:
11000 => 11 | 000 => 11011
10011 => 10 | 011 => 10000

9.Randomly mutate a very small fraction of


genes in the population.
10.Go back and re-evaluate fitness of the
population(new generation):
this would be the first step in generating a new
generation of solutions.Here a single iteration of
the genetic algorithm has improved this sample.

Observations

Initial populations:at start step 5 were


01101,11000,01000,10011

After one cycle,new populations,at step 10 to


act as initial population
01100,11001,11011,10000

The total fitness has gone from 1170 to 1754 in


a single generation.
The algorithm has already come up with the
string 11011(i.e. X=27) as a possible solution.

We are here focusing on point to point trajectory


planning for mechanical manipulators.
Here quadrinomial and quintic polynomials are
used to describe the segment,which connects
the initial,intermediate,and final points in joint
space.
Here the aim is to find the optimum
trajectory,that minimizes both traveling time and
traveling space,while not exceeding the
maximum pre-defined torque,without collision
with any obstacle in the workspace.

Motion Planning Strategy

The supposed point to point trajectory is


connected by several segments with continuous
acceleration at the intermediate via point.
The intermediate points can be given as
particular points that should be passed through.
For a robot the number of DOF of the
manipulator is n and the number of DOF of the
end effector is m.
Let us assume that there are mp intermediate
via points between the initial and final points.

If one wishes to be able to specify the


position,velocity and acceleration at the
beginning and the end of a path segment,a
quadrinomial and quintic polynomial can be
used.
Between the initial points to mp intermediate via
points,a quadrinomial polynomial is used to
describe these segments.
where (ai0,...,ai4) are constants.

And the constraints are given as

where Ti is the execution time from point i to


point i+1.

The 5 unknowns can be solved as:

The intermediate point (i+1)'s acceleration can


be obtained as

The segment between the mp of intermediate


point and the final point can be described by the
quintic polynomial as:

where the constraints are given as

In addition these constraints specify a linear set


of six equations with six unknowns whose
solution is:

The total parameters to be determined are the


joint angles of each intermediate via point (n x
mp parameters),the joint angular velocities of
each intermediate point (n x mp parameters),the
execution time for each segment (mp+1
parameters) and the posture of the final
configuration (n-m).
Therefore for a 3-link robot case,mp=1,n=3 and
one degree of freedom of redundancy for the
final point,there are 9 parameters to be
determined.

If all the intermediate points are connected by


quintic polynomial,there will be eight
parameters to be determined.
This would be more time consuming,which is
why we choose both quadrinomial and quintic
polynomial to generate the segments.

GA Motion Planning Scheme

The GA planning scheme renders an optimized


trajectory having minimum space,minimum
time,while not exceeding a maximum pre
defined torque,without colliding with any
obstacle in the workspace.
The trajectory parameters are encoded
directly,using real codification,as
strings(chromosomes) to be used by GA.
For 3R,redundant robot there are nine
parameters should be optimized as shown in
the following chromosome:

Where
are intermediate joint angle and
velocity of ith joint respectively, qg is the global
angle of the final configuration of the end
effectors which equals the sum of joint angles of
the manipulator.t1 is the execution time from
the initial to the intermediate via point,t2 is the
execution time from intermediate to final point.

Operators in Genetic Algorithm

The initial population of strings is generated at


random and the search is then carried out
among this population.
The evolution of the population elements is
non-generational,meaning that the new replace
the worst elements.
The main different operators used in GA are
reproduction,crossover,and mutation.
For the reproduction operator,the successive
generations of new strings are generated based
on their fitness values.In this case,a 5
tournament is used to select the strings for
reproduction.

With a given probability Pc,the crossover


operator adopted the single point technique and
therefore the crossover point is only allowed
between genes.
The mutation operator replaces one gene value
xt with another one generated randomly with a
specified range by a given probability Pm .

Evolution Criteria

Four indices are used to qualify the evolving


trajectory robotic manipulators free workspace.
All indices are translated into penalty functions
to be minimized.
Each index is computed individually and is
integrated in the fitness function evaluation.
The fitness function ff adopted for evaluating the
candidate trajectories is defined as:

The optimization goal consists in finding a set of


design parameters that minimize ff according to
the priorities given by the weighting
factors,where each different set of weighting
factors must result in a different solution.
The fot index represents the amount of
excessive driving,in relation to the maximum
torque,that is demanded for the ith joint motor for
the trajectory under consideration.

Flow Chart of GA

Where a is the number of robot links,and b is


the number of joint positions from the initial to
the final configuration.
For simplicity ,all mass exist as a point mass at
the distal end of each link.

The index fq represents the total joint traveling


distance of the manipulator as criteria:

The index fc represents total cartesian trajectory


length,as criteria:

The 3R Robot

Whether pj is the robot jth intermediate arm


cartesian position and d(....) is a function that
gives the distance between the two arguments.
The index tT represents the total consumed time
for robot motion,as criteria:
tT =t1 + t2
where t1 and t2 are the execution time from start to intermediate configuration and
from intermediate to target configuration,repectively.

For obstacle existence workspace,obstacle


avoidance objective function fob has been
combined with free space fitness function to
form over all fitness function f,as shown below:
f=ff/fob

By fob , the robot manipulator has the ability to


avoid the obstacle collision during its movement
from point to point inside the workspace.
When all the links of configurations ,which
formed ,by the joint positions between the initial
and final robot configurations do not intersect
obstacle region.The fitness value is fob =1.

The objective function of collision avoidance fob


can be written as:

Results

A moving 3R robot arm from starting point (x=0


m,y=2.3 m,qg =80 degrees) to final point (x=-2
m,y=0 m) was considered.
The robot links have lengths of (l1=1 m,l2=1 m
and l3= 0.5 m) and mass of (m1= 1kg
,m2=1kg,m3=0.5kg).
The maximum allowed torques for joints 1,2
and 3 are 45Nm,20Nm and 5Nm respectively.
The joints velocity and acceleration of the initial
and final configuration are assumed zeros.

The obstacle has circular shape of radius


0.35m.
Crossover probability Pc=0.8 per
chromosome,a mutation probability Pm=0.05
per locus,a population of 200 elements for
intermediate joints angle,joint velocity and
traveling time of the arm,a string size ss=9
robot respectively.
A 5-tournament selection scheme with
elitism,and maximum generation mg=80.

Tournament Selection

Tournament selection is a method of selecting


an individual from a population of individuals in
a GA.
Tournament selection involves running several
tournaments among a few individuals(or
'chromosomes') chosen at random from the
population.
The winner of each tournament(the one with the
best fitness) is selected for crossover.
Selection pressure is easily adjusted by
changing the tournament size.
If the tournament size is larger,weak individuals

The weight factors set for fitness is


At the initial generation of population,GA
generates the chromosome elements with
specified range,as following:

At each generation,GA chooses an adequate qg


By final point coordinates and qg ,the joint
angles of the final configuration can be
evaluated by inverse kinematics of the planar 3link articulated robot.

You might also like