[ROS1] Install CasADi and use it in ROS1 package (c++)
CasADi is an open-source tool for nonlinear optimization and algorithmic differentiation.
In this post, I will present you how to install CasADi and use it in ROS1 package with c++ nodes. Also, since a type of quadratic programming solvers, qpOASES, is not automatically installed by just installing CasADi, I will also present you how to install qpOASES and use it with CasADi.
- Operating System: Ubuntu 20.04, 64 bits
- ROS version: noetic
Procedure
Step 1: Install development tools and libraries
Before installing qpOASES and CasADi, install the necessary development tools and libraries.
sudo apt-get update
sudo apt-get install -y build-essential cmake g++ python3-dev git
Step 2: Install CasADi from source
At first, download the CasADi repository from github as followss:
git clone https://github.com/casadi/casadi.git
cd casadi
Then, make a build folder and build CasADi at that folder.
mkdir build
cd build
cmake ..
make -j4
Finally, install CasADi.
sudo make install
Step 3: Add the following command lines on your package’s CMakeLists.txt
To add the dependency on CasADi in your ROS package, add the following command lines on their proper locations (They depend on your originally made CMakeLists.txt).
(omission)
...
set(CASADI_INCLUDE_DIRS /usr/local/include/casadi)
set(CASADI_LIBRARIES /usr/local/lib/libcasadi.so)
...
(syncopation)
...
include_directories( ${CASADI_INCLUDE_DIRS} )
...
(syncopation)
...
target_link_libraries(<your node name> ${catkin_LIBRARIES} ... ${CASADI_LIBRARIES})
...
(omission)
Then, add the casadi header fiie on your c++-coded node.
(Option) qpOASES addition process
To use the qpOASES, go back to your default installation location and execute the following commands on your terminal. (In my case, it was “Documents” folder.)
git clone https://github.com/coin-or/qpOASES.git
cd qpOASES
mkdir build
cd build
cmake ..
make -j4
sudo make install
Then, go back to your casadi build folder (<path/to/casadi/installation>/casadi/build, in my case, ~/Documents/casadi/build/), then execute the following commands:
cmake .. -DWITH_QPOASES=ON -DWITH_LAPACK=ON
make -j4
sudo make install
Reference
https://web.casadi.org/
https://github.com/coin-or/qpOASES
Leave a Comment
Your email address will not be published. Required fields are marked *