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.

Thursday, September 24, 2009

Naming components in software? - Think about it!

If you are writing a piece of code, especially for other peoples use, think about how you name it. Does it make sense? I have just wasted several hours chasing a bug in some VHDL for an Altera Cyclone III. I want to force the use of carry chains; to inform the synthisizer, pass the signals through a CARRY_SUM buffer that has the ports (Sin, Cin, Sout, Cout). There are a few rules that must be followed for the input logic functions of the signals.
rant begin
Why did the engineer who constructed the CARRY_SUM buffer, put the ports in the opposite order; sum then carry. This engineer has single handedly wasted three hours of my life and I shudder to think how many other people have had the same problem.
end rant;
Unfortunately this is set in stone now, no way to change it, here to annoy me forever. I've posted this in the hope that it will have saved you some precious time, because I couldn't find the solution anywhere else on the interwebs, probably because it makes you feel stupid when you do find the issue and don't want to admit it, hence the rant (it wasn't my fault).

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