Skip to content

Commit 81defc4

Browse files
Update scripts for matplotplusplus (#89)
* Update scripts for matplotplusplus * better case study results generated
1 parent 9b4f87b commit 81defc4

File tree

110 files changed

+6418
-8471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+6418
-8471
lines changed

CMakeLists.txt

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,43 @@ option(CDDP_CPP_CASADI "Whether to use CasADi" OFF)
3838
option(CDDP_CPP_ACADO "Whether to use Acado" OFF)
3939

4040
# Gurobi Configuration
41+
# If you want to install Gurobi, please follow the instructions at:
42+
# https://support.gurobi.com/hc/en-us/articles/4534161999889-How-do-I-install-Gurobi-Optimizer
4143
option(CDDP_CPP_GUROBI "Whether to use Gurobi solver." OFF)
4244
option(GUROBI_ROOT "Path to Gurobi installation" "")
43-
set(GUROBI_ROOT $ENV{HOME}/.local/lib/gurobi1103/linux64)
45+
set(GUROBI_ROOT /usr/local/lib/gurobi1201/linux64) # FIXME: Change this to your local gurobi installation directory
4446

4547
# LibTorch Configuration
48+
# If you want to install LibTorch, please follow the instructions at:
49+
# https://pytorch.org/
50+
# $ sudo cp -r libtorch /usr/local/lib/
4651
option(CDDP_CPP_TORCH "Whether to use LibTorch" OFF)
4752
option(CDDP_CPP_TORCH_GPU "Whether to use GPU support in LibTorch" OFF)
48-
set(LIBTORCH_DIR $ENV{HOME}/.local/lib/libtorch CACHE PATH "Path to local LibTorch installation") # FIXME: Change this to your local LibTorch installation directory
49-
50-
# Python Configuration
51-
set(Python_EXECUTABLE /usr/bin/python3.10) # Or the path to your desired Python interpreter
52-
execute_process( # Find the NumPy include directory
53-
COMMAND "${Python_EXECUTABLE}" -c "import numpy; print(numpy.get_include())"
54-
OUTPUT_VARIABLE NUMPY_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE
55-
)
53+
set(LIBTORCH_DIR /usr/local/lib/libtorch CACHE PATH "Path to local LibTorch installation") # FIXME: Change this to your local LibTorch installation directory
5654

5755
# Find packages
5856
find_package(Eigen3 REQUIRED)
59-
find_package(Python3 3.10 EXACT COMPONENTS Interpreter Development NumPy REQUIRED)
6057

6158
if (CDDP_CPP_CASADI)
6259
# Assuming that CasADi is installed in /usr/local/include/casadi by:
63-
# sudo apt install gfortran liblapack-dev pkg-config --install-recommends
64-
# sudo apt install swig
65-
# cd
66-
# git clone https://github.com/casadi/casadi.git -b main
67-
# cd casadi
68-
# mkdir build
69-
# cd build
70-
# cmake -DWITH_PYTHON=ON -DWITH_IPOPT=ON -DWITH_OPENMP=ON -DWITH_THREAD=ON ..
71-
# make
72-
# sudo make install
73-
# echo "export LD_LIBRARY_PATH=/home/<path_to_casadi>/casadi/build/lib:$LD_LIBRARY_PATH" >> ~/.bashrc && source ~/.bashrc
60+
# https://github.com/casadi/casadi/wiki/InstallationLinux
61+
# $ echo "export LD_LIBRARY_PATH=/home/<path_to_casadi>/casadi/build/lib:$LD_LIBRARY_PATH" >> ~/.bashrc && source ~/.bashrc
7462

7563
find_package(casadi REQUIRED)
76-
set(CASADI_INCLUDE_DIR /$ENV{HOME}/local/include/casadi)
64+
set(CASADI_INCLUDE_DIR /usr/local/include/casadi)
7765
find_library(CASADI_LIBRARY NAMES casadi HINTS ${CASADI_INCLUDE_DIR}/../lib $ENV{CASADI_PREFIX}/lib)
7866
set(CASADI_LIBRARIES ${CASADI_LIBRARIES} ${CASADI_LIBRARY})
67+
if (NOT CASADI_LIBRARIES)
68+
message(FATAL_ERROR "CasADi library not found. Please set CASADI_PREFIX.")
69+
else()
70+
message(STATUS "Found CasADi: ${CASADI_LIBRARIES}")
71+
endif()
7972
endif()
8073

8174
if (CDDP_CPP_ACADO)
8275
# Assuming that Acado is installed by: https://acado.github.io/install_linux.html
83-
set(ACADO_DIR $ENV{HOME}/github/ACADOtoolkit)
76+
set(ACADO_DIR $ENV{HOME}/github/ACADOtoolkit) # FIXME: Change this to your local Acado installation directory
77+
8478
# Include ACADO header files
8579
include_directories(${ACADO_DIR})
8680
include_directories(${ACADO_DIR}/acado)
@@ -89,6 +83,16 @@ endif()
8983
# Enable FetchContent for downloading dependencies
9084
include(FetchContent)
9185

86+
# Matplotplusplus
87+
FetchContent_Declare(matplotplusplus
88+
GIT_REPOSITORY https://github.com/alandefreitas/matplotplusplus
89+
GIT_TAG origin/master) # or whatever tag you want
90+
FetchContent_GetProperties(matplotplusplus)
91+
if(NOT matplotplusplus_POPULATED)
92+
FetchContent_Populate(matplotplusplus)
93+
add_subdirectory(${matplotplusplus_SOURCE_DIR} ${matplotplusplus_BINARY_DIR} EXCLUDE_FROM_ALL)
94+
endif()
95+
9296
# Googletest
9397
if (CDDP_CPP_BUILD_TESTS)
9498
enable_testing()
@@ -203,8 +207,6 @@ FetchContent_GetProperties(osqp-cpp)
203207
# Include directories
204208
include_directories(
205209
${CMAKE_CURRENT_SOURCE_DIR}/include
206-
${Python3_INCLUDE_DIRS}
207-
${NUMPY_INCLUDE_DIR}
208210
)
209211

210212
# Add your library
@@ -251,9 +253,7 @@ add_library(${PROJECT_NAME}
251253

252254
target_link_libraries(${PROJECT_NAME}
253255
Eigen3::Eigen
254-
Python3::Python
255-
Python3::Module
256-
Python3::NumPy
256+
matplot
257257
osqp-cpp
258258
)
259259

@@ -304,7 +304,8 @@ if (CDDP_CPP_GUROBI)
304304

305305
include_directories(${GUROBI_INCLUDE_DIR})
306306
target_link_libraries(${PROJECT_NAME} ${GUROBI_LIBRARIES} gurobi_c++
307-
gurobi110)
307+
gurobi120) # FIXME: Change this to your local gurobi installation
308+
message(STATUS "Successfully linked Gurobi version 120.")
308309
else()
309310
message(FATAL_ERROR "Could not find Gurobi. Please set GUROBI_ROOT.")
310311
endif()
@@ -321,6 +322,7 @@ add_subdirectory(examples)
321322
# Cmake compile commmand:
322323
# $ mkdir build
323324
# $ cd build
324-
# $ cmake -DCDDP_CPP_GUROBI=ON -DCDDP_CPP_BUILD_TESTS=ON -DGUROBI_ROOT=/home/tom/.local/lib/gurobi1103/linux64 -DCDDP_CPP_TORCH=ON -DCDDP_CPP_TORCH_GPU=ON -DLIBTORCH_DIR=/home/tom/.local/lib/libtorch ..
325+
# $ cmake -DCDDP_CPP_BUILD_TESTS=ON -DCDDP_CPP_TORCH=ON -DCDDP_CPP_TORCH_GPU=ON -DLIBTORCH_DIR=/usr/local/lib/libtorch -DCDDP_CPP_SQP=ON -DCDDP_CPP_GUROBI=ON -DGUROBI_ROOT=/usr/local/lib/gurobi1201/linux64 -DCDDP_CPP_CASADI=ON -DCDDP_CPP_ACADO=ON ..
325326
# $ make -j4
326327
# $ make test
328+

Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-ins
1212
libjpeg-dev \
1313
libpng-dev \
1414
libeigen3-dev \
15-
python3 \
16-
python3-dev \
17-
python3-numpy && \
1815
rm -rf /var/lib/apt/lists/*
1916

2017
# Install Cuda Toolkit

README.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ Car model with limited velocity and steering control:
8383
./examples/cddp_car // after building
8484
```
8585

86-
<img src="results/tests/car_motion.gif" width="300" alt="Car Model CDDP">
86+
<img src="results/tests/car_parking.gif" width="300" alt="Car Model CDDP">
87+
88+
```bash
89+
./examples/cddp_car_ipddp // after building
90+
```
91+
92+
<img src="results/tests/car_parking_ipddp.gif" width="300" alt="Car Model CDDP">
8793

8894
### Pendulum
8995

@@ -105,17 +111,36 @@ Cartpole with cart control:
105111
```
106112

107113
<img src="results/tests/cartpole.gif" width="300" alt="Cartpole CDDP">
114+
<img src="results/tests/cartpole_results.png" width="300" alt="Cartpole CDDP">
115+
108116

109117
### Quadrotor
110118

111119
Quadrotor with thrust control:
112120

113121
```bash
114-
./examples/cddp_quadrotor // after building
122+
./examples/cddp_quadrotor_point // after building
115123
```
116124

117125
<img src="results/tests/quadrotor.gif" width="300" alt="Quadrotor CDDP">
118126

127+
```bash
128+
./examples/cddp_quadrotor_circle // after building
129+
```
130+
131+
<img src="results/tests/quadrotor_circle.gif" width="300" alt="Quadrotor CDDP">
132+
133+
134+
```bash
135+
./examples/cddp_quadrotor_figure_eight_horizontal // after building
136+
```
137+
<img src="results/tests/quadrotor_figure_eight_horizontal.gif" width="300" alt="Quadrotor CDDP">
138+
139+
```bash
140+
./examples/cddp_quadrotor_figure_eight_vertical // after building
141+
```
142+
<img src="results/tests/quadrotor_figure_eight_vertical.gif" width="300" alt="Quadrotor CDDP">
143+
119144
### Manipulator
120145

121146
Manipulator with joint torque control:
@@ -140,14 +165,15 @@ sudo apt-get install libeigen3-dev # For Ubuntu
140165
brew install eigen # For macOS
141166
```
142167

143-
* [Matplotlib](https://matplotlib.org/) (Plotting Library in Python)
168+
* [gnuplot](http://www.gnuplot.info/) (Plotting Library)
144169
```bash
145-
pip install matplotlib
170+
sudo apt-get install gnuplot # For Ubuntu
171+
brew install gnuplot # For macOS
146172
```
147-
148-
* [numpy](https://numpy.org/) (Numerical Library in Python)
173+
* [imagemagick](https://imagemagick.org/) (Image Processing Library)
149174
```bash
150-
pip install numpy
175+
sudo apt-get install imagemagick # For Ubuntu
176+
brew install imagemagick # For macOS
151177
```
152178

153179
Although the library automatically finds and installs the following dependencies via [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html), if you do not have ones, here is how you can install on your own.
@@ -187,7 +213,7 @@ This project uses the following open-source libraries:
187213

188214
* [OSQP](https://github.com/google/osqp-cpp) (Apache License 2.0)
189215
* [osqp-cpp](https://github.com/google/osqp-cpp) (Apache License 2.0)
190-
* [matplotlibcpp](https://github.com/lava/matplotlib-cpp) (MIT License)
216+
* [matplotplusplus](https://github.com/alandefreitas/matplotplusplus) (MIT License)
191217
* [libtorch](https://github.com/pytorch/pytorch) (BSD 3-Clause License)
192218

193219
## Citing
@@ -201,6 +227,7 @@ This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENS
201227
* add state constraint handling
202228
* add initial guess functionality based on path planner solution
203229
* add automatic differentiation
230+
* add second-order derivative handling
204231
* add nonlinear objective and constraint handling
205232
* improve parallelization
206233
* improve boxqp

examples/CMakeLists.txt

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,32 @@ target_link_libraries(cddp_car_ipddp cddp)
2525
add_executable(cddp_cartpole cddp_cartpole.cpp)
2626
target_link_libraries(cddp_cartpole cddp)
2727

28-
add_executable(cddp_dubins_car cddp_dubins_car.cpp)
29-
target_link_libraries(cddp_dubins_car cddp)
28+
add_executable(cddp_hcw cddp_hcw.cpp)
29+
target_link_libraries(cddp_hcw cddp)
30+
31+
add_executable(cddp_lti_system cddp_lti_system.cpp)
32+
target_link_libraries(cddp_lti_system cddp)
33+
34+
add_executable(cddp_manipulator cddp_manipulator.cpp)
35+
target_link_libraries(cddp_manipulator cddp)
36+
37+
add_executable(cddp_pendulum cddp_pendulum.cpp)
38+
target_link_libraries(cddp_pendulum cddp)
39+
40+
add_executable(cddp_quadrotor_circle cddp_quadrotor_circle.cpp)
41+
target_link_libraries(cddp_quadrotor_circle cddp)
42+
43+
add_executable(cddp_quadrotor_figure_eight_horizontal cddp_quadrotor_figure_eight_horizontal.cpp)
44+
target_link_libraries(cddp_quadrotor_figure_eight_horizontal cddp)
45+
46+
add_executable(cddp_quadrotor_figure_eight_vertical cddp_quadrotor_figure_eight_vertical.cpp)
47+
target_link_libraries(cddp_quadrotor_figure_eight_vertical cddp)
48+
49+
add_executable(cddp_quadrotor_point cddp_quadrotor_point.cpp)
50+
target_link_libraries(cddp_quadrotor_point cddp)
51+
52+
# # add_executable(cddp_quadrotor_circle_safe cddp_quadrotor_circle_safe.cpp)
53+
# # target_link_libraries(cddp_quadrotor_circle_safe cddp)
3054

3155
add_executable(cddp_unicycle cddp_unicycle.cpp)
3256
target_link_libraries(cddp_unicycle cddp)
@@ -40,23 +64,11 @@ target_link_libraries(cddp_unicycle_safe_ipddp cddp)
4064
add_executable(cddp_unicycle_safe_ipddp_v2 cddp_unicycle_safe_ipddp_v2.cpp)
4165
target_link_libraries(cddp_unicycle_safe_ipddp_v2 cddp)
4266

43-
add_executable(cddp_manipulator cddp_manipulator.cpp)
44-
target_link_libraries(cddp_manipulator cddp)
45-
46-
add_executable(cddp_lti_system cddp_lti_system.cpp)
47-
target_link_libraries(cddp_lti_system cddp)
67+
add_executable(cddp_unicycle_safe_comparison cddp_unicycle_safe_comparison.cpp)
68+
target_link_libraries(cddp_unicycle_safe_comparison cddp)
4869

49-
add_executable(cddp_pendulum cddp_pendulum.cpp)
50-
target_link_libraries(cddp_pendulum cddp)
51-
52-
add_executable(cddp_quadrotor cddp_quadrotor.cpp)
53-
target_link_libraries(cddp_quadrotor cddp)
54-
55-
add_executable(cddp_hcw cddp_hcw.cpp)
56-
target_link_libraries(cddp_hcw cddp)
57-
58-
add_executable(mpc_hcw mpc_hcw.cpp)
59-
target_link_libraries(mpc_hcw cddp)
70+
# add_executable(mpc_hcw mpc_hcw.cpp)
71+
# target_link_libraries(mpc_hcw cddp)
6072

6173
# Ipopt examples
6274
if (CDDP_CPP_CASADI)
@@ -79,12 +91,6 @@ endif()
7991
if (CDDP_CPP_ACADO)
8092
add_executable(acado_car acado_car.cpp)
8193
target_link_libraries(acado_car cddp)
82-
83-
# add_executable(acado_unicycle acado_unicycle.cpp)
84-
# target_link_libraries(acado_unicycle cddp)
85-
86-
# add_executable(acado_cartpole acado_cartpole.cpp)
87-
# target_link_libraries(acado_cartpole cddp)
8894
endif()
8995

9096
# Neural dynamics examples

0 commit comments

Comments
 (0)