robotology / osqp-eigen

Simple Eigen-C++ wrapper for OSQP library
https://robotology.github.io/osqp-eigen/
BSD 3-Clause "New" or "Revised" License
395 stars 118 forks source link

ROS catkin_make #129

Closed JulienRineau closed 1 year ago

JulienRineau commented 1 year ago

Hi I'm trying to make this repo work without docker. But even after installing osqp-eigen (from source and with conda) I obtain this error:

In file included from /usr/include/OsqpEigen/OsqpEigen.h:10,
                 from /home/parallels/capstone/workspace/src/a1_cpp/src/test/test_rotation.cpp:8:
/usr/include/OsqpEigen/Constants.hpp:12:10: fatal error: osqp.h: No such file or directory
   12 | #include <osqp.h>
      |          ^~~~~~~~
compilation terminated.
make[2]: *** [a1_cpp/CMakeFiles/test_rotation.dir/build.make:63: a1_cpp/CMakeFiles/test_rotation.dir/src/test/test_rotation.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2868: a1_cpp/CMakeFiles/test_rotation.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Invoking "make -j4 -l4" failed

Does someone have an idea on how to solve this ?

S-Dafarra commented 1 year ago

Hi @JulienRineau, thanks for the issue.

Could you please post here the steps you are following? That could give us a possibility to reproduce the issue.

JulienRineau commented 1 year ago

Thank you @S-Dafarra. Here is what I have done:

  1. Create a ros workspace and copy past the a1_cpp package in src
  2. Try with conda: conda install -c conda-forge osqp-eigen
  3. Try to build my ros workspace with catkin_make but obtain the above error
  4. Try to install osqp-eigen from source: git clone https://github.com/robotology/osqp-eigen.git in the folder containing my ros workspace
  5. cd osqp-eigen
  6. mkdir build
  7. cd build
  8. cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ../ (I'm not sure of this part)
  9. make
  10. sudo make install
  11. OsqpEigen_DIR=/path/to/osqp-eigen/ ('m not sure of this part)
  12. Obtain the above error

I'm using ros Noetic with Ubuntu 20.04

traversaro commented 1 year ago

Hello @JulienRineau, how did you installed the ROS installation with which you created the ROS workspace? If you did it with apt (the default and official installation method), then in general you can't install and use conda(-forge) packages. apt and conda effectively are completly separated distributions of C++ libraries, that even have different libstdc++ version, so you can't mix apt and conda packages. If you want to use osqp-eigen from conda-forge, you need to install ROS as well with conda, via https://robostack.github.io/ . Furthermore, never install in /usr, that location is reserved for apt package. To recover your system I suggest to:

A. Make sure that you do not have any conda environment active when you work with ROS/apt, ensuring that you are not activating any in the .bashrc or similar, and that even your base environment is not active (i.e. call conda config --set auto_activate_base true once). This should revert any problem introduced by step 2. B. Uninstall the osqp-eigen that you installed in /usr, by going in the build dir and running `sudo make uninstall . This should revert any problem introduced by step 8.

At this point, I think you can start again, probably installing osqp-eigen by source either in a user directory. From the problem you have, probably it is important to check:

traversaro commented 1 year ago

By the way, now that I think of @wxmerkt in https://github.com/robotology/osqp-eigen/pull/109 added a package.xml in osqp-eigen for catkin compatibility, so perhaps if he has time he may have some hints on how to compile and install osqp-eigen directly via catkin (thanks in advance, my experience with ROS build tools is mostly limited to colcon).

Based on https://answers.ros.org/question/306181/how-to-build-non-catkin-package-in-catkin-workspace/, I guess (never tested) that you can simply clone it in the src directory of your workspace and use either catkin_make_isolated or catkin build.

wxmerkt commented 1 year ago

You can directly compile OSQP and osqp-eigen in a catkin workspace. To do so, clone OSQP from https://github.com/ori-drs/osqp (the only modifcation being an added package.xml) and osqp-eigen from this repository - directly into your catkin_ws/src. You can then compile with catkin build or catkin_make_isolated - but not catkin_make. I did not have to modify any environment variables - and it compiles the above repository just fine.

it appears that the osqp::osqp target that is linked to OsqpEigen::OsqpEigen does not get searched/its INTERFACE_INCLUDE_DIRECTORIES appended? Scratch that, this was due to a differently wrapped OSQP used by Anybotics

traversaro commented 1 year ago

Thanks a lot @wxmerkt !

JulienRineau commented 1 year ago

Thanks @wxmerkt and @traversaro for your help. Running catkin_make give me now another error. Have you ever encountered this ?

parallels@ubuntu-linux-20-04-desktop:~/capstone/workspace$ catkin_make_isolated
Base path: /home/parallels/capstone/workspace
Source space: /home/parallels/capstone/workspace/src
Build space: /home/parallels/capstone/workspace/build_isolated
Devel space: /home/parallels/capstone/workspace/devel_isolated
Install space: /home/parallels/capstone/workspace/install_isolated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~  traversing 13 packages in topological order:
~~  - a1_description
~~  - aliengo_description
~~  - b1_description
~~  - go1_description
~~  - laikago_description
~~  - osqp (plain cmake)
~~  - osqp-eigen (plain cmake)
~~  - unitree_legged_msgs
~~  - a1_cpp
~~  - unitree_controller
~~  - unitree_gazebo
~~  - unitree_legged_control
~~  - unitree_legged_real
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

==> Processing catkin package: 'a1_description'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/parallels/capstone/workspace/build_isolated/a1_description'
==> make -j4 -l4 in '/home/parallels/capstone/workspace/build_isolated/a1_description'
<== Finished processing package [1 of 13]: 'a1_description'

==> Processing catkin package: 'aliengo_description'
==> Building with env: '/home/parallels/capstone/workspace/devel_isolated/a1_description/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/parallels/capstone/workspace/build_isolated/aliengo_description'
==> make -j4 -l4 in '/home/parallels/capstone/workspace/build_isolated/aliengo_description'
<== Finished processing package [2 of 13]: 'aliengo_description'

==> Processing catkin package: 'b1_description'
==> Building with env: '/home/parallels/capstone/workspace/devel_isolated/aliengo_description/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/parallels/capstone/workspace/build_isolated/b1_description'
==> make -j4 -l4 in '/home/parallels/capstone/workspace/build_isolated/b1_description'
<== Finished processing package [3 of 13]: 'b1_description'

==> Processing catkin package: 'go1_description'
==> Building with env: '/home/parallels/capstone/workspace/devel_isolated/b1_description/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/parallels/capstone/workspace/build_isolated/go1_description'
==> make -j4 -l4 in '/home/parallels/capstone/workspace/build_isolated/go1_description'
<== Finished processing package [4 of 13]: 'go1_description'

==> Processing catkin package: 'laikago_description'
==> Building with env: '/home/parallels/capstone/workspace/devel_isolated/go1_description/env.sh'
Makefile exists, skipping explicit cmake invocation...
==> make cmake_check_build_system in '/home/parallels/capstone/workspace/build_isolated/laikago_description'
==> make -j4 -l4 in '/home/parallels/capstone/workspace/build_isolated/laikago_description'
<== Finished processing package [5 of 13]: 'laikago_description'

==> Processing plain cmake package: 'osqp'
==> Building with env: '/home/parallels/capstone/workspace/devel_isolated/laikago_description/env.sh'
==> cmake /home/parallels/capstone/workspace/src/osqp -DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/workspace/devel_isolated/osqp -G Unix Makefiles in '/home/parallels/capstone/workspace/build_isolated/osqp/devel'
-- We are on a Linux system
-- Embedded is OFF
-- Printing is ON
-- Profiling is ON
-- User interrupt is ON
-- Floats are OFF
-- Long integers (64bit) are ON
-- Code coverage is OFF
-- MKL Pardiso: ON
CMake Error at lin_sys/direct/qdldl/CMakeLists.txt:2 (add_subdirectory):
  The source directory

    /home/parallels/capstone/workspace/src/osqp/lin_sys/direct/qdldl/qdldl_sources

  does not contain a CMakeLists.txt file.

-- Configuring incomplete, errors occurred!
See also "/home/parallels/capstone/workspace/build_isolated/osqp/devel/CMakeFiles/CMakeOutput.log".
<== Failed to process package 'osqp': 
  Command '['/home/parallels/capstone/workspace/devel_isolated/laikago_description/env.sh', 'cmake', '/home/parallels/capstone/workspace/src/osqp', '-DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/workspace/devel_isolated/osqp', '-G', 'Unix Makefiles']' returned non-zero exit status 1.

Reproduce this error by running:
==> cd /home/parallels/capstone/workspace/build_isolated/osqp && /home/parallels/capstone/workspace/devel_isolated/laikago_description/env.sh cmake /home/parallels/capstone/workspace/src/osqp -DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/workspace/devel_isolated/osqp -G 'Unix Makefiles'

Command failed, exiting.
traversaro commented 1 year ago

I think you did not downloaded osqp with all its git submodules, see for example in https://osqp.org/docs/get_started/sources.html#build-the-binaries where osqp is downloaded with git clone --recursive .

JulienRineau commented 1 year ago

Thank you @traversaro! I think I am still missing something unfortunately. To be sure there is no issues due to my previous work I created a separated workspace. Here is what I've done

mkdir test_ws
cd test_ws
mkdir src
catkin_make

Move a1_cpp in src

cd src
git clone https://github.com/ori-drs/osqp.git --recursive
git clone https://github.com/robotology/osqp-eigen.git --recursive
cd ..
catkin_make_isolated

Here is what I obtain

parallels@ubuntu-linux-20-04-desktop:~/capstone/test_ws$ catkin_make_isolated
Base path: /home/parallels/capstone/test_ws
Source space: /home/parallels/capstone/test_ws/src
Build space: /home/parallels/capstone/test_ws/build_isolated
Devel space: /home/parallels/capstone/test_ws/devel_isolated
Install space: /home/parallels/capstone/test_ws/install_isolated
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~  traversing 3 packages in topological order:
~~  - a1_cpp
~~  - osqp (plain cmake)
~~  - osqp-eigen (plain cmake)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The packages or cmake arguments have changed, forcing cmake invocation

==> Processing catkin package: 'a1_cpp'
==> Creating build directory: 'build_isolated/a1_cpp'
==> cmake /home/parallels/capstone/test_ws/src/a1_cpp -DCATKIN_DEVEL_PREFIX=/home/parallels/capstone/test_ws/devel_isolated/a1_cpp -DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/test_ws/install_isolated -G Unix Makefiles in '/home/parallels/capstone/test_ws/build_isolated/a1_cpp'
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_PREFIX_PATH: 
-- Using CATKIN_DEVEL_PREFIX: /home/parallels/capstone/test_ws/devel_isolated/a1_cpp
-- Using CMAKE_PREFIX_PATH: /home/parallels/capstone/workspace/devel;/home/parallels/CS206_final/workspace/devel;/home/parallels/catkin_ws/devel;/opt/ros/noetic
-- This workspace overlays: /home/parallels/capstone/workspace/devel;/home/parallels/CS206_final/workspace/devel;/home/parallels/catkin_ws/devel;/opt/ros/noetic
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Found PY_em: /usr/lib/python3/dist-packages/em.py  
-- Using empy: /usr/lib/python3/dist-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/parallels/capstone/test_ws/build_isolated/a1_cpp/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python3 (found version "3.8.10") 
-- Found Threads: TRUE  
-- Using Python nosetests: /usr/bin/nosetests3
-- catkin 0.8.10
-- BUILD_SHARED_LIBS is on
CMake Error at CMakeLists.txt:39 (find_package):
  By not providing "FindOsqpEigen.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "OsqpEigen", but CMake did not find one.

  Could not find a package configuration file provided by "OsqpEigen" with
  any of the following names:

    OsqpEigenConfig.cmake
    osqpeigen-config.cmake

  Add the installation prefix of "OsqpEigen" to CMAKE_PREFIX_PATH or set
  "OsqpEigen_DIR" to a directory containing one of the above files.  If
  "OsqpEigen" provides a separate development package or SDK, be sure it has
  been installed.

-- Configuring incomplete, errors occurred!
See also "/home/parallels/capstone/test_ws/build_isolated/a1_cpp/CMakeFiles/CMakeOutput.log".
See also "/home/parallels/capstone/test_ws/build_isolated/a1_cpp/CMakeFiles/CMakeError.log".
<== Failed to process package 'a1_cpp': 
  Command '['cmake', '/home/parallels/capstone/test_ws/src/a1_cpp', '-DCATKIN_DEVEL_PREFIX=/home/parallels/capstone/test_ws/devel_isolated/a1_cpp', '-DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/test_ws/install_isolated', '-G', 'Unix Makefiles']' returned non-zero exit status 1.

Reproduce this error by running:
==> cd /home/parallels/capstone/test_ws/build_isolated/a1_cpp && cmake /home/parallels/capstone/test_ws/src/a1_cpp -DCATKIN_DEVEL_PREFIX=/home/parallels/capstone/test_ws/devel_isolated/a1_cpp -DCMAKE_INSTALL_PREFIX=/home/parallels/capstone/test_ws/install_isolated -G 'Unix Makefiles'

Command failed, exiting.

I can't find the two files OsqpEigenConfig.cmake and osqpeigen-config.cmake

Am I doing something wrong ?

S-Dafarra commented 1 year ago

At this point, I think it is an issue of a1_cpp that does not specify osqp-eigen as dependency: https://github.com/ShuoYangRobotics/A1-QP-MPC-Controller/blob/de07f355b93bee95151296d814fc47d3c1fb8349/src/a1_cpp/package.xml#L42-L50

It also includes osqp in a pretty weird way https://github.com/ShuoYangRobotics/A1-QP-MPC-Controller/blob/de07f355b93bee95151296d814fc47d3c1fb8349/src/a1_cpp/CMakeLists.txt#L38

wxmerkt commented 1 year ago

@JulienRineau I have a fork with the fixes needed to compile it here: https://github.com/wxmerkt/A1-QP-MPC-Controller - and yes it had to address the odd includes that @S-Dafarra mentioned

Note that we also use a different unitree_legged_sdk, but I didn't test that here. But the OsqpEigen code is fixed in the above repository

JulienRineau commented 1 year ago

Awesome. I still have issues with the a1_cpp and unitree_legged_sdk repo but everything concerning osqp-eigen has been solved.

I'll close this issue then.

Thank you @wxmerkt @S-Dafarra and @traversaro for your help

wxmerkt commented 1 year ago

You can try putting https://github.com/ori-drs/unitree_legged_sdk into your catkin workspace, it should compile. If not, also add <depend>unitree_legged_sdk</depend> to a1_cpp's package.xml. If this does not work, I'll circle back to your message

JulienRineau commented 1 year ago

Thanks a lot @wxmerkt. I take the liberty of asking more questions about this repo here because the issue is already closed. I ran your repo with Docker because it seems easier. However when trying to run the simulation with sudo roslaunch unitree_gazebo normal.launch rname:=a1 wname:=stairs_single I obtain [gazebo_gui-3] process has died And the log is: cat: /root/.ros/log/a8a1848a-76b4-11ed-bad4-a8a1596e44b4/gazebo_gui-3.log: Permission denied

This seems to be an issue related to launching a GUI with docker hower the repo already implemented all the requirements I found (e.g https://wiki.ros.org/docker/Tutorials/GUI)

Did you ever had this problem ?

wxmerkt commented 1 year ago

Hi @JulienRineau I haven't run the code in the repository or looked into it too deeply so cannot comment in too much detail. One reason this issue could happen is if your uid/gid inside the Docker is not the same as your username outside e.g. if you want to give access to the xhost. You can manually set the uid/gid of the user inside docker when building the image to equal the one of your user outside if that was the issue. But that may only be one cause of failure. Second, and this is only an observation, I am not sure why you need sudo for roslaunch. I am aware that Unitree in some cases does some unorthodox memory blocking/allocation that requires sudo (e.g. on the robot and for controlling robots rather than managing permissions more explicitly), but not sure why that would be the case here for Gazebo. Again, I haven't run or analysed the code in the linked repositories too closely, with my related experience only stemming from running experiments on the physical robot and packaging/build system fixes for the related libraries including Unitree's SDK