This page primarily provides usage examples for simulating and evolving the robot in RoboGen with User Interface edition.
Four steps to evolve a robot
Robogen is designed to be a simple and powerful tool for evolving robots. The picture below shows the fours simple steps:
The goal of the following sections is to provide a detailed explanation on all the aspects of Robogen Software in detail, with the aim to build a Smart Cart Robot whose brain is evolved through the RoboGen software Suite.
Setting up the environment:
Once the last line of installation command of the installation procedure is executed, the robogen user interface will appear on the screen. If a popup to add Robogen as a system app appears, press yes. From now on, you can start the app by just searching Robogen on the search bar.
The app comprises two main components: simulator and evolver. As names suggest, the simulator is responsible for performing and displaying you a simulation of your robot, while the evolver is responsible for evolving your robot. At any time, you can see the status of the simulator and evolver on the top right corner of the app. In the case of an inactive system, you will need to activate it by clicking a link appearing on the status.
By default, at the first usage, the software will download necessary files. You can see the downloading status at the top-right corner of the Robogen app window. When the app is ready to use, the status will change for both Simulator and Evolver to active. Once the statuses are active, you can follow this documentation to build your first Robot in Robogen.
Download the files: Cart Robo files for download
Once downloaded extract the zip file and place it in the folder
By default, the app will be pointing to the home page. It contains two folder paths: Main Folder and Project Folder. The Main folder path will automatically point to
~/Robogen/Exercises folder. Remember, only the files within this folder are available for the Simulator and the Evolver. The second folder is the
Project folder that contains all the project files. Go ahead and select
~/Robogen/Exercises/Excercise1 as your project folder. This step will automatically recognize the files and load them into the system.
Step 1: Build a Robot
This section allows to manually defining the body and brain of a robot or upload an existing robot body-brain file (e.g. name.robot.txt). For this exercise, choose cart.robot.txt as your Robot file (it should be selected by default). Followed by this, you will have the following sections
- Robot Body: that describes the tree structure of the body
- Hidden neurons: that describes any hidden neuron in the brain of the robot along with their parameters
- Connection to describe the connection of the neural network and
- The bias that defines the offset
As you see the current robot has no hidden neurons and no connections. However, there is a slight bias that makes the robot moves.
Let’s now test the robot by clicking Test Me button on the right bottom of the application. Clicking this should open a new window. Click, drag and zoom to have a look on the robot. As you see, the robot has three IR sensors on the front and one IR sensor on the back. The robot also has a front-drive mechanism, where the front two wheels are actively driven by DC motor while the back wheels are passive.
Click the button P on your computer to see the robot in action.
Wondering why the robot moves?
This is because of the bias in the robot’s network. The robot currently has a bias of 0.1 (clockwise) on the left wheel and 0.5 (anticlockwise) on the right wheel. Modify these numbers to get a robot that goes straight with its maximum speed.
Step 2. Simulation Settings:
Simulation settings aims in defining the environment of the robot. The settings should be as close as that of reality to ensure the right robot behavior.
In Simulation Settings tab you will see the file conf.sim.txt is automatically updated. Firstly, go ahead and press Simulate Robot button on the right. Zoom in the simulation window and press P to simulate the robot.
Below are the parameters that can be configured in the Simulations Settings.
• Robot File (The main Robot file from Step 1)
• Fitness Function File. (This is the important file that defines the good behavior of the robot. More details of writing this file are available here??????????)
• Time step and simulation time are the parameters that define how precise the simulation calculation should be and how long the execution should take place.
• Terrain friction and Gravity
• We can also have many other parameters for the simulation settings. Look here for more details.
• obstaclesConfig file is what defines the obstacle (or maze) of the simulation. You can simply modify it by opening it in a text editor. Guide for creating a maze/arena is available here.
Step 3. Evolution Settings:
Evolution settings define the parameters that you can change to evolve an effective robot. This link will guide you through the detailed list of parameters.
As you see the evolution settings from conf.evol.txt would be automatically loaded into the User Interface. You should have the cart.robot.txt (from step 1) and conf.sim.txt (from step 2) as your robot and simulation file. Cart robot is a special kind of robot that supports only the brain evolution, however, Robogen is capable to evolve a body of the robots too. So for time being set the evolution mode to brain. You can also explore the evolution parameters (like number of generations, population and offspring size, Replacement Strategy, etc..) and Brain Variation Probabilities.
With default parameters, let’s run our first evolution by clicking Evolve Robot button on the right bottom corner. Clicking Evolve Robot button leads automatically to section 4 where results of the evolution are displayed.
Step 4. Evolution Results:
On this page, you have two tabs, Past Evolutions, and Ongoing Evolution. Past Evolutions are used to analyze your previous evolutions and Ongoing Evolution (where you are now), will show the status of your current evolution. However, both of these tabs have almost similar layouts.
The top part of the page contains the Fitness Evaluation Graph that shows the Generation on the X-Axis and the fitness value in the Y-Axis. Below this graph, you have a table that shows the best, mean and standard deviations of the individuals in each generation. On the right of these values, it displays the performance distribution within the population. In this distribution, all individuals of that generation are represented as a square (of different color according to the individual fitness value). By clicking on any individual of the generation, it is possible to play the simulation of the corresponding individual.
What does Fitness value mean??
The fitness value is the value that defines the performance of the robot. This value comes from the fitness function file that you used in Step 2. By default, the fitness function we have provided try to maximize speed of the robot regardless of obstacles.
Can Evolutionary Algorithm eventually solve the maze problem with this fitness function??
Yes, eventually, the well-tuned evolutionary algorithm can solve the maze just by evolving a robot that follows always the same trajectory. This is called overfitting problem. The ideal fitness function should generalize the problem in such a way that the same robot should be capable of solving the task irrespective of the maze configuration and of a certain trajectory.
How to ensure that your robot does not overfit a fixed trajectory?
Starting Positions: You can have multiple starting positions configured through the startPositionConfigFile in the Simulation Settings. This method will evaluate every individual (during evolution) starting from all the available starting points and the lowest value across them is returned as the fitness value of the robot.
How to test the robot in different arenas?
In the simulation settings section of the robogen app, it is possible to change the arena by changing: obstaclesConfigFile= nameofyourfile.arena.txt
By default we provide two areas:
Bravo! You made your first step towards evolving the robot through artificial evolution.
Note: On Linux and Mac you should run all commands starting with “./” as is shown below. On windows, you should omit this. The present working directory for windows should be Robogen Windows\run and for Linux should be robogen/build
View the shape and the behavior of a robot
You can visualize the shape and behavior of a robot using the robogen-file-viewer software using the following command:
./robogen-file-viewer <robot .json or .txt file> <scenario configuration>.txt
With the example files:
./robogen-file-viewer ../examples/simpleRobot.txt ../examples/conf.txt
Use ‘p’ to pause the simulation, and ‘q’ to quit.
If several starting positions are defined, you can add another parameter to specify which one is to be used. To do that, simply append at the end an integer from 1 to n, where n is the number of specified starting positions:
./robogen-file-viewer ../examples/simpleRobot.txt ../examples/conf.txt 2
This command will start the robot from the second defined starting position.
For each file viewer run, it is possible to output all files necessary to reproduce the run as well as statistics of the run, i.e. Sensor and Motor history. In order to do this, you must use the –output option of robogen-file-viewer, e.g.:
./robogen-file-viewer simpleRobot.txt conf.txt --output OutputData
where OutputData can be any name you choose. A folder “OutputData” is then created, which contains the output files. You can then plot the content of those files using “robogen/octave/robogenPlot.m”, which can be executed in Octave or Matlab. This folder will also contain a NeuralNetwork.h file, which is what you will use for uploading the robot’s brain onto the Arduino for use on a physical robot.
Additionally, you can combine the –output option with –webgl option to additionally output a webGL.json file in the output directory, which can be used to visualize your robot in the online visualizer, and shared with others.
./robogen-file-viewer simpleRobot.txt conf.txt --output OutputData --webgl
Note: by default running the file viewer with –output multiple times in a row, will cause the software to create a new directory with incrementing integer suffixes on each invocation. If you really want to write to the specified directory, potentially overwriting any data that already exists in that location you must additionally specify option –overwrite
./robogen-file-viewer simpleRobot.txt conf.txt --output OutputData --overwrite
The robogen-file-viewer has many other options, which can be seen by running:
Artificial evolution of robots
The main part of RoboGen is the co-evolution of the brains (controllers) and bodies (morphologies) of robots. Each evolutionary run first has to be configured using an evolution configuration file, which contains the evolution parameters such as the selection method and various mutation parameters. An example of such a configuration file is provided, “evolConf.txt” in “robogen/examples”. As the RoboGen simulator (also called “the server”) is implemented as a separate executable from the evolution engine, we need to launch them both. First, launch the simulator by executing in a separate command line window:
Where 8001 is the suggested port for communication between the evolution engine and simulator. The simulator should signal its readiness by outputting “Waiting for clients…” to the console. (NOTE: If the execution crashes or you get an error stating “cannot bind port 8001” use other port numbers such as 8002 or 8003. You should also update this port in the last line of evolution configuration file ).
Once the simulator is ready, launch the evolution engine using:
./robogen-evolver <seed, INTEGER> <output directory, STRING> <evolution configuration file, STRING>
where “seed” is a seed for the pseudo-random number generator, “output directory” is a path to a directory where the output files should be written, and “evolution configuration file” is the location of the evolution configuration to use. With our example (verify that the directory contains evolConf.txt, conf.txt, obstacles.txt and startPos.txt):
./robogen-evolver 1 results/my_first_evolution_experiment ../examples/evolConf.txt
You can read more about the evolution configuration here. The artificial evolution engine should now launch, and a folder titled “results/my_first_evolution_experiment” should appear in the execution folder. That folder contains “BestAvgStd.txt”, which is a file containing fitness statistics, and also contains a copy of the evolution configuration files, and will contain the best individual for each generation as evolution proceed.