commaai/laika

Error in EKF_sym() class - C code generation and compilation probably missing?!

scud3r1a opened this issue · 2 comments

Within in the given Kalman filter example (Jupyter notebook), the following error occurs:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-2-744c422db1fc> in <module>
      3 from laika_repo.examples.kalman.gnss_kf import GNSSKalman
      4 from laika_repo.examples.kalman.kalman_helpers import run_car_ekf_offline, ObservationKind
----> 5 ekf = GNSSKalman()
      6 init_state = ekf.x
      7 init_state[:3] = est_pos

~/one/laika_repo/examples/kalman/gnss_kf.py in __init__(self, N, max_tracks)
     60     name = 'gnss'
     61     # init filter
---> 62     self.filter = EKF_sym(name, Q, x_initial, P_initial, self.dim_state, self.dim_state, maha_test_kinds=maha_test_kinds)
     63 
     64   @property

~/one/laika_repo/examples/kalman/ekf_sym.py in __init__(self, name, Q, x_initial, P_initial, dim_main, dim_main_err, N, dim_augment, dim_augment_err, maha_test_kinds)
    177     self.init_state(x_initial, P_initial, None)
    178 
--> 179     ffi, lib = wrap_compiled(name, EXTERNAL_PATH)
    180     kinds, self.feature_track_kinds = [], []
    181     for func in dir(lib):

~/one/laika_repo/examples/kalman/ffi_wrapper.py in wrap_compiled(name, directory)
     39 def wrap_compiled(name, directory):
     40   sys.path.append(directory)
---> 41   mod = __import__(name)
     42   return mod.ffi, mod.lib

ModuleNotFoundError: No module named 'gnss'

Even when I executed the code locally, without the Jupyter notebook but with a common Python script containing the same code, the error occurred. When going through the code, I found out that the EKF_sym object instantiates a filter object when instantiated. The filter relies on the EKF code written in C. This code is not manually written but assembled inside the gen_code function.

During the example, the compiled code is wrapped without existing since the code generation function, the code compiling function and the FFI wrapper are not called during the EKF_sym object instantiation (or before). Hence, the compiled C code with the name gnss cannot be found.

Since the code structure is not clear, I struggle with fixing this myself. Feel free to help me.
In my view, the error should occur in anybody's attempt to run the Kalman example.

Yes you understand correctly how it works. However it should still work without gnss.c, since the compile .so and .o files are included. I thought it tested that and it worked in a docker. It is possible something broke since.

Unfortunately this was done a while ago and we weren't ready to open source the kalman compilation code. We did now here:
https://github.com/commaai/openpilot/tree/master/selfdrive/locationd/kalman

Everything is there, including what is needed to recompile the gnss kalman filter. So if you really want to get it to work, you should be able to figure it out. I sadly don't have the time at the moment to clean up stuff here now. If you get it to work, PRs would be greatly appreciated.

Let me know if you have more questions.

Thanks for your quick response. Actually, I found that someone has already done so and integrated the latest Kalman filter version into the original Laika repo:
https://github.com/rwschubert/kalman-laika

So I think I was not the only one getting stuck with that error.
The referenced repo also uses Docker and tried it: works for me.
Thanks anyway!