Skip to content

Commit

Permalink
get docker working, fix issue #85
Browse files Browse the repository at this point in the history
  • Loading branch information
alexliniger committed Jun 29, 2023
1 parent 792913c commit 99d87d3
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
build

.DS_Store
6 changes: 5 additions & 1 deletion C++/ADCodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ set(CMAKE_CXX_STANDARD_LIBRARIES -ldl)

include_directories("..")
#include_directories(.)
include_directories(../External/Eigen)

# Find the globally installed Eigen library
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
include_directories(../External/Json/include)

add_executable(ADCodeGen
Expand All @@ -16,4 +19,5 @@ add_executable(ADCodeGen
../Params/params.cpp
main.cpp)

target_link_libraries(ADCodeGen /usr/local/lib/libcppad_lib.so)
#target_link_libraries(ADCodeGen cppad_cg_RK4.so m)
4 changes: 2 additions & 2 deletions C++/ADCodeGen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ int main(void) {
std::unique_ptr<CppAD::cg::GenericModel<double>> model;
model = myLib->model("RK4");

Eigen::Vector<double,15> x;
Eigen::Matrix<double,15,1> x;
x.setZero();
x(3) = 10.0;
std::vector<double> xv(x.data(), x.data() + x.size());
Expand All @@ -50,7 +50,7 @@ int main(void) {
StateVector f = Eigen::Map<StateVector>((model_cont_dyn->ForwardZero(xv)).data());
std::cout << f << std::endl;

Eigen::Vector<double,NX> s;
Eigen::Matrix<double,NX,1> s;
s.setZero();
s(3) = 10.0;
s(5) = 1.0;
Expand Down
23 changes: 17 additions & 6 deletions C++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ cmake_minimum_required(VERSION 3.8)
project(MPCC)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_FLAGS "-O0")
set(CMAKE_CXX_STANDARD_LIBRARIES -ldl)
set(CMAKE_CXX_FLAGS "-O2")

include_directories(.)
include_directories(External/blasfeo/lib/include)
include_directories(External/hpipm/lib/include)
include_directories(/opt/blasfeo/include)
include_directories(/app/hpipm/include)
include_directories(External/matplotlib)
include_directories(External/Eigen)
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
include_directories(External/Json/include)

find_package(Python3 COMPONENTS Interpreter NumPy Development)

add_executable(MPCC
main.cpp
types.cpp
Expand All @@ -36,8 +40,15 @@ add_executable(MPCC
Plotting/plotting.cpp
Plotting/plotting.h)

find_package(Python3 COMPONENTS Interpreter NumPy Development)


message(STATUS "Python3_EXECUTABLE: ${Python3_EXECUTABLE}")
message(STATUS "Python3_INCLUDE_DIRS: ${Python3_INCLUDE_DIRS}")
message(STATUS "Python3_LIBRARIES: ${Python3_LIBRARIES}")

target_include_directories(MPCC PRIVATE ${Python3_INCLUDE_DIRS})
target_link_libraries(MPCC ${Python3_LIBRARIES})

target_link_libraries(MPCC ${CMAKE_SOURCE_DIR}/External/hpipm/lib/lib/libhpipm.a ${CMAKE_SOURCE_DIR}/External/blasfeo/lib/lib/libblasfeo.a m)

# target_link_libraries(MPCC ${CMAKE_SOURCE_DIR}/External/hpipm/lib/lib/libhpipm.a ${CMAKE_SOURCE_DIR}/External/blasfeo/lib/lib/libblasfeo.a m)
target_link_libraries(MPCC /app/hpipm/lib/libhpipm.a /opt/blasfeo/lib/libblasfeo.a m)
66 changes: 66 additions & 0 deletions C++/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Use the official Ubuntu 20.04 as the base image
FROM ubuntu:20.04

# Set the geographic area environment variable
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Paris

# Set the working directory inside the container
WORKDIR /app

RUN apt update && \
apt install -y build-essential wget && \
apt install -y cmake && \
apt install -y git && \
apt install -y libgtest-dev

RUN apt-get update && apt-get install -y \
python3 \
python3-dev \
python3-pip\
python3-numpy

# Install Python packages
RUN pip3 install numpy==1.20.0 matplotlib

# Install Eigen library
RUN apt-get install -y libeigen3-dev

RUN git clone https://github.com/coin-or/CppAD.git
WORKDIR /app/CppAD
RUN mkdir build
WORKDIR /app/CppAD/build
RUN cmake ..
RUN make install

WORKDIR /app

RUN git clone https://github.com/joaoleal/CppADCodeGen.git
WORKDIR /app/CppADCodeGen
RUN mkdir build
WORKDIR /app/CppADCodeGen/build
RUN cmake ..
RUN make install

WORKDIR /app

RUN git clone https://github.com/giaf/blasfeo.git
WORKDIR /app/blasfeo
RUN mkdir build
WORKDIR /app/blasfeo/build
RUN cmake ..
RUN make install

WORKDIR /app
RUN git clone https://github.com/giaf/hpipm.git
WORKDIR /app/hpipm
RUN make static_library TARGET=GENERIC -j 4

# Create a directory inside the container to mount the external folder
RUN mkdir /app/MPCC

# Mount the external folder to /app/MPCC inside the container
VOLUME /app/MPCC

# Change to the MPCC directory
WORKDIR /app/MPCC
2 changes: 1 addition & 1 deletion C++/MPC/mpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void MPC::setMPCProblem()
{
for(int i=0;i<=N;i++)
{
setStage(initial_guess_[i].xk,initial_guess_[i].uk,initial_guess_[i+1].xk,i);
setStage(initial_guess_[i].xk,initial_guess_[i].uk,initial_guess_[std::min(i+1, N)].xk,i);
}
}

Expand Down
1 change: 1 addition & 0 deletions C++/Plotting/plotting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ void Plotting::plotRun(const std::list<MPCReturn> &log, const TrackPos &track_xy
plt::axis("equal");
plt::xlabel("X [m]");
plt::ylabel("Y [m]");
plt::save("XY_traj.pdf");
plt::figure();
// plt::subplot(3,2,1);
plt::plot(plot_x);
Expand Down
35 changes: 5 additions & 30 deletions C++/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,15 @@
## Install dependencies
set -e

## clone blasfeo
repository_blasfeo="https://github.com/giaf/blasfeo.git"
localFolder_blasfeo="External/blasfeo"
git clone "$repository_blasfeo" "$localFolder_blasfeo"
## clone hpipm
repository_hpipm="https://github.com/giaf/hpipm.git"
localFolder_hpipm="External/hpipm"
git clone "$repository_hpipm" "$localFolder_hpipm"

## clone matplotlib-cpp
repository_matplotlib="https://github.com/lava/matplotlib-cpp.git"
localFolder_matplotlib="External/matplotlib"
git clone "$repository_matplotlib" "$localFolder_matplotlib"
## clone eigne
repository_eigen="https://gitlab.com/libeigen/eigen.git"
localFolder_eigen="External/Eigen"
git clone "$repository_eigen" "$localFolder_eigen"

## clone json
repository_json="https://github.com/nlohmann/json.git"
localFolder_json="External/Json"
git clone "$repository_json" "$localFolder_json"


cd External/blasfeo
mkdir -p build
mkdir -p lib
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$(realpath ../lib)
make
make install

cd ../../hpipm
mkdir -p build
mkdir -p lib
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$(realpath ../lib) -DBLASFEO_PATH=$(realpath ../../blasfeo/lib)
make
make install
git clone --depth 1 "$repository_json" "$localFolder_json"


2 changes: 1 addition & 1 deletion C++/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main() {
log.push_back(mpc_sol);
}
plotter.plotRun(log,track_xy);
plotter.plotSim(log,track_xy);
// plotter.plotSim(log,track_xy);

double mean_time = 0.0;
double max_time = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion C++/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ std::vector<double> stateInputToVector(const State x,const Input u)
StateVector xv = stateToVector(x);
InputVector uv = inputToVector(u);

Eigen::Vector<double,NX+NU> z;
Eigen::Matrix<double,NX+NU,1> z;
z << xv,uv;
std::vector<double> zv(z.data(), z.data() + z.size());

Expand Down

0 comments on commit 99d87d3

Please sign in to comment.