![]() |
Computational Embodied Neuroscience Simulator
1.1
3D simulation library
|
Download page: http://sourceforge.net/projects/censlib/
This software allows to build 3D simulated environments and robots using Bullet physics library for physics simulation and OpenGL for rendering. The library contains the CENSEngine class that is able to automatize the rendering of objects created through the physics engine. Moreover the CENSSerializedEngine::loadBulletFile method contained in CENSSerializedEngine derived from CENSEngine completely automatize the creation of btRigidBody and btHingeConstraint objects and their usage. Objects and constraints can be designed in a visual mode using Blender and then imported into CENSLIB through the method CENSSerializedEngine::loadBulletFile. By this mean writing bullet code directly can also be avoided.
The project start code is the DemoApplication class present in the Demos/OpenGL folder in the Bullet physics library package. The idea of this library was born from the need to have a cleaner code to allow users to bypass all graphics rendering issues and focus on the bullet code.
The CENSLIB library is meant to be used on a linux platform. It depends on bullet library and OpenGL. Other needed libraries are the Eigen2 linear algebra library, used for data manipulation within the graphics module, the Magick++ library used to manipulate screenshots of simulations as pixmaps and boost libraries used for regular expressions and file management.
On a debian distribution install these packages through this command:
sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev \ libmagick++-dev libeigen2-dev libboost-regex-dev \ libboost-system-dev libboost-filesystem-dev libxmu-dev libxi-dev
Then install bullet 2.82 release. On a terminal:
svn checkout http://bullet.googlecode.com/svn/tags/bullet-2.82/ bullet cd bullet; mkdir cmake_build; cd cmake_build cmake .. -DBUILD_SHARED_LIBS=ON -DBUILD_EXTRAS=ON -DINSTALL_LIBS=ON -DINSTALL_EXTRA_LIBS=ON make -j4 sudo make install
Now download the latest CENSLIB version from here, untar, build and install it:
tar xzvf censlib-<release-number>.tar.gz cd CENSLIB
and you can build it using cmake :
mkdir build; cd build cmake .. make -j4 sudo make install
or the Autotools:
mkdir build; cd build ../configure make -j4 sudo make install
The following command Compiles and links an example.cpp source file:
c++ -O2 -o example example.cpp \ -I/usr/local/include/CENS \ -I/usr/local/include/bullet -I/usr/include/eigen2 \ -I/usr/include/ImageMagick \ -lCENS-1.1 \ -lBulletWorldImporter -lBulletFileLoader \ -lBulletSoftBody -lBulletDynamics \ -lBulletCollision -lLinearMath \ -lboost_regex -lboost_system -lboost_filesystem\ -lGL -lGLU -lglut \ -lMagick++
In a typical simulation using CENSLIB a new class is derived from CENSEngine:
Two methods must be overloaded. One of them is CENSEngine::initObjects where you write bullet code about the initialization of your objects and constraints :
Note how the building of a btRigidBody is simplified by the use of the method CENSEngine::localCreateRigidBody, which automatically build and attach a btRigidBody to the world starting from a shape, a transform and a mass value.
The other method to overload is CENSEngine::step. You can write here your bullet code for applying forces at each timestep:
the call to CENSEngine::step must always be at the end of your overloaded step method, otherwise the simulation does not start.
Once you built your class derived from CENSEngine you only need to define an object of that type and call its CENSEngine::init and CENSEngine::run methods in the main function:
When the program runs the first time two files are searched for in the ./parameters directory, one called "physics_parameters", the other called "graphics_parameters". They contain the values of graphics and physics parameters respectiivelly. Both can bechanged offline before starting a simulation. if those files do not exist they are created with default values:
graphics_parameters
800 ------- SCREEN_WIDTH <- pixel width of the window 600 ------- SCREEN_HEIGHT <- pixel height of the window 10 ------- SCREEN_XGAP <- horizontal position of the window 10 ------- SCREEN_YGAP <- vertical position of the window 10 ------- TIMESTEP <- time interval of a single timestep (milliseconds) Demo ------- SCREEN_TITLE <- title of the window 70 ------- FIELD_OF_VIEW <- the angle (degrees) defining the width of the FoV 1.2 ------- RATIO <- ratio between horizontal/vertical FoV angle 1 ------- NEAR <- near plane of view 10000 ------- FAR <- far plane of view 0.15 ------- ANGLE <- from where the camera points to the target 15 ------- DISTANCE <- distance of the camera from the origin 15 ------- HEIGHT <- height of the camera with respect to the origin 0;0;1 ------- TARGET <- the center of the scene 0;0;1 ------- UP <- direction of the UP vector 0.1 ------- MOV <- right-left increment when moving the scene 0.1 ------- GAP <- bottom-up increment when moving the scene 0.1;0.1;0 ------- ENV_COLOR <- background color 0.6;0.2;0.2 ------- GROUND_COLOR <- floor color 0.2;0.6;0.2 ------- OBJECT_COLOR <- generic object color 0.2;0.2;0.0 ------- BOX_COLOR <- box color 0.4;0.4;0.6 ------- CAPSULE_COLOR <- capsule color 0.7;0.1;0.7 ------- SPHERE_COLOR <- sphere color 0.2;0.6;0.2 ------- COMPOUND_COLOR <- color of a compound object 0;0.6;0.6 ------- SOFT_COLOR <- color of a soft body 0.5;.5;0.2;1 ------- LIGHT_AMBIENT <- lights - ambient light color 1;1;1;1 ------- LIGHT_DIFFUSE <- lights - diffuse light color 1;1;1;1 ------- LIGHT_SPECULAR <- lights -specular light color 10;10;10;1 ------- LIGHT_POSITION0 <- light0 position 10;10;10;0 ------- LIGHT_POSITION1 <- light1 position
physics_parameters
0;0;-9.8 ------- GRAVITY <- a vector defining gravity amplitude and direction 0.05 ------- STEP <- integration step for physics 20 ------- SUBSTEP <- number of real teps if timestep is too long
These are some examples of how to implement the main features:
derive an Engine from CENSEngine:
Implement the overloading of CENSEngine::initObjects and CENSEngine::step
derive an Engine from CENSEngine:
Implement the overloading of CENSEngine::initObjects and CENSEngine::step
derive an Engine from CENSSerializedEngine:
Now the overloading of CENSEngine::initObjects and CENSEngine::step is very simple. Just call loadBulletFile:
derive an Engine from CENSSerializedEngine:
Within CENSEngine::initObjects call loadBulletFile, while within CENSEngine::step call the method CENSSerializedRobot::move on the acquired CENSSerializedRobot object, indicating one of the loaded hinges:
derive an Engine from CENSSerializedEngine
Implement the overloading of CENSSerializedEngine::initObjects and CENSSerializedEngine::step