Jaeyoung-Lim / px4-mpc

MPC implementation using acados integrated with with PX4 on ROS2
BSD 3-Clause "New" or "Revised" License
42 stars 8 forks source link

qpOASES linking issue #12

Closed TomJanssen00 closed 5 months ago

TomJanssen00 commented 9 months ago

When running

roslaunch px4_mpc test_multirotor_rate_ocp.launch

I get the following error message

Traceback (most recent call last):
  File "/home/tom/workspaces/UAV_ws/src/px4-mpc/px4_mpc/nodes/test_multirotor_rate_ocp.py", line 54, in <module>
    main()
  File "/home/tom/workspaces/UAV_ws/src/px4-mpc/px4_mpc/nodes/test_multirotor_rate_ocp.py", line 45, in main
    mpc_controller = MultirotorRateMPC(model)
  File "/home/tom/workspaces/UAV_ws/src/px4-mpc/px4_mpc/src/px4_mpc/controllers/multirotor_rate_mpc.py", line 47, in __init__
    self.ocp_solver, self.integrator = self.setup(self.x0, self.N , self.Tf)
  File "/home/tom/workspaces/UAV_ws/src/px4-mpc/px4_mpc/src/px4_mpc/controllers/multirotor_rate_mpc.py", line 120, in setup
    ocp_solver = AcadosOcpSolver(ocp, json_file = 'acados_ocp.json')
  File "/home/tom/PythonPackages/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 451, in __init__
    self.__acados_lib = DllLoader(libacados_filepath)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libqpOASES_e.so.3.1: cannot open shared object file: No such file or directory
[mpc_quadrotor-2] process has died [pid 3430, exit code 1, cmd /home/tom/workspaces/UAV_ws/src/px4-mpc/px4_mpc/nodes/test_multirotor_rate_ocp.py __name:=mpc_quadrotor __log:=/home/tom/.ros/log/1d080fe4-cf4a-11ee-a3c6-0f3f0f39368d/mpc_quadrotor-2.log].
log file: /home/tom/.ros/log/1d080fe4-cf4a-11ee-a3c6-0f3f0f39368d/mpc_quadrotor-2*.log

This error (OSError:...) also appears when I run minimal_example_ocp.py from acados/examples/acados_python/getting_started:

Traceback (most recent call last):
  File "minimal_example_ocp.py", line 104, in <module>
    main()
  File "minimal_example_ocp.py", line 83, in main
    ocp_solver = AcadosOcpSolver(ocp, json_file = 'acados_ocp.json')
  File "/home/tom/PythonPackages/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 451, in __init__
    self.__acados_lib = DllLoader(libacados_filepath)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libqpOASES_e.so.3.1: cannot open shared object file: No such file or directory

I have installed qpOASES using this manual. The example script as described in chapter 2.1, point 5 seems to be working correctly.

Any idea how I can fix this problem?

Jaeyoung-Lim commented 9 months ago

@TomJanssen00 How did you install acados? I did not have the need to install qpoases separately.

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim First I installed acados using https://docs.acados.org/installation/index.html using cmake

Then installed the python interface using: https://docs.acados.org/python_interface/index.html

Jaeyoung-Lim commented 9 months ago

@TomJanssen00 Could you share the result of

cmake -DACADOS_WITH_QPOASES=ON ..

?

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim here you go

-- Build type is Release
-- ACADOS_WITH_OPENMP: OFF
-- Using linear algebra: HIGH_PERFORMANCE
-- Using matrix format: PANELMAJ
-- Using external BLAS: 0
-- Testing target X64_INTEL_HASWELL: assembly compilation [success]
-- Testing target X64_INTEL_HASWELL: assembly run [success]
-- Testing target X64_INTEL_HASWELL: intrinsic compilation [success]
-- Testing target X64_INTEL_HASWELL: intrinsic run [success]
-- Detected target X64_INTEL_HASWELL
-- Using BLASFEO path: 
-- Installation directory: /home/tom/PythonPackages/acados
--  
-- Target: BLASFEO is X64_AUTOMATIC, HPIPM is X64_AUTOMATIC
-- Linear algebra: HIGH_PERFORMANCE
-- Matlab MEX (OFF)
-- Octave MEX (OFF)
-- Octave Templates ()
-- System name:version Linux:5.15.0-91-generic
-- Build type is Release
-- Installation directory is /home/tom/PythonPackages/acados
-- OpenMP parallelization is OFF
--  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tom/PythonPackages/acados/build
Jaeyoung-Lim commented 9 months ago

@TomJanssen00 It is likely that the problem is in this step in the installation instruction.

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<acados_root>/lib"
export ACADOS_SOURCE_DIR="<acados_root>"

libqpOASES_e.so exists in the lib folder on my system.

~/dev/acados/lib$ ls
libacados.so   libhpipm.so      libqpOASES_e.so.3.1
libblasfeo.so  libqpOASES_e.so  link_libs.json

Could you check if the library files exist there?

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim It seems that I have the same output there:

~/PythonPackages/acados/lib$ ls
libacados.so   libhpipm.so      libqpOASES_e.so.3.1
libblasfeo.so  libqpOASES_e.so  link_libs.json
Jaeyoung-Lim commented 9 months ago

@TomJanssen00 Right, but then if you have configured LD_LIBRARY_PATH and ACADOS_SOURCE_DIR, it should be linked properly. I think the problem might be that you installed qpoases separately.

Can you echo LD_LIBRARY_PATH and ACADOS_SOURCE_DIR ?

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim It returns as follows

$ echo $LD_LIBRARY_PATH
/opt/ros/noetic/lib
$ echo $ACADOS_SOURCE_DIR
/home/tom/PythonPackages/acados/

ACADOS_SOURCE_DIR somehow did not return anything initially, so I added the path as described in the instruction by

export ACADOS_SOURCE_DIR=~/PythonPackages/acados/

But I still get the same error

Jaeyoung-Lim commented 9 months ago
$ echo $LD_LIBRARY_PATH
/opt/ros/noetic/lib

@TomJanssen00 This explains the problem?

The installation instruction says you need to map

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<acados_root>/lib"
TomJanssen00 commented 9 months ago

@Jaeyoung-Lim I ran

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"<acados_root>/lib"

Now it returns

$ echo $LD_LIBRARY_PATH 
/opt/ros/noetic/lib:~/PythonPackages/acados/lib

That should be good right?

When I try to run an example script now from acados_python I run into a different issue that I encountered yesterday as well, but resolved at some point. It had to do with setting up Tera renderer. I am looking into that now.

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim Now I run into the following issue

acados_solver_pendulum_ode.c:37:10: fatal error: acados_c/ocp_nlp_interface.h: No such file or directory
   37 | #include "acados_c/ocp_nlp_interface.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [<builtin>: acados_solver_pendulum_ode.o] Error 1
Traceback (most recent call last):
  File "minimal_example_ocp.py", line 104, in <module>
    main()
  File "minimal_example_ocp.py", line 83, in main
    ocp_solver = AcadosOcpSolver(ocp, json_file = 'acados_ocp.json')
  File "/home/tom/PythonPackages/acados/interfaces/acados_template/acados_template/acados_ocp_solver.py", line 451, in __init__
    self.__acados_lib = DllLoader(libacados_filepath)
  File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: ~/PythonPackages/acados/lib/../lib/libacados.so: cannot open shared object file: No such file or directory

However, acados_c/ocp_nlp_interface.h seems to exist in acados/interfaces. Do you know how to fix this?

Btw. I did not make a virtualenv. Do you think this could affect it?

Jaeyoung-Lim commented 9 months ago

@TomJanssen00 Are you sure you have ACADOS_SOURCE_DIR configured properly?

Btw. I did not make a virtualenv. Do you think this could affect it?

I also didn't configure a virtualenv. It should work without.

In the log:

OSError: ~/PythonPackages/acados/lib/../lib/libacados.so: cannot open shared object file: No such file or directory

You can check if this file exists. and if not how you can create it.(by building acados I presume?)

TomJanssen00 commented 9 months ago

@Jaeyoung-Lim I reconfigured ACADOS_SOURCE_DIR and LD_LIBRARY_PATH and replaced ~/PythonPa... with /home/tom/PythonPa... and now it works... so I think this fixed the issue.

Your code is now also working! (sitl not yet as I have not installed px4 yet)

Thanks a lot for helping me fix the issue!

Jaeyoung-Lim commented 9 months ago

@TomJanssen00 Awesome!