Вы находитесь на странице: 1из 29

ROBOTC PROGRAMMING

11. Advanced programming

d-r. Ramona Markoska, assist. prof.


TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

Topic of discusion in this chapter


Robot Metaphors and Models Base Robot Architecture and Design Software Diagram for Robot Genetic algorithm Darwin Genetic Algorithm: Maze Program Example Genetic Algorithm Process:Initialize Population, Calculate Fitness , Selection Using Fitness, Genetic Operators, Chromosomes

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11. Robot Metaphors and Models


Animatronic Robot or device Perceiving Robot

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11. Robot Metaphors and Models


Reactive Robot as a simplest behavioral robot. This is the simplest robot that satisfies the definition of a robot Reactive Robot in environment

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11. Robot Metaphors and Models


Emotional Robot has a simple form of memory or state.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.1. Base Robot Architecture and Design

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.2. Software Diagram for Robot

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.3. Genetic algorithm


Genetic algorithm is an evolutionary algorithm which models a form of evolution. These could be: Darwinian Evolution Lamarckian Evolution Genetic Algorithm Process: Each genetic algorithm have the following steps in a similar way: Initialize Population Calculate Fitness Selection Using Fitness Genetic Operators Repeat Unless Condition is Satisfied End

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.4. Genetic algorithm-flowchart


A fitness value represents how much an organism is suited to the environment Genetic operators are used to create the offspring from two parents. Some of these operators are: Crossover Mutation
Darwinian GA: The Process (pic.right -> )
TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.5.Genetic Operators

A crossover operatore is done by taking a random point and swapping the left (or right) side of the parent chromosomes. This creates the chromosomes of the children.

A mutation operator is done when a random position in a chromosome is selected and the value is inversed.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.6.Darwin Genetic Algorithm: Maze Program Example


.Description: In this program, the goal is to create a simulated robot which will evolve each generation to solve a maze. Eventually, the robot would get to the end, unless the maze was impossible to solve The maze map:

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.6.Darwin Genetic Algorithm: Maze Program Example


In the maze, a red square represents the starting point. A green square represents the goal. A black square represents a wall. A empty square represents a movable square.

The maze map:

The numbers represent the Manhattan distance from the goal


TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.7.Darwin Genetic Algorithm: 1.The Chromosome Coding and. 2. Initializing the Population
For the chromosomes, it is necessary to have a coding for each of the directions: Forward = 1 Left = 2 Right = 3 Backwards = 4 Turning is not required since an omnidirectional drive is used
At the beginning of the program, the first step is to initialize a population, and.. .. to create a maze, and place it into a 8 by 8 maze. We do this by creating a for loop filling in numerical values into the array. The coding is as below: 7 is the start 8 is the goal 9 is a wall

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.7.Darwin Genetic Algorithm:Initializing the Population(2)


Numeric coding of the maze 9 = wall

7 = starting point
8 = goal

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.8.Darwin Genetic Algorithm:The code for initializing the shape of the maze

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.9.Darwin Genetic Algorithm: The code for initializing


the chromosome placement array

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.10.Darwin Genetic Algorithm: Numeric coding (2)


Numeric coding of the maze 9 = wall

7 = starting point
8 = goal

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.11Darwin Genetic Algorithm: Arrays and Chromosomes


It is necessary to create 2 other copies of the array: for keeping track of the order the place the chromosome values, and for calculating distance traveled. After the array was created, the chromosomes were made.

This is done by creating a for-loop which assigns random movement values (1-4) into a integer array of 21 (the number of unused space in the maze).
Each chromosome is part of a vector with 1000 chromosomes (the population).

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.12.Darwin Genetic Algorithm: The code for generating the chromosomes

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13. Darwin Genetic Algorithm- Calculating the Fitness


The fitness of each chromosome is done by simulating the maze. The maze is initialized by first reset setting the state of all arrays. Then, we fill in the maze with the chromosome values using one of our defined maze arrays as a guide. We have a variable for the robot which is initialized at the starting position. We move according to the number (1-4) of the cell.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13.Darwin Genetic Algorithm- Calculating the Fitness Function (2)


The number represents the order that the chromosome values are placed into the array.

The values of the chromosome is placed from left to right

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13.Darwin Genetic Algorithm- Calculating the Fitness Function (3)


The code for finding the start and end of the maze:

Note that !

7 = starting point 8 = goal

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13.Darwin GA: -Calculating the Fitness (4)


The code for filling in the maze:

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13.Darwin GA: Calculating the Fitness (6)


The function for checking the movement of the robot: continue on the next slide

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.13. Darwin GA: Calculating the Fitness (6)


The function for checking the movement of the robot -2nd slide

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.14.Darwin GA: Sorting and Selecting the Best Chromosomes


The next main function is the selection of the best chromosomes. This is simply done by sorting the vector until the lowest fitness values (20, 21, etc) at the bottom and the highest fitness values (2, 3, etc) at the top. Therefore, we select the top half or third to get the best chromosomes.

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.15. Darwin GA: Mating and Looping


After selection of the chromosomes, we them randomly mate them. Thus, we then apply the crossover and mutation operators. We create the next generation from this. As the final step in the process, it will loop until the condition is solved, being getting to the end. In simple words, the fitness value has to equal 2. Code: Crossover and Mutation

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

11.16.Darwin GA: The Running of a Generation


Position 11 from Start

Well use this chromosome. 333112111242244444434

Note that the goal sequence is: 333112111222244444434 We first fill in the maze. The next step is to see how far the robot (orange square) goes. Now we calculate the fitness by first seeing how far it went: 10 21-10 = 11 which is the fitness value
TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

Then, we are ready for calculate the other fitness values and for selection of the best chromosomes and apply the genetic operators (shown before). ROBOTC PROGRAMMING

References

Marek Perkowski, Class Mat. http://web.cecs.pdx.edu/~mperkows/CLASS_479/lectures-2006.html http://www.codeproject.com/Articles/26203/Genetic-Algorithm-Library Inteligent Computing Lab. http://iclab.life.nctu.edu.tw/POPI/doc.php#cont http://www.frank-dieterle.de/phd/2_8_5.html Alan Cheng, Robot Project Report , http://web.cecs.pdx.edu/

TEMPUS IV Project: 158644 -JPCR Development of Regional Interdisciplinary Mechatronic Studies DRIMS

ROBOTC PROGRAMMING

Вам также может понравиться