Monday, May 17, 2010

[Py] PyODE installation and test

I read about ODE (no, not the ODE in math) in a thesis last week, and searched it to see what it is. ODE is the abbreviation of Open Dynamic Engine, an library for simulating rigid body dynamics. As a Python fan, it's reasonable for me to search related module of ODE written in Python. The keywords ``python ode'' brought me the PyODE, a set of Python bindings for ODE.

There are three examples on the PyODE page. I tried to test it, and installed what my system lacked accordingly.

The installation in Ubuntu is quite easy as usual. My procedures are listed as the follows.

First, get the PyODE module, which is the basic one to run the 1st example:
$ sudo apt-get install python-pyode

Then if you want to run the 2nd example, you need Pygame:
$ sudo apt-get install python-pygame

Finally, the 3rd example demands PyOpenGL:
$ sudo apt-get install python-opengl

After these steps, I found the best way to get all these examples is to install the documents of PyODE:
$ sudo apt-get install python-pyode-doc

You could find the source code of all the three examples in
/usr/share/doc/python-pyode-doc/examples

There are two more examples in the folder, but they needs more libraries. To run the ``transforms.py'' example, the error message showed there was no module named ``cgtypes.'' It seems to be in the cgkit package. This package cannot be found in Ubuntu repository, so I downloaded the source and read the README. The SCons and Boost are necessary:
$ sudo apt-get install scons
$ sudo apt-get install libboost-dev

But I couldn't install the package and still get no luck so far.

I decide not to bother with the Scons and Boost by now. If I have some time, I would like to play with the original 3 examples to see whether I can learn something fun and useful from them.


When I ran the setup.py to install the package, there came lots of error messages. With some efforts, I noticed one of the error message read there was no file named ``boost/python.hpp.'' And with some more efforts, it came to me that maybe something like ``libboost-dev'' is needed. Therefore, I typed libboost in the terminal and used the Tab key to check available packages. Yes, there was a library named ``libboost-python-dev'' which looked like what I needed, so I installed it by typing:
$ sudo apt-get install libboost-python-dev

Then, everything was ready to install the cgkit in the downloaded and extracted folder:
$ sudo python setup.py install

The cgkit has been installed, though, the example transforms.py cannot be executed correctly. According to the error message (ImportError: No module named cgtypes), I edited the line in the transforms.py from
from cgtypes import *
to
from cgkit.cgtypes import *

After the modification, new problem emerged. The window showed up and then closed, with the eorror message given in the terminal:
freeglut ERROR: Function called without first calling 'glutInit'.

Then I found the page talking about this issue. So what I had to do was to find somewhere to put the glutInit function call. I tested for several times but totally had no idea where to add the glutInit, then I noticed the keyword in the error message: Function . It took me to the right location of the code to add a line as follows:
glutInit(argc, argv)
glutSolidCube(1)

It didn't work and threw back a name error:
NameError: global name 'argc' is not defined

I thought there might be no argument for this function call in the code, so I deleted the argc and argv to make the glutInit be called as the following:
glutInit()
glutSolidCube(1)

Bingo! Although I am still not sure whether the transforms.py runs properly, at least the window showed up with several moving cubes inside.

By far, the problem to run the transforms.py is solved. However, there is still an example code named vehicle.py cannot be run properly in my system. I have to do other works. Maybe I will come back to find out the solution for the vehicle.py.

No comments:

Post a Comment