About this Blog

This blog is an engineering log book; for me to record the progress on my many projects and hopefully to inspire you.

Some projects do not get off the ground, they remain as interesting thoughts, a select few get some work done on them, even fewer get close to completion, and none get completed because unfortunately I subscribe to the theory: "If something ain't broke then it doesn't have enough features". If you'd like to collaborate on some work to get something to a useable state then send me some communications.

Being a blog, posts are listed in chronological order. However I usually have multiple projects on the go and will try to post some of my earlier work. With this in mind I'll try to add labels to each post so all posts relevant to one project can be easily extracted.

Enjoy and happy hacking.

Monday, April 27, 2009

Compiling the physics abstraction layer (PAL) with the BULLET physics engine

So I have an aquatic robotics project I am working on where I want to build a physics simulation for testing my control code. The robot itself is quite large and requires a large amount of space to operate in, i.e., open ocean and is currently in another city. This all makes testing and experimentation difficult. Therefore I am going to build a physics simulation that will emulate the robot on my laptop so I can do development at my leisure, and without getting water and sand in my beautiful laptop.

So to start with I need to select a physics engine and compile it for my computer running Ubuntu Jaunty 9.04 64-bit. I have chosen to use the Physics Abstraction Layer (PAL) since it looks relatively easy to use and includes some buoyancy functionality (which I intend to improve). It requires an actual physics engine back end, there are many to choose from such as ODE, Tomahawk, Box2D, .... I have chosen the BULLET physics engine.

Now to set up the programming environment. How to compile and build PAL physics abstraction layer with the BULLET physics engine on Linux. The lines starting with a $ are to be executed on the command line.

Get the Subversion source control client (svn):
$ sudo apt-get install subversion
Checkout read-only copies of PAL and BULLET from svn:
$ svn co https://pal.svn.sourceforge.net/svnroot/pal/pal pal
$ svn checkout http://bullet.googlecode.com/svn/trunk/ bullet-read-only
Get some of their dependencies:
$ sudo apt-get install freeglut3 freeglut3-dev cmake g++ cmake cmake-gui libsdl1.2-dev
Compile BULLET.
$ cd bullet-read-only
Edit install.sh, replacing all Window's line endings (\r\n) with UNIX line endings (\n)
$ gedit install.sh &
Menu->Search->Replace, Search for \r\n, Replace with \n, click Find. Save, Quit.
$ ./autogen
If you have a multicore CPU then include the --enable-multithreaded option. It may give you better real-time performance.
$ ./configure --enable-multithreaded
Compile using make.
$ make -j 2
The -j 2 option tells make to do two jobs at once, i.e., use two CPU cores.
Install the Bullet libraries to /usr/local/lib/ and the Header files to /usr/local/include/bullet/
$ sudo make install
I had to manually copy the btActionInterface.h file to get PAL to compile, it appears it was left out of the install script.
$ sudo cp src/BulletDynamics/Dynamics/btActionInterface.h /usr/local/include/bullet/BulletDynamics/Dynamics/
Compile PAL.
Do not use the premake instructions for building PAL. I believe they are old. Use the Cmake system instead.
$ cd ../pal/
Open the Cmake GUI
$ cmake-gui &
Enter the source and build directories at the top to the current directory (pal). The window below will list a bunch of variables. Select the tick box for PAL_BUILD_BULLET. Click "Configure". A window will show up. Select the default Unix make file option.

Some more variables will be shown in the main window.
  1. Set the BULLET_SINGLE_THREADED if you didn't build the multi-threaded version before.
  2. Fix the BULLET_INCLUDE_DIR -> /usr/local/include/bullet and the
  3. BULLET_LIBRARY_??? variables -> /usr/local/lib/lib???.so if they haven't been found.
  4. Change from simple view to advanced view and find the CMAKE_CXX_FLAGS variable and add -fPIC to it.
Click Configure again. Hopefully there won't be any errors in the bottom window. If so try fix them.

Click Generate. This will setup the project for you.

Now make a few quick edits to get the demo to work. In pal/Config.h change the default engine from "BULLET" to "Bullet". In pal/example/begin.cpp change line 7 from PF->LoadPALfromDLL(); to PF->LoadPALfromDLL("/usr/local/lib/"); so it know's where to find the Bullet physics libraries.

Now compile it.
$ make -j 2
And install it.
$ sudo make install
Tell the operating system about the new libraries.
$ sudo ldconfig
Now we should be able to test the demo/test program. It has been compiled into the bin/ directory. Run it.
$ bin/palbeginner
Should get output like:
Found dll 'liblibpal_bullet.so'
Found dll 'libbulletmultithreaded.so'
Found dll 'libbulletcollision.so'
Found dll 'libbulletdynamics.so'
Found dll 'libbulletmath.so'
Found dll 'libbulletsoftbody.so'
Current box position is 1.49902 at time 0.01
Current box position is 1.49706 at time 0.02
Current box position is 1.49412 at time 0.03


Nick said...

Thank you! I've been trying to get this to work for about a day now and your instructions helped a HEAP! (aren't search engines great?)

saviourmachine said...

Hey, that's nice. I wanted to try PhysX, PAL and Delta3D. Just tested PAL now with Bullet using your directions. Changing the all CAPITALS version from "NOVODEX" to "Novodex" in pal/Config.h worked. For the PhysX files I had to change some macros on Ubuntu, for example in the NxSimpleTypes.h file they forgot to add "defined" as in #elif defined LINUX. Oh yeah, and contrary to what is stated in the cmake-gui, there is SDL on Linux (sudo aptitude install libsdl-dev).

The only big BUT, the ball stays at position 1.5:

/opt/pal$ bin/palbeginner
Found dll 'libpal_novodex.so'
Found dll 'libbulletmath.so'
Found dll 'libpal.so'
Found dll 'libpal_bullet.so'
Found dll 'libbulletcollision.so'
Found dll 'libbulletdynamics.so'
Found dll 'libbulletsoftbody.so'
Current box position is 1.50000 at time 0.02
Current box position is 1.50000 at time 0.04
Current box position is 1.50000 at time 0.06
Current box position is 1.50000 at time 0.08

Anonymous said...

Thanks for the tutorial. I think it worked great for installing bulletphysics, but I've had trouble getting the PAL part to work too.
Does this still work when you try to install? I tried, but I get all sorts of errors which I listed here (Since I want to use Bullet and PAL with irrlicht): http://irrlicht.sourceforge.net/forum/viewtopic.php?f=1&t=46752

If you encountered this and have any advice, suggestions, etc. I would really appreciate any help. Thanks!