Closed hmartiro closed 11 years ago
Had some success with ctypes, even though it is supposed to be used with C and not C++. Just adding the line
#define PYTHON_EXPORT extern "C"
and declaring certain functions with it makes it possible to call them directly from Python with zero overhead. Stuff is successfully printed out using printf.
However, passing arguments and getting return values is not figured out yet. Also, I'll have to plug in the robot and try it to see if it's actually working.
Got int, string, and float arguments working, and int/float return values. This should be all we need to port most of the code to Python. We just need to make sure that the actual robot works through this method (it should), and that we can handle the IPM mode, because that is the most complicated part.
Got mostly everything working in Python, with pygame for key events. Stripped down the C++ library to only include wrappers for the EposCmd functions to avoid pointers and annoying C stuff. Created libxjus.so, which contains these functions and nothing else (no trajectory generation, logic, etc).
Then, import the .so into python using ctypes. Create a pygame window which captures key events, and have a while loop with an FPS maintained by pygame. Got standing/sitting to work with spacebar, and IPM mostly working (my trajectory functions are still not right in Python).
It's safe to say we can forget about ncurses completely. We won't need to programming in Eclipse or compile anything for the most part, except to update libxjus.so when needed. The python setup is wayyyy better.
Fixed trajectory functions, IPM is now working as expected.
Uploaded the code. The source files for libxjus.so are in EPOS/linux-library/libxjus
and the python script is EPOS/linux-library/python/xJus.py
.
This looks pretty cool but I have some questions for you, could be talk tonight or tomorrow late afternoon?
I'm game after dinner
Notes for configuring Python:
sudo apt-get install python-pip
to get the standard Python package installer. To install a package (numpy for example), use pip install numpy
.sudo apt-get install python-pygame
to get pygame. You could just do pip install pygame
, but pygame also has some non-python dependencies which the first command installs as well.ctypes
is a built-in Python package, no install required.Attempting to run the Python program on my 64b machine, encountering ELFCLASS32 errors. Updating my library using the following forum
idk what the forum is talking about, but there's a good chance you can solve this by installing 32-bit python using virtualenv. I can help you w/ that if needed
On Mon, Mar 4, 2013 at 10:45 PM, PayneTrain notifications@github.comwrote:
Attempting to run the Python program on my 64b machine, encountering ELFCLASS32 errors. Updating my library using the following forumhttps://bugs.launchpad.net/ubuntu/+source/ia32-libs/+bug/1016294
— Reply to this email directly or view it on GitHubhttps://github.com/hmartiro/project-thesis/issues/73#issuecomment-14422003 .
Basically I installed sudo apt-get install ia32-libs
but it didn't work, so let me look at virtualenv now
Installed a fresh copy of 32b Ubuntu! Cloning the repo now....
I get the following error when calling python xJus.py
:
`cpayne@ubuntu:~/project-thesis/EPOS/linux-library/python$ python xJus.py
Traceback (most recent call last):
File "xJus.py", line 17, in <module>
xjus = CDLL('/home/cpayne/project-thesis/EPOS/linux-library/definition-files/libxjus.so')
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libEposCmd.so: cannot open shared object file: No such file or directory`
Why would the libxjus.so library be looking for libEposCmd.so - Isn't it compiled with EposCmd only once so it doesn't need to be accessed again?
maybe libxjus was compiled with a hard link to libEposCmd on my system. you might have to create an eclipse project and compile your own libxjus from the two source files in the repo. otherwise, make sure libEpos is in the LD path
On Tue, Mar 5, 2013 at 8:35 PM, PayneTrain notifications@github.com wrote:
I get the following error when calling python xJus.py :
cpayne@ubuntu:~/project-thesis/EPOS/linux-library/python$ python xJus.py Traceback (most recent call last): File "xJus.py", line 17, in
xjus = CDLL('/home/cpayne/project-thesis/EPOS/linux-library/definition-files/libxjus.so') File "/usr/lib/python2.7/ctypes/init.py", line 365, in init self._handle = _dlopen(self._name, mode) OSError: libEposCmd.so: cannot open shared object file: No such file or directory Why would the libxjus.so library be looking for libEposCmd.so - Isn't it compiled with EposCmd only once so it doesn't need to be accessed again?
— Reply to this email directly or view it on GitHubhttps://github.com/hmartiro/project-thesis/issues/73#issuecomment-14477220 .
Good call on LD, changed it to the defintion-files on github and it works now! Will test functionality tomorrow in the lab when I'm wiih Jr.
Closing this because python works
Options