Using the python wrapper for IMU pre-Integration

Issue #293 resolved
Y Simson created an issue

I had trouble activating the tests in python/gtsam_tests

I had to manually add to path the place of the sitepackage:

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/site-packages/gtsam

In addition I had to add

export PYTHONPATH=${PYTHONPATH}:/home/yonatan/gtsam/build/python/handwritten

Otherwise python could not find gtsampy.so

After solving these problems I ran into another problem.

When typing:

python ImuFactorExample.py

I get the following error:

 File "/usr/local/lib/python2.7/site-packages/gtsam_utils/plot.py", line 39, in plotPose3OnAxes
    xAxis = C + gRp[:, 0] * axisLength
TypeError: unsupported operand type(s) for +: 'Point3' and 'float'

C is Point3 type and gRp[:, 0] is numpy vector. There doesn't appear to be a conversion between the two.

Is this a genuine bug or a mistake in the way I compiled the python wrapper?

Comments (18)

  1. kpykc KPyKC

    Sorry if I am wrong, but I think it is related question.

    Also, it is not apparent for me:

    • how (if it is possible) to export gtsam.KeyVector as numpy array or arrays.

    For examlpe I would like to use gtsam python wrapper in Jupyter Notebook, print method unfortunately prints to terminal.

    So if it is already possible it would be nice to see how gtsam->numpy direction works.

  2. Ludwig Auer

    Hey all,

    in the past couple of days I tested the pull request with a new cython wrapper by @thduynguyen (thanks a lot for that!) and tried translating the IMUkittixample.m to python. I had a small issue with PreintegrationParams, which would throw me

    gtsam.PreintegrationParams(n_gravity)

    which would throw me the following type error

    gtsam.pyx in gtsam.PreintegratedRotationParams.__cinit__ (gtsam.cpp:326130)() TypeError: PreintegratedRotationParams construction failed!

    For now I just hardcoded n_gravity to np.array([0., 0., -9.81]) in gtsam.pyx.

    Other than that, translating IMU Kitti worked fine, and the example runs through, but I still need to do a direct comparison with the MATLAB output. Would be great to get in touch with others who are interested in using GTSAM through python, so let me know if you would like to try out the script.

    Best wishes,

    Ludwig

  3. Duy-Nguyen Ta

    @auerl Thanks for trying it out! I've just pushed a fix. Can you let me know if that fixes your problem?

    It was because PreintegratedRotationParams is the base class of PreintegrationParams, and the base class's cinit is automatically called by Cython with all parameters passed to the subclass, in this case, n_gravity. However, the base class doesn't have any constructor accepting a Vector, thus the error.

    Changing cinit to init seems to fix the problem. All the tests still pass, so I think it's ok.

    Thanks!

  4. Ludwig Auer

    Hi @thduynguyen, thanks much, that fixed the problem! I'll keep you posted about how the results compare to the ones obtained with the MATLAB version of it. Greets, Ludwig

  5. Y Simson reporter

    I tried the cython wrapper. There were a few problems in the tests. 3/13 failed:

    ====================================================================== ERROR: test_Pose3SLAMExample (unittest.loader.ModuleImportFailure)


    ImportError: Failed to import test module: test_Pose3SLAMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_Pose3SLAMExample.py", line 5, in <module> from gtsam.utils.circlePose3 import * ImportError: No module named utils.circlePose3

    ====================================================================== ERROR: test_VisualISAMExample (unittest.loader.ModuleImportFailure)


    ImportError: Failed to import test module: test_VisualISAMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_VisualISAMExample.py", line 4, in <module> import gtsam.utils.visual_data_generator as generator ImportError: No module named utils.visual_data_generator

    ====================================================================== ERROR: test_SFMExample (unittest.loader.ModuleImportFailure)


    ImportError: Failed to import test module: test_SFMExample Traceback (most recent call last): File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests module = self._get_module_from_name(name) File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name import(name) File "/home/ysimson/develop/gtsam_cython/cython/gtsam/tests/test_SFMExample.py", line 5, in <module> import gtsam.utils.visual_data_generator as generator ImportError: No module named utils.visual_data_generator

    cc: @thduynguyen

  6. Duy-Nguyen Ta

    @YontanSimson Thanks for trying it out! Please make sure you stay in your <GTSAM_CYTHON_INSTALL_PATH> folder (or above) when running the unittests. I get the same problem if I stay inside <GTSAM_CYTHON_INSTALL_PATH/gtsam>. "gtsam" is installed as a package inside your <GTSAM_CYTHON_INSTALL_PATH> folder, and "utils" is a sub_package inside gtsam. Also, I've recently made some changes on how the packages should be installed, so if you still have problems after pulling down the latest version, please let me know. Thanks!

  7. Lachlan Nicholson

    A solution to the original question about the Point3 to float conversion is to modify (in /usr/local/lib/python2.7/dist-packages/gtsam_utils/plot.py) line 36 to be:

    C = pose.translation().vector()

  8. Log in to comment