|
Army ant simulation
|
The first objective of this simulator is to try to replicate army ant bridge formation with flipping biped robots. The simulator can be used to help determining the parameters that influence the bridge formation. It also allows to try several basic rules on the simulated robots quickly. The simulator is working in 2D and combines 2 main libraries:
However, both libraries does not use the same origin. Indeed. while the SFML (graphic) origin of the shapes is on the top left corner, the Box2D (physics) origin is set at the middle of the shape.
(cf image below)
In addition, while in SFML all the positions are given in the world reference frame, the Box2D positions can be obtained either in the world reference frame our in their local reference frame (the shape from where the position is asked)
More importantly, the Box2D dimensions are given in meters while the SFML ones are given in pixel: to go from one to the other the conversion has to be carefully done Thus, if it is possible to do all the transformation from the Box2D position to the SFML ones manually, it is usually easier to proceed as following:
To launch a simulation with existing terrains and without modifying the intrinsic properties of the robots or the controller, only the main.cpp and Demo.cpp file should be modified. In addition, the simulator has not been implemented as a library and the main program is mixed with background source code. Thus it is better to start from the existing main file (and modifying it) than creating a new one. Indeed, the main file also implements the basic function to parse the arguments to launch a simulation and the help function.
The configuration parameters are defined in Config.h. There is several way for the user to specify the input parameters. An easy way to do so when just launching the simulation from the IDE (eg:eclipse) is to modify the default parameters value in default_parameters(config::sConfig& cfg) (in main.cpp).
Another proper way to specify the configuration parameters is to write them in a config file and launch the simulation from the terminal specifying the configuration path : -cp <path>. An example of configuration file is given under examples/config_template.cfg.
However, if one want to launch a batch of simulation with different values for the parameters. It might be easier to specify the parameters values individually with the correct entry command. The list of command can be obtain when launching the simulation from the terminal: "./Simulation_v2 -h " or "./Simulation_v2 --help"
From the source code, the commands are summarized in help() (in main.cpp)
Different type of terrain are already implemented.
The Default terrain is the one implemented in the parent class Terrain. It is a simple horizontal ground.
The BoxTerrain is an horizontal rectangular box.
The Vterrain is an horizontal ground with a V-shaped gap.
The V2BLTerrain is similar to the Vterrain but the bottom of the V-shaped gap is truncated so that the width corresponds to 2 body-length.
The Ramp is a single descending ramp (with a 90° angle).
The VStepper is a more complex terrain where the obstacle is kind of a stepper but with sharper angle (angle < 90°).
To select which terrain should be used in the simulation, it has to be specified in the Demo.h file: the type of the Demo::m_terrain member has to be adapted. Once the terrain has been chosen, the terrain Parameters (cf sTerrain struct in Config.h) can be adjusted using different methods described in Configuration parameters
If the creation of a new terrain is necessary, the new class should inherit from the global Terrain class. then the newly created .h file should be included in Demo.h.
It might be necessary to re-implement the getScale() function depending on the parameters so that the whole terrain fits the window size.
The robot flow is either by a given delay between the robots and initial position or a given distance between the robots and phase shift. The way the robots are created is controlled in the Demo.cpp file by choosing which function is used in Demo::demoLoop(). It can be either Demo::addRobotWithDelay() to control the robot creation with a given delay or Demo::addRobotWithDistance() to control the robot creation with a given distance. Then the distance, delay, phase, initial position are specified in the sSimulation Configuration parameters.
By default, the delay (or distance) between the robots follow a constant distribution (ie the distance/ delay is identical between every successive robots). In certain cases, it can be interesting to customize the distribution for example to study the introduction of perturbation. A way to do so without modifying to much the code structure is to update m_config.simulation.robot_delay (respectively m_config.simulation.robot_distance) directly in the Demo.cpp file at every timestep (either within a newly created function or directly in the Demo::demoLoop() one).
Currently, two different delay distribution have been briefly implemented:
The rules can be adapted at several positions
As briefly explained in the Code overview, currently, the simulation should be adapted by changing directly the main function of the main.cpp file and adapt the Demo.cpp / Demo.h files. The basic steps are described below
In main.cpp :
In Demo.h: change the terrain type
In Demo.cpp: choose how the robots are created in the Demo::demoLoop() : either with a given distance or a given delay in the main demoLoop. Be careful, you have to change at two distinct positions: in the first part of the loop when the visualization is activated and in the second part of the loop when the visualization is deactivated
1.8.14