Goals: Evolving a cart robot
These pages aim to lay down the foundations is to evolve a neural controller for a simple differential wheel drive cart robot (similar to the e-puck) that has to navigate in an environment as fast as possible while avoiding obstacles (for example, walls). Evolution is performed in the RoboGen with the user interface, and tests of the best controller found by evolution can be done either in simulation or on a real, 3D printed version of the robot. However, you could use all the RoboGen software editions to achieve the same.
Theory
Neural Controller. The robot is controlled by a neural network which transforms the sensory IR inputs received from the sensors into motor commands for the left and right wheels of the robot. Inputs are scaled to fit the range [0,1] and the neuronal transfer function is chosen to be the logistic (sigmoid) function.
Genetic Algorithm. A genetic algorithm is used to evolve the synaptic weights of the described neural controller. The synaptic weights, which represent the genes of the individuals, are coded using floating point values. When putting together, the genes form a genome.
A population of individuals is evolved, using tournament parent selection, one-point crossover, weight mutation and either “mu+lambda” or “mu, lambda” replacement. The genomes of the first generation are initialized randomly in the range [−3,3]. Each individual is evaluated based on the fitness function defined in the examples/obstacleAvoidance.js (more on this below).
In the case of “plus” replacement, the mu parents and lambda children are grouped together and ranked according to their measured fitness values, the top mu individuals are copied to the new population (elitism). This allows evolution to make sure that good solutions are not lost because of mutation or crossover. On the other hand, in the case of “comma” replacement, the mu parents are discarded, the lambda children are ranked, and the top mu of these are copied to the new population (lambda>=mu). This replacement strategy favors exploration.
After this step, a new set of lambda children are generated from the mu survivors with parents chosen by a tournament competition. With a certain probability two parents will be chosen (each by its own tournament) and one point crossover is applied to the pair, otherwise, a single parent is chosen. In either the case the new offspring (either a clone or created by recombination) will have each of its genes mutated with a certain probability. In the case of mutation that gene will have a number drawn from a Gaussian distribution (w/ mean 0) added to it.
All of these parameters: choice of “plus” or “comma” replacement, the values for mu and lambda, the tournament size, the crossover probability, the mutation probability, and the mutation standard deviation are all configurable.
More detailed information with regards to the implementation of RoboGen is available in this presentation.
Fitness Function (aka Scenario) Definition
Fitness Functions of Evolutionary Robotics are called Scenarios in RoboGen. Scenarios can be defined by short pieces of ECMAScript/JavaScript. Please refer to Custom Scenarios for complete details.
Fitness functions of the Cart Robot
CartScenario.js is the scenario file that you can download the fitness function that guides the robot to travel as fast as it can. However, you are welcome to modify the fitness function to make the robot more intelligent in avoding the obstacles. We have already provided you some helper functions too.
Here you will design and implement a fitness function that will reward robots to navigate in an arena as fast as possible and without touching any walls. To do you will modify the code in examples/obstacleAvoidance.js.
Explanation: After each simulation step we collect various information about the robot’s behavior in afterSimulationStep
, and then at the end of the simulation, the fitness for that simulation is computed in endSimulation
. Finally, getFitness
will return the min fitness across all simulations (so, for example, if we evaluate a robot in multiple environments it is only as good as its worst case).
Note: Be careful in modifying the code. You can debug by printing to the JavaScript console (opened in Firefox with Ctrl+Shift+K ) by using console.log()
.
Before trying to evolve with a given fitness function, make sure it works by just running the simulator. As evolution progresses you will see the performance of your population on the graph, if you are using other versions you can use BestAvgStd.txt file from the results directory. You can run plot_results.py to create a fitness graph (requires having Python with Pylab on your computer too.
Genetic Algorithm parameters
RoboGen provides two different evolutionary algorithms namely Genetic Algorithm and HyperNEAT. that can be used to evolve robots. Further, RoboGen provides versatile parameter sets that can be altered to improve the efficiency of evolution. Here are some of the parameters to name few: mu, lambda, replacement, tournamentSize, pBrainMutate, brainSigma, pBrainCrossover.
More parameters can be found here.
Generalization
One of the main challenges in the robotic world is to transfer the simulated robot in reality. RoboGen developers have carefully considered many such constraints to make the simulation environment as close as that of reality. However, we also provide some crucial parameters to robot designers such that they can ensure the realistic robot evolution. Some of those parameters are capAcceleration, maxLinearAcceleration, maxAngularAcceleration, maxDirectionShiftsPerSecond, disallowObstacleCollisions, etc..
For details on the contents of these files, see Simulator settings
Transfer to the real robot
When you have found a good controller that you wish to test on a real robot, click the “Generate log files” option in the new simulation window and give it a directory to write to. Then open the NeuralNetwork.h file from this directory. Now you can continue building your robot as described here and use the neural network file when required.
Next Exercise: Your First Evolution